Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 73dfef8771b77ba867d667b2271bb9ee4bec8349 1 parent f5c1bb1
Gary Wilson Jr. gdub authored

Showing 1 changed file with 15 additions and 8 deletions. Show diff stats Hide diff stats

  1. +15 8 django/contrib/auth/backends.py
23 django/contrib/auth/backends.py
... ... @@ -1,14 +1,15 @@
  1 +try:
  2 + set
  3 +except NameError:
  4 + from sets import Set as set # Python 2.3 fallback
  5 +
1 6 from django.db import connection
2 7 from django.contrib.auth.models import User
3 8
4   -try:
5   - set
6   -except NameError:
7   - from sets import Set as set # Python 2.3 fallback
8   -
  9 +
9 10 class ModelBackend(object):
10 11 """
11   - Authenticate against django.contrib.auth.models.User
  12 + Authenticates against django.contrib.auth.models.User.
12 13 """
13 14 # TODO: Model, login attribute name and password attribute name should be
14 15 # configurable.
@@ -21,7 +22,10 @@ def authenticate(self, username=None, password=None):
21 22 return None
22 23
23 24 def get_group_permissions(self, user_obj):
24   - "Returns a list of permission strings that this user has through his/her groups."
  25 + """
  26 + Returns a set of permission strings that this user has through his/her
  27 + groups.
  28 + """
25 29 if not hasattr(user_obj, '_group_perm_cache'):
26 30 cursor = connection.cursor()
27 31 # The SQL below works out to the following, after DB quoting:
@@ -50,7 +54,7 @@ def get_group_permissions(self, user_obj):
50 54 cursor.execute(sql, [user_obj.id])
51 55 user_obj._group_perm_cache = set(["%s.%s" % (row[0], row[1]) for row in cursor.fetchall()])
52 56 return user_obj._group_perm_cache
53   -
  57 +
54 58 def get_all_permissions(self, user_obj):
55 59 if not hasattr(user_obj, '_perm_cache'):
56 60 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):
61 65 return perm in self.get_all_permissions(user_obj)
62 66
63 67 def has_module_perms(self, user_obj, app_label):
  68 + """
  69 + Returns True if user_obj has any permissions in the given app_label.
  70 + """
64 71 return bool(len([p for p in self.get_all_permissions(user_obj) if p[:p.index('.')] == app_label]))
65 72
66 73 def get_user(self, user_id):

0 comments on commit 73dfef8

Please sign in to comment.
Something went wrong with that request. Please try again.