Skip to content

Commit

Permalink
api: convenience wrapper for the idiom when starting to use urls prop…
Browse files Browse the repository at this point in the history
…erty
  • Loading branch information
dlamotte committed Dec 18, 2014
1 parent 6a56fa2 commit bc2db70
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions krankshaft/api.py
Expand Up @@ -945,3 +945,25 @@ def view(request, *args, **kwargs):
# @api(param=val)
# class/def ...
return decorator

def wrap_and_route(self, obj):
'''wrap_and_route(self)
When starting with a `urls` property on an object, you initially do
a really simple idiom. This simply makes it easier.
@property
def urls(self):
from django.conf.urls import patterns, urls
return patterns('',
url('^url/to/respond/to/$', api.wrap_and_route(self)),
)
When you need more flexibility, you can remove the `wrap_and_route` and
define your own routing but for the simplest case where you just want
the default routing, this is helpful.
'''
return self.wrap(
lambda request, *args, **kwargs:
self.route(obj, request, args, kwargs)
)

0 comments on commit bc2db70

Please sign in to comment.