cubicweb/pyramid/predicates.py
author Denis Laxalde <denis.laxalde@logilab.fr>
Fri, 18 Nov 2016 10:28:41 +0100
branch3.24
changeset 11923 acfb9aa4845e
parent 11631 faf279e33298
child 11967 83739be20fab
permissions -rw-r--r--
[devtools] Make timeout error in qunit tests configurable and use SkipTest in test_jscript.py This is grafted from 87443f279b0f in default branch (got tired of CI failing because of these unreliable tests).

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