pyramid_cubicweb/predicates.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 28 Jun 2016 11:03:20 +0200
changeset 11629 0459094d9728
parent 11601 23a62d151382
permissions -rw-r--r--
Use opened connections as much as possible instead of opening a new internal connection to set the session cookie or retrieve the session data, which may exhaust the connection pools.

"""Contains predicates used in Pyramid views.
"""


class MatchIsETypePredicate(object):
    """A predicate that match if a given etype exist in schema.
    """
    def __init__(self, matchname, config):
        self.matchname = matchname

    def text(self):
        return 'match_is_etype = %s' % self.matchname

    phash = text

    def __call__(self, info, request):
        return info['match'][self.matchname].lower() in \
            request.registry['cubicweb.registry'].case_insensitive_etypes


def includeme(config):
    config.add_route_predicate('match_is_etype', MatchIsETypePredicate)