summaryrefslogtreecommitdiff
path: root/pecan/decorators.py
diff options
context:
space:
mode:
authorJonathan LaCour <jonathan@cleverdevil.org>2010-11-18 10:54:15 -0500
committerJonathan LaCour <jonathan@cleverdevil.org>2010-11-18 10:54:15 -0500
commit17df37c09a5c45a618f79bfbbbcd0708a3a65057 (patch)
treec9ced1fe44466c7e1e99f063fa4743bc4446be23 /pecan/decorators.py
parentb1fbdc3802e91351bf2bebe6ffed67893665f4b8 (diff)
downloadpecan-17df37c09a5c45a618f79bfbbbcd0708a3a65057.tar.gz
Adding support for generic controllers, which allow you to dispatch to
different controllers based upon request method.
Diffstat (limited to 'pecan/decorators.py')
-rw-r--r--pecan/decorators.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/pecan/decorators.py b/pecan/decorators.py
index 7dce90a..8a330b7 100644
--- a/pecan/decorators.py
+++ b/pecan/decorators.py
@@ -5,11 +5,21 @@ def _cfg(f):
return f.pecan
+def when_for(controller):
+ def when(method):
+ def decorate(f):
+ controller.pecan['generic_handlers'][method.upper()] = f
+ return f
+ return decorate
+ return when
+
+
def expose(template = None,
content_type = 'text/html',
schema = None,
json_schema = None,
- error_handler = None):
+ error_handler = None,
+ generic = False):
if template == 'json': content_type = 'application/json'
def decorate(f):
@@ -22,6 +32,12 @@ def expose(template = None,
cfg.setdefault('template', []).append(template)
cfg.setdefault('content_types', {})[content_type] = template
+ # handle generic controllers
+ if generic:
+ cfg['generic'] = True
+ cfg['generic_handlers'] = dict(DEFAULT=f)
+ f.when = when_for(f)
+
# store the arguments for this controller method
cfg['argspec'] = getargspec(f)