Permalink
Browse files

Added docstring and other minor style fixes.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7822 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent f5c1bb1 commit 73dfef8771b77ba867d667b2271bb9ee4bec8349 @gdub gdub committed Jul 2, 2008
Showing with 15 additions and 8 deletions.
  1. +15 −8 django/contrib/auth/backends.py
@@ -1,14 +1,15 @@
+try:
+ set
+except NameError:
+ from sets import Set as set # Python 2.3 fallback
+
from django.db import connection
from django.contrib.auth.models import User
-try:
- set
-except NameError:
- from sets import Set as set # Python 2.3 fallback
-
+
class ModelBackend(object):
"""
- Authenticate against django.contrib.auth.models.User
+ Authenticates against django.contrib.auth.models.User.
"""
# TODO: Model, login attribute name and password attribute name should be
# configurable.
@@ -21,7 +22,10 @@ def authenticate(self, username=None, password=None):
return None
def get_group_permissions(self, user_obj):
- "Returns a list of permission strings that this user has through his/her groups."
+ """
+ Returns a set of permission strings that this user has through his/her
+ groups.
+ """
if not hasattr(user_obj, '_group_perm_cache'):
cursor = connection.cursor()
# The SQL below works out to the following, after DB quoting:
@@ -50,7 +54,7 @@ def get_group_permissions(self, user_obj):
cursor.execute(sql, [user_obj.id])
user_obj._group_perm_cache = set(["%s.%s" % (row[0], row[1]) for row in cursor.fetchall()])
return user_obj._group_perm_cache
-
+
def get_all_permissions(self, user_obj):
if not hasattr(user_obj, '_perm_cache'):
user_obj._perm_cache = set([u"%s.%s" % (p.content_type.app_label, p.codename) for p in user_obj.user_permissions.select_related()])
@@ -61,6 +65,9 @@ def has_perm(self, user_obj, perm):
return perm in self.get_all_permissions(user_obj)
def has_module_perms(self, user_obj, app_label):
+ """
+ Returns True if user_obj has any permissions in the given app_label.
+ """
return bool(len([p for p in self.get_all_permissions(user_obj) if p[:p.index('.')] == app_label]))
def get_user(self, user_id):

0 comments on commit 73dfef8

Please sign in to comment.