traversal and path with one element

33 views
Skip to first unread message

rockerzz

unread,
Apr 23, 2012, 9:08:00 AM4/23/12
to pylons-discuss
Could you explain why not return view_name if I work with url
something like http://0.0.0.0:6543/catalog/.

If I remove from my root resources object __getitem__ function - its
work fine.

class Resource(object):
def __init__(self, name=None, parent=None):
self.__name__ = name
self.__parent__ = parent
self.children = {}

def add_child(self, name, klass=None, **kw):
if klass is None:
child = Resource(name, self)
else:
child = klass(name, self, **kw)
self.children[name] = child
'''
def __getitem__(self, name):
return self.children[name]
'''
class Catalog(Resource):
pass


root = Resource('root')
root.add_child('catalog', Catalog)

As I understand it, this is the logic of work. How do I properly solve
this problem?

Code from traversal.py ResourceTreeTraverser class:

try:
getitem = ob.__getitem__
except AttributeError:
return {'context':ob,
'view_name':segment,
'subpath':vpath_tuple[i+1:],
'traversed':vpath_tuple[:vroot_idx+i+1],
'virtual_root':vroot,
'virtual_root_path':vroot_tuple,
'root':root}

try:
next = getitem(segment)
except KeyError:
return {'context':ob,
'view_name':segment,
'subpath':vpath_tuple[i+1:],
'traversed':vpath_tuple[:vroot_idx+i+1],
'virtual_root':vroot,
'virtual_root_path':vroot_tuple,
'root':root}

Alexey Gelyadov

unread,
Apr 23, 2012, 9:40:16 AM4/23/12
to pylons-...@googlegroups.com
I would like to work with interfaces, by doing something like for url example.com/catalog and m.example.com/catalog:

<view context=".resources.ISite"    view=".views.views.my_view" renderer="catlog/catalog.html"/>
<view context=".resources.IMobile"  view=".views.views.my_view" renderer="mobile/catalog/catalog.html"/>

Feng Wang

unread,
Apr 23, 2012, 10:06:11 PM4/23/12
to pylons-...@googlegroups.com
I think maybe you will raise a KeyError when the getitem method of you root resource dont't have a self.children[name].

在 2012年4月23日星期一UTC+8下午9时08分00秒,Alexey Gelyadov写道:

Feng Wang

unread,
Apr 23, 2012, 10:07:40 PM4/23/12
to pylons-...@googlegroups.com

In your case, catalog will be the context ,and the view_name will be none.

在 2012年4月23日星期一UTC+8下午9时08分00秒,Alexey Gelyadov写道:
Reply all
Reply to author
Forward
0 new messages