Added docstring and other minor style fixes.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7822 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Gary Wilson Jr 2008-07-02 05:00:09 +00:00
parent f5c1bb1cad
commit 73dfef8771
1 changed files with 15 additions and 8 deletions

View File

@ -1,14 +1,15 @@
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
from django.db import connection
from django.contrib.auth.models import User
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 @@ class ModelBackend(object):
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:
@ -61,6 +65,9 @@ class ModelBackend(object):
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):