summaryrefslogtreecommitdiff
path: root/repoze/bfg/zcml.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-05-31 20:36:53 +0000
committerChris McDonough <chrism@agendaless.com>2009-05-31 20:36:53 +0000
commit6c7b9a1534d35aeb07f4a9a59b8e15633f6b6b6b (patch)
tree184f1553b041226cac7e8a83b71578e556e15874 /repoze/bfg/zcml.py
parent8c3b807625d0480c7ce934bf7daf3437328346bf (diff)
downloadpyramid-6c7b9a1534d35aeb07f4a9a59b8e15633f6b6b6b.tar.gz
pyramid-6c7b9a1534d35aeb07f4a9a59b8e15633f6b6b6b.tar.bz2
pyramid-6c7b9a1534d35aeb07f4a9a59b8e15633f6b6b6b.zip
- The ``request_type`` argument of ZCML ``view`` declarations and
``bfg_view`` decorators can now be one of the strings ``GET``, ``POST``, ``PUT``, ``DELETE``, or ``HEAD`` instead of a reference to the respective interface type imported from ``repoze.bfg.interfaces``.
Diffstat (limited to 'repoze/bfg/zcml.py')
-rw-r--r--repoze/bfg/zcml.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/repoze/bfg/zcml.py b/repoze/bfg/zcml.py
index 39366b0b1..0f9d4a22b 100644
--- a/repoze/bfg/zcml.py
+++ b/repoze/bfg/zcml.py
@@ -25,6 +25,8 @@ from repoze.bfg.interfaces import IRoutesContext
from repoze.bfg.interfaces import IViewPermission
from repoze.bfg.interfaces import IView
+from repoze.bfg.request import HTTP_METHOD_INTERFACES
+
from repoze.bfg.security import ViewPermissionFactory
import martian
@@ -68,6 +70,15 @@ def view(
# the view specification; we ignore it.
pass
+ if request_type is None:
+ request_type = IRequest
+
+ elif isinstance(request_type, basestring):
+ if request_type in HTTP_METHOD_INTERFACES:
+ request_type = HTTP_METHOD_INTERFACES[request_type]
+ else:
+ request_type = _context.resolve(request_type)
+
if inspect.isclass(view):
# If the object we've located is a class, turn it into a
# function that operates like a Zope view (when it's invoked,
@@ -84,9 +95,6 @@ def view(
_bfg_class_view.__doc__ = view.__doc__
view = _bfg_class_view
- if request_type is None:
- request_type = IRequest
-
if permission:
pfactory = ViewPermissionFactory(permission)
_context.action(
@@ -132,8 +140,8 @@ class IViewDirective(Interface):
required=False,
)
- request_type = GlobalObject(
- title=u"""The request type interface for the view""",
+ request_type = TextLine(
+ title=u"The request type string or dotted name interface for the view",
description=(u"The view will be called if the interface represented by "
u"'request_type' is implemented by the request. The "
u"default request type is repoze.bfg.interfaces.IRequest"),