pyramid_cubicweb/predicates.py
author David Douard <david.douard@logilab.fr>
Tue, 22 Mar 2016 13:58:38 +0100
changeset 11610 4cac84a8bf5f
parent 11601 23a62d151382
permissions -rw-r--r--
[pkg] add a requirements-test.txt file for test dependencies on WebTest and cubicweb-pyramid

"""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)