Refactoring of 'fully_decorated' for clarity and removal of duplication.
Also allows re-use of 'full_decorator' if we need it. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16271 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
4c4e46e646
commit
55c2c302c1
|
@ -16,35 +16,50 @@ def fully_decorated(request):
|
||||||
return HttpResponse('<html><body>dummy</body></html>')
|
return HttpResponse('<html><body>dummy</body></html>')
|
||||||
fully_decorated.anything = "Expected __dict__"
|
fully_decorated.anything = "Expected __dict__"
|
||||||
|
|
||||||
|
|
||||||
|
def compose(*functions):
|
||||||
|
# compose(f, g)(*args, **kwargs) == f(g(*args, **kwargs))
|
||||||
|
functions = list(reversed(functions))
|
||||||
|
def _inner(*args, **kwargs):
|
||||||
|
result = functions[0](*args, **kwargs)
|
||||||
|
for f in functions[1:]:
|
||||||
|
result = f(result)
|
||||||
|
return result
|
||||||
|
return _inner
|
||||||
|
|
||||||
|
|
||||||
|
full_decorator = compose(
|
||||||
# django.views.decorators.http
|
# django.views.decorators.http
|
||||||
fully_decorated = require_http_methods(["GET"])(fully_decorated)
|
require_http_methods(["GET"]),
|
||||||
fully_decorated = require_GET(fully_decorated)
|
require_GET,
|
||||||
fully_decorated = require_POST(fully_decorated)
|
require_POST,
|
||||||
fully_decorated = require_safe(fully_decorated)
|
require_safe,
|
||||||
|
|
||||||
# django.views.decorators.vary
|
# django.views.decorators.vary
|
||||||
fully_decorated = vary_on_headers('Accept-language')(fully_decorated)
|
vary_on_headers('Accept-language'),
|
||||||
fully_decorated = vary_on_cookie(fully_decorated)
|
vary_on_cookie,
|
||||||
|
|
||||||
# django.views.decorators.cache
|
# django.views.decorators.cache
|
||||||
fully_decorated = cache_page(60*15)(fully_decorated)
|
cache_page(60*15),
|
||||||
fully_decorated = cache_control(private=True)(fully_decorated)
|
cache_control(private=True),
|
||||||
fully_decorated = never_cache(fully_decorated)
|
never_cache,
|
||||||
|
|
||||||
# django.contrib.auth.decorators
|
# django.contrib.auth.decorators
|
||||||
# Apply user_passes_test twice to check #9474
|
# Apply user_passes_test twice to check #9474
|
||||||
fully_decorated = user_passes_test(lambda u:True)(fully_decorated)
|
user_passes_test(lambda u:True),
|
||||||
fully_decorated = login_required(fully_decorated)
|
login_required,
|
||||||
fully_decorated = permission_required('change_world')(fully_decorated)
|
permission_required('change_world'),
|
||||||
|
|
||||||
# django.contrib.admin.views.decorators
|
# django.contrib.admin.views.decorators
|
||||||
fully_decorated = staff_member_required(fully_decorated)
|
staff_member_required,
|
||||||
|
|
||||||
# django.utils.functional
|
# django.utils.functional
|
||||||
fully_decorated = memoize(fully_decorated, {}, 1)
|
lambda f: memoize(f, {}, 1),
|
||||||
fully_decorated = allow_lazy(fully_decorated)
|
allow_lazy,
|
||||||
fully_decorated = lazy(fully_decorated)
|
lazy,
|
||||||
|
)
|
||||||
|
|
||||||
|
fully_decorated = full_decorator(fully_decorated)
|
||||||
|
|
||||||
class DecoratorsTest(TestCase):
|
class DecoratorsTest(TestCase):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue