cubicweb/pyramid/predicates.py
author Philippe Pepiot <philippe.pepiot@logilab.fr>
Wed, 08 Feb 2017 10:31:26 +0100
changeset 11954 e0d708fb20e8
parent 11631 faf279e33298
child 11967 83739be20fab
permissions -rw-r--r--
Make load_module() return existing module if present in sys.modules Otherwise the reload() builtin will not work correctly: https://www.python.org/dev/peps/pep-0302/#specification-part-1-the-importer-protocol

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