Skip to content

Commit 184d815

Browse files
committed
Add "LIFT" sentinel for context and name arguments to add_view
1 parent 3739a77 commit 184d815

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/pyramid/config/views.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
as_sorted_tuple,
5757
is_nonstr_iter,
5858
)
59-
from pyramid.view import AppendSlashNotFoundViewFactory
59+
from pyramid.view import LIFT, AppendSlashNotFoundViewFactory
6060
import pyramid.viewderivers
6161
from pyramid.viewderivers import (
6262
INGRESS,
@@ -572,7 +572,9 @@ def wrapper(context, request):
572572
name
573573
574574
The :term:`view name`. Read :ref:`traversal_chapter` to
575-
understand the concept of a view name.
575+
understand the concept of a view name. When :term:`view` is a class,
576+
the sentinel value view.LIFT will cause the :term:`attr` value to be
577+
copied to name (useful with view_defaults to reduce boilerplate).
576578
577579
context
578580
@@ -587,6 +589,9 @@ def wrapper(context, request):
587589
to ``add_view`` as ``for_`` (an older, still-supported
588590
spelling). If the view should *only* match when handling
589591
exceptions, then set the ``exception_only`` to ``True``.
592+
When :term:`view` is a class, the sentinel value view.LIFT here
593+
will cause the :term:`context` value to be set at scan time
594+
(useful in conjunction with venusian :term:`lift`).
590595
591596
route_name
592597
@@ -815,6 +820,14 @@ def wrapper(context, request):
815820
containment = self.maybe_dotted(containment)
816821
mapper = self.maybe_dotted(mapper)
817822

823+
if inspect.isclass(view):
824+
if context is LIFT:
825+
context = view
826+
if name is LIFT:
827+
name = attr
828+
elif LIFT in (context, name):
829+
raise ValueError('LIFT is only allowed when view is a class')
830+
818831
if is_nonstr_iter(decorator):
819832
decorator = combine_decorators(*map(self.maybe_dotted, decorator))
820833
else:

src/pyramid/view.py

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from pyramid.util import hide_attrs, reraise as reraise_
2424

2525
_marker = object()
26+
LIFT = object()
2627

2728

2829
def render_view_to_response(context, request, name='', secure=True):

0 commit comments

Comments
 (0)