summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2006-09-22 01:44:28 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2006-09-22 01:44:28 +0000
commit6be701eba172a2ca71aaff0f9efe5796b30ca066 (patch)
tree51e7e64293dfb64a9ec62893e61674a3b795febc /django
parent3efd4dcd2d03c235a1b28d382466440a33c271f9 (diff)
Fixed #2629 -- Added a permission_required decorator to
django.contrib.auth.decorator. Thanks, dummy@habmalnefrage.de. git-svn-id: http://code.djangoproject.com/svn/django/trunk@3779 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/contrib/auth/decorators.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/django/contrib/auth/decorators.py b/django/contrib/auth/decorators.py
index 0102496a33..8164d8314e 100644
--- a/django/contrib/auth/decorators.py
+++ b/django/contrib/auth/decorators.py
@@ -26,3 +26,11 @@ login_required.__doc__ = (
to the log-in page if necessary.
"""
)
+
+def permission_required(perm, login_url=LOGIN_URL):
+ """
+ Decorator for views that checks if a user has a particular permission
+ enabled, redirectiing to the log-in page if necessary.
+ """
+ return user_passes_test(lambda u: u.has_perm(perm), login_url=login_url)
+