From 6225a24982dfaeffbc53f85d214159c08a0dbfc2 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sat, 19 Dec 2009 18:40:19 +0000 Subject: - Add a ``custom_predicates`` argument to the ``Configurator`` ``add_view`` method, the ``bfg_view`` decorator and the attribute list of the ZCML ``view`` directive. If ``custom_predicates`` is specified, it must be a sequence of predicate callables (a predicate callable accepts two arguments: ``context`` and ``request`` and returns ``True`` or ``False``). The associated view callable will only be invoked if all custom predicates return ``True``. Use one or more custom predicates when no existing predefined predicate is useful. Predefined and custom predicates can be mixed freely. - Add a ``custom_predicates`` argument to the ``Configurator`` ``add_route`` and the attribute list of the ZCML ``route`` directive. If ``custom_predicates`` is specified, it must be a sequence of predicate callables (a predicate callable accepts two arguments: ``context`` and ``request`` and returns ``True`` or ``False``). The associated route will match will only be invoked if all custom predicates return ``True``, else route matching continues. Use one or more custom predicates when no existing predefined predicate is useful. Predefined and custom predicates can be mixed freely. --- repoze/bfg/view.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'repoze/bfg/view.py') diff --git a/repoze/bfg/view.py b/repoze/bfg/view.py index e5b271262..4aebe8832 100644 --- a/repoze/bfg/view.py +++ b/repoze/bfg/view.py @@ -322,6 +322,12 @@ class bfg_view(object): expression. The view will only be invoked if the ``PATH_INFO`` WSGI environment variable matches the expression. + If ``custom_predicates`` is specified, it must be a sequence of + :term:`predicate` callables (a predicate callable accepts two + arguments: ``context`` and ``request`` and returns ``True`` or + ``False``). The view will only be invoked if all custom + predicates return ``True``. + Any individual or all parameters can be omitted. The simplest bfg_view declaration then becomes:: @@ -427,7 +433,8 @@ class bfg_view(object): def __init__(self, name='', request_type=None, for_=None, permission=None, route_name=None, request_method=None, request_param=None, containment=None, attr=None, renderer=None, wrapper=None, - xhr=False, accept=None, header=None, path_info=None): + xhr=False, accept=None, header=None, path_info=None, + custom_predicates=()): self.name = name self.request_type = request_type self.for_ = for_ @@ -443,6 +450,7 @@ class bfg_view(object): self.accept = accept self.header = header self.path_info = path_info + self.custom_predicates = custom_predicates def __call__(self, wrapped): setting = self.__dict__.copy() -- cgit v1.2.3