On Mon, 2011-09-05 at 15:50 -0500, Michael Merickel wrote:
> Brian, I just want to clarify some points from your original email.
> 
> 
> Specifying the ``factory`` on the route is telling the traversal
> system how to get the root of your resource tree for that specific
> route. Thus in your example you might do:
> 
> 
> def PageFactory(request):
>     pagename = request.matchdict.get('page')
>     if pagename:
>         # page = <query db for a Page object named 'pagename'>
>         return page
> 
> 
> Specifying the ``context`` parameter on the view is saying "for this
> view to match (be invoked), the context object must be an instance of
> this class (or interface)". There is a subtle caveat here when using
> url dispatch. Traversal stops when the path being traversed is
> exhausted *OR* when a KeyError is raised. If you are attempting in
> your ``PageFactory`` to load a ``Page`` and that fails, raising a
> KeyError, then the ``PageFactory`` instance will now be the context.
>  ACLs will then be checked against the ``PageFactory`` object instead
> of your intended ``Page``. In this case you would probably prefer a
> 404 instead of having your view be invoked without a valid ``Page``.
> Thus, if your view specifies ``route_name='foo'`` *and*
> ``context=Page``, then you can be sure that view will only be called
> if the context is a ``Page``. On top of that if you specify a
> permission, then the view is only invoked if that permission was in
> the ACL as well.

I think this is incorrect.  There is no PageFactory class involved here,
and no traversal will be happening here without a "*traverse" in the
match pattern or a traverse= argument to add_route.  The context will
always be the Page instance in this example, so there's no reason to
even try using the context= argument to add_view; the view can just
assume the context will always be a Page.

Additionally, raising a KeyError from a root factory (as opposed as to
from the __getitem__ of a resource) will just cause the request to raise
an exception; it's unrelated to traversal.



-- 
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To post to this group, send email to pylons-devel@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en.

Reply via email to