summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert JW Regeer <bertjw@regeer.org>2015-10-15 22:52:40 -0600
committerBert JW Regeer <bertjw@regeer.org>2015-10-20 23:21:26 -0600
commit7fb6f954f406e99a969c5d4d108ed3e5edb6f9cd (patch)
tree623fd26994a6d499e95a84e55807cb6cc9d55b69
parent51ee346f982aaa325d22a80fd676ee2a21b985f5 (diff)
downloadpyramid-7fb6f954f406e99a969c5d4d108ed3e5edb6f9cd.tar.gz
pyramid-7fb6f954f406e99a969c5d4d108ed3e5edb6f9cd.tar.bz2
pyramid-7fb6f954f406e99a969c5d4d108ed3e5edb6f9cd.zip
Rename predicates to view_options
We also use the previously defined names() method on PredicateList to fetch the list of predicates and pull out all predicate values into it's own dictionary. Then the rest of the values are the view options for the view derivations. At the moment we do not check if the options matches a valid view derivation. No seatbelts for view options.
-rw-r--r--pyramid/config/views.py42
1 files changed, 31 insertions, 11 deletions
diff --git a/pyramid/config/views.py b/pyramid/config/views.py
index 30c73f6cb..5d92d6982 100644
--- a/pyramid/config/views.py
+++ b/pyramid/config/views.py
@@ -205,7 +205,7 @@ class ViewsConfiguratorMixin(object):
http_cache=None,
match_param=None,
check_csrf=None,
- **predicates):
+ **view_options):
""" Add a :term:`view configuration` to the current
configuration state. Arguments to ``add_view`` are broken
down below into *predicate* arguments and *non-predicate*
@@ -646,16 +646,17 @@ class ViewsConfiguratorMixin(object):
obsoletes this argument, but it is kept around for backwards
compatibility.
- predicates
+ view_options:
- Pass a key/value pair here to use a third-party predicate
- registered via
- :meth:`pyramid.config.Configurator.add_view_predicate`. More than
+ Pass a key/value pair here to use a third-party predicate or set a
+ value for a view derivative option registered via
+ :meth:`pyramid.config.Configurator.add_view_predicate` or
+ :meth:`pyramid.config.Configurator.add_view_derivation`. More than
one key/value pair can be used at the same time. See
:ref:`view_and_route_predicates` for more information about
third-party predicates.
- .. versionadded: 1.4a1
+ .. versionadded: 1.7
"""
if custom_predicates:
@@ -722,8 +723,8 @@ class ViewsConfiguratorMixin(object):
accept = accept.lower()
introspectables = []
- pvals = predicates.copy()
- pvals.update(
+ ovals = view_options.copy()
+ ovals.update(
dict(
xhr=xhr,
request_method=request_method,
@@ -742,9 +743,26 @@ class ViewsConfiguratorMixin(object):
def discrim_func():
# We need to defer the discriminator until we know what the phash
# is. It can't be computed any sooner because thirdparty
- # predicates may not yet exist when add_view is called.
+ # predicates/view derivations may not yet exist when add_view is
+ # called.
+ valid_predicates = predlist.names()
+ pvals = {}
+ options = {}
+
+ for (k, v) in ovals.items():
+ if k in valid_predicates:
+ pvals[k] = v
+ else:
+ options[k] = v
+
order, preds, phash = predlist.make(self, **pvals)
- view_intr.update({'phash':phash, 'order':order, 'predicates':preds})
+
+ view_intr.update({
+ 'phash': phash,
+ 'order': order,
+ 'predicates': preds,
+ 'options': options
+ })
return ('view', context, name, route_name, phash)
discriminator = Deferred(discrim_func)
@@ -780,7 +798,7 @@ class ViewsConfiguratorMixin(object):
decorator=decorator,
)
)
- view_intr.update(**predicates)
+ view_intr.update(**view_options)
introspectables.append(view_intr)
predlist = self.get_predlist('view')
@@ -812,6 +830,7 @@ class ViewsConfiguratorMixin(object):
# added by discrim_func above during conflict resolving
preds = view_intr['predicates']
+ opts = view_intr['options']
order = view_intr['order']
phash = view_intr['phash']
@@ -832,6 +851,7 @@ class ViewsConfiguratorMixin(object):
mapper=mapper,
decorator=decorator,
http_cache=http_cache,
+ options=opts,
)
derived_view.__discriminator__ = lambda *arg: discriminator
# __discriminator__ is used by superdynamic systems