Predicates should return True or False. They have no sense of
locality, so if you mess with the request and return True, and another
predicate returns False then you have screwed up the request for some
subsequent route that may match. This is obviously not ideal, but will
work in 95% of apps.

The factory is invoked *after* the route is matched, which means this
is not a problem.

def parse_identifier(identifier):
    return None, None

def user_by_factory(request):
    type, value = parse_identifier(request.matchdict['identifier'])
    if type is None:
        raise HTTPNotFound

    request.matchdict[type] = value

config.add_route('by', '/by/{identifier}', factory=user_by_factory)

The return-value of the factory is request.context, so in this case it
will be None. Other times you'd return an object with ACLs and other
useful information for your views and security system to use.

On Wed, Oct 15, 2014 at 1:49 PM, Jonathan Vanasco <jvana...@gmail.com> wrote:
> Thanks!  It looks like Route Factory is what I want.
>
> The docs are pretty sparse on it (at least on
> http://docs.pylonsproject.org/docs/pyramid/en/latest/narr/urldispatch.html)
>
> I'll look up some examples in public Pyramid projects and blogs later.
>
> I didn't realize that I could affect the dict with custom predicates.  It
> was pretty easy to make a temporary prototype with that, after knowing where
> to look.
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pylons-discuss+unsubscr...@googlegroups.com.
> To post to this group, send email to pylons-discuss@googlegroups.com.
> Visit this group at http://groups.google.com/group/pylons-discuss.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pylons-discuss+unsubscr...@googlegroups.com.
To post to this group, send email to pylons-discuss@googlegroups.com.
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.

Reply via email to