pyramid traversal resource url no attribute __name__
Posted
by
Santana
on Stack Overflow
See other posts from Stack Overflow
or by Santana
Published on 2012-09-03T03:07:54Z
Indexed on
2012/09/03
9:38 UTC
Read the original article
Hit count: 242
So I have:
resources.py:
def _add(obj, name, parent):
obj.__name__ = name
obj.__parent__ = parent
return obj
class Root(object):
__parent__ = __name__ = None
def __init__(self, request):
super(Root, self).__init__()
self.request = request
self.collection = request.db.post
def __getitem__(self, key):
if u'profile' in key:
return Profile(self.request)
class Profile(dict):
def __init__(self, request):
super(Profile, self).__init__()
self.__name__ = u'profile'
self.__parent__ = Root
self.collection = request.db.posts
def __getitem__(self, name):
post = Dummy(self.collection.find_one(dict(username=name)))
return _add(post, name, self)
and I'm using MongoDB and pyramid_mongodb
views.py:
@view_config(context = Profile, renderer = 'templates/mytemplate.pt')
def test_view(request):
return {}
and in mytemplate.pt:
<p tal:repeat='item request.context'>
${item}
</p>
I can echo what's in the database (I'm using mongodb), but when I provided a URL for each item using resource_url()
<p tal:repeat='item request.context'>
<a href='${request.resource_url(item)}'>${item}</a>
</p>
I got an error: 'dict' object has no attribute '__name__'
, can someone help me?
© Stack Overflow or respective owner