hello.
before i begin i would like to say, that i have read both 'Traversal'
and 'Resources' chapters from pyramid docs. I also read this thread ->
http://groups.google.com/group/pylons-devel/browse_thread/thread/a8d4cc7e8d0c9855
which is a similar problem i have, but i still cannot wrap my mind
around traversal. However, i think it's the best approach for me,
because of it's config.scan() capabilities. I also have a background
in pylons, which i was using without any problems.
So - to keep my long story short, i am trying to implement a fairly
simplistic application (task / bugtracker) in order to learn pyramid.
Here are the models:
User - a developer
Task - a Bug, that can have one developer and many comments.
Comment - a Task comment.
i have named my project 'flyswatter', therefore:
#flyswatter/__init__.py
...
config = Configurator(settings=settings)
config.add_static_view('static', 'flyswatter:static')
config.scan(".views")
...
#flyswatter/resources.py
class Resource(dict, object):
def __init__(self, name = None, parent = None):
self.__name__ = name
self.__parent__ = parent
self.children = {}
def add_child(self, name):
self.children[name] = Resource(name = name, parent = self)
def __getitem__(self, name):
return self.children.get(name)
root = Resource()
now - onto my problem. I would like to use config.scan() and traversal
in order to map url's to the views. my view directory structure looks
like this:
#flyswatter/flyswatter/views
__init__.py
default.py
task.py
admin
admin/__init__.py
admin/foo.py
The only way i managed to combine the traversal with views mapping is
like this:
#views/default.py
from flyswatter.resources import root
@view_config(context = root)
def index(request):
return Response('root::index')
@view_config(name="method", context = root)
def method(self):
return Response('root::method')
so far so good - url's "/" and "/method" are correctly mapped.
#views/task.py
from flyswatter.resources import root, Resource
root.add_child("task")
root["task"].add_child("method")
@view_config(name="task_index", context = root["task"])
def index(request):
return Response('task::index')
@view_config(name="task_method", context=root["task"])
def method(request):
return Response('task::method')
not so good - in order to access task.method i need to type the url /
task_method ( instead of /task/method ). I also cannot access
task.index by visiting /task - i need to use /task_index.
I tried to use "/task/method" as a name in @view_config but this
didn't seem to make any difference.
I think i'm pretty close to the desired result, however i am 100% sure
i am missing some crucial bit of information on understanding how
traversal / view mapping work. Could some direct me in a right way,
please? :)
best regards,
toudi.
p.s. sorry if my code looks ugly, i am still learning.. :)
p.p.s. i don't want to use view handlers - because ( unless i'm
mistaken ) i need to explicitly register the view classes one by one
in __init__.py. The config.scan() approach seems like a lot easier
( for instance for creating additional modules for the admin panel
without modyfing flyswatter/__init__.py )
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.