From 208ee5a8d6409bcdce361009dee6a2e335de1679 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Thu, 15 Jul 2010 17:41:05 +0000 Subject: Features -------- - New view predicate: match_val. The ``match_val`` value represents the presence of a value in the structure added to the request named ``matchdict`` during URL dispatch representing the match values from the route pattern (e.g. if the route pattern has ``:foo`` in it, and the route matches, a key will exist in the matchdict named ``foo``). Like all other view predicates, this feature is exposed via the ``bfg_view`` API, the Configurator ``add_view`` API, and the ZCML ``view`` directive. Documentation ------------- - API documentation for the ``add_view`` method of the configurator changed to include ``match_val``. - ZCML documentation for ``view`` ZCML directive changed to include ``match_val``. - The ``Views`` narrative chapter now contains a description of the ``match_val`` predicate. Bug Fixes --------- - The ``header`` predicate (when used as either a view predicate or a route predicate) had a problem when specified with a name/regex pair. When the header did not exist in the headers dictionary, the regex match could be fed ``None``, causing it to throw a ``TypeError: expected string or buffer`` exception. Now, the predicate returns False as intended. Internal -------- - Remove ``repoze.bfg.configuration.isclass`` function in favor of using ``inspect.isclass``. --- docs/narr/views.rst | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'docs/narr/views.rst') diff --git a/docs/narr/views.rst b/docs/narr/views.rst index eebaa63de..9b7d6b2dd 100644 --- a/docs/narr/views.rst +++ b/docs/narr/views.rst @@ -1358,6 +1358,33 @@ Predicate Arguments taken into consideration when deciding whether or not to invoke the associated view callable. +``match_val`` + + This value represents :term:`URL dispatch` ``request.matchdict`` + name or a matchdict name/value pair. ``request.matchdict`` is a + dictionary representing the match values from the route pattern + (e.g. if the route pattern has ``:foo`` in it, and the route + matches, a key will exist in the matchdict named ``foo``). + + If ``match_val`` is specified, it must be the name of a key presumed + to be present in the ``matchdict`` or a ``key:regex`` pair. + + If ``match_val`` is specified without a colon in it + (e.g. ``action``), the predicate will return true if the + ``matchdict`` has a key which exists with any value. + + When the ``match_val`` contains a ``:`` (colon), it will be split at + the first colon; the left hand of that split will considered a key + and the right hand a regular expression. For example, in + ``action:\w+\.html``, the key part is ``action``, the regex part is + ``\w+\.html``. The resulting predicate will only be true if the + matchdict contains a key that matches the key part *and* the + matchdict value is matched by the regex part. + + If ``match_val`` is not specified, the composition, presence or + absence of values in the matchdict is not taken into consideration + when deciding whether or not to invoke the associated view callable. + ``custom_predicates`` If ``custom_predicates`` is specified, it must be a sequence of references to custom predicate callables. Use custom predicates -- cgit v1.2.3