Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use the pyramid_traversalwrapper?
    primarykey
    data
    text
    <p>I'm new to pyramid as well as the traversal concept. I have a basic object model working with traversal however the objects are location un-aware, so reading up on pyramid documentation found on this page <a href="http://docs.pylonsproject.org/projects/pyramid/en/1.0-branch/narr/resources.html#location-aware" rel="nofollow">http://docs.pylonsproject.org/projects/pyramid/en/1.0-branch/narr/resources.html#location-aware</a> it talks about using the pyramid_traversalwrapper. </p> <p>Following the instruction I added the following lines to my main:</p> <pre><code>config = Configurator(root_factory=Root) config.registry.registerAdapter(ModelGraphTraverser, (Interface,), ITraverser) </code></pre> <p>The rest of my traversal tree objects look like this:</p> <pre><code>class Root(object): def __init__(self, request): pass def __getitem__(self, key): if key == 'users': return UserList() raise KeyError class UserList(): def __getitem__(self, key): users = {'a':None,'b':None, 'c':None} if key in users: return User() raise KeyError class User(object): def __init__(self): pass def __getitem__(self, key): if (key == 'channels'): return Channels() def GET(self): return Response("got user") </code></pre> <p>When I ran the code it does seem to use the ModelGraphTraverser when resolving urls, however what do I have to do to make my model location-aware, as in knowing the <code>__parent__</code> and <code>__name__</code> and such? Do I have to add wrapper classes? If so how do I go about doing it? pyramid_traversalwrapper is supposed to make managing <code>__parent__</code> and <code>__name__</code> effortless, but I have no idea how to take advantage of it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload