cubicweb/pyramid/predicates.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 09 Nov 2016 11:46:03 +0100
branch3.24
changeset 11814 ab8f652a9c99
parent 11631 faf279e33298
child 11967 83739be20fab
permissions -rw-r--r--
[pyramid] Add action verb used in some messages displayed by the command For instance we'll see 'instance started' instead of 'instance None', which is nicer.

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