Code

Ticket #3011: auth_user_module.diff

File auth_user_module.diff, 8.1 KB (added by nowell strite, 7 years ago)

auth_user_module patch

Line 
1Index: django/contrib/auth/users/__init__.py
2===================================================================
3Index: django/contrib/auth/users/models.py
4===================================================================
5--- django/contrib/auth/users/models.py (revision 0)
6+++ django/contrib/auth/users/models.py (revision 0)
7@@ -0,0 +1,41 @@
8+from django.core import validators
9+from django.db import backend, connection, models
10+from django.utils.translation import gettext_lazy as _
11+from django.contrib.auth.models import Group, Permission, UserManager, UserTemplate
12+
13+class DefaultUser(models.Model, UserTemplate):
14+    """Users within the Django authentication system are represented by this model.
15+
16+    Username and password are required. Other fields are optional.
17+    """
18+    username = models.CharField(_('username'), maxlength=30, unique=True, validator_list=[validators.isAlphaNumeric], help_text=_("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores)."))
19+    first_name = models.CharField(_('first name'), maxlength=30, blank=True)
20+    last_name = models.CharField(_('last name'), maxlength=30, blank=True)
21+    email = models.EmailField(_('e-mail address'), blank=True)
22+    password = models.CharField(_('password'), maxlength=128, help_text=_("Use '[algo]$[salt]$[hexdigest]'"))
23+    is_staff = models.BooleanField(_('staff status'), default=False, help_text=_("Designates whether the user can log into this admin site."))
24+    is_active = models.BooleanField(_('active'), default=True, help_text=_("Designates whether this user can log into the Django admin. Unselect this instead of deleting accounts."))
25+    is_superuser = models.BooleanField(_('superuser status'), default=False, help_text=_("Designates that this user has all permissions without explicitly assigning them."))
26+    last_login = models.DateTimeField(_('last login'), default=models.LazyDate())
27+    date_joined = models.DateTimeField(_('date joined'), default=models.LazyDate())
28+    groups = models.ManyToManyField(Group, verbose_name=_('groups'), blank=True, help_text=_("In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in."))
29+    user_permissions = models.ManyToManyField(Permission, verbose_name=_('user permissions'), blank=True, filter_interface=models.HORIZONTAL)
30+    objects = UserManager()
31+
32+    class Meta:
33+        verbose_name = _('user')
34+        verbose_name_plural = _('users')
35+        ordering = ('username',)
36+        db_table = 'auth_user'
37+       
38+    class Admin:
39+        fields = (
40+            (None, {'fields': ('username', 'password')}),
41+            (_('Personal info'), {'fields': ('first_name', 'last_name', 'email')}),
42+            (_('Permissions'), {'fields': ('is_staff', 'is_active', 'is_superuser', 'user_permissions')}),
43+            (_('Important dates'), {'fields': ('last_login', 'date_joined')}),
44+            (_('Groups'), {'fields': ('groups',)}),
45+        )
46+        list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff')
47+        list_filter = ('is_staff', 'is_superuser')
48+        search_fields = ('username', 'first_name', 'last_name', 'email')
49Index: django/contrib/auth/models.py
50===================================================================
51--- django/contrib/auth/models.py       (revision 4061)
52+++ django/contrib/auth/models.py       (working copy)
53@@ -3,6 +3,7 @@
54 from django.db import backend, connection, models
55 from django.contrib.contenttypes.models import ContentType
56 from django.utils.translation import gettext_lazy as _
57+from django.conf import settings
58 import datetime
59 
60 def check_password(raw_password, enc_password):
61@@ -82,41 +83,7 @@
62         from random import choice
63         return ''.join([choice(allowed_chars) for i in range(length)])
64 
65-class User(models.Model):
66-    """Users within the Django authentication system are represented by this model.
67-
68-    Username and password are required. Other fields are optional.
69-    """
70-    username = models.CharField(_('username'), maxlength=30, unique=True, validator_list=[validators.isAlphaNumeric], help_text=_("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores)."))
71-    first_name = models.CharField(_('first name'), maxlength=30, blank=True)
72-    last_name = models.CharField(_('last name'), maxlength=30, blank=True)
73-    email = models.EmailField(_('e-mail address'), blank=True)
74-    password = models.CharField(_('password'), maxlength=128, help_text=_("Use '[algo]$[salt]$[hexdigest]'"))
75-    is_staff = models.BooleanField(_('staff status'), default=False, help_text=_("Designates whether the user can log into this admin site."))
76-    is_active = models.BooleanField(_('active'), default=True, help_text=_("Designates whether this user can log into the Django admin. Unselect this instead of deleting accounts."))
77-    is_superuser = models.BooleanField(_('superuser status'), default=False, help_text=_("Designates that this user has all permissions without explicitly assigning them."))
78-    last_login = models.DateTimeField(_('last login'), default=models.LazyDate())
79-    date_joined = models.DateTimeField(_('date joined'), default=models.LazyDate())
80-    groups = models.ManyToManyField(Group, verbose_name=_('groups'), blank=True,
81-        help_text=_("In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in."))
82-    user_permissions = models.ManyToManyField(Permission, verbose_name=_('user permissions'), blank=True, filter_interface=models.HORIZONTAL)
83-    objects = UserManager()
84-    class Meta:
85-        verbose_name = _('user')
86-        verbose_name_plural = _('users')
87-        ordering = ('username',)
88-    class Admin:
89-        fields = (
90-            (None, {'fields': ('username', 'password')}),
91-            (_('Personal info'), {'fields': ('first_name', 'last_name', 'email')}),
92-            (_('Permissions'), {'fields': ('is_staff', 'is_active', 'is_superuser', 'user_permissions')}),
93-            (_('Important dates'), {'fields': ('last_login', 'date_joined')}),
94-            (_('Groups'), {'fields': ('groups',)}),
95-        )
96-        list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff')
97-        list_filter = ('is_staff', 'is_superuser')
98-        search_fields = ('username', 'first_name', 'last_name', 'email')
99-
100+class UserTemplate:
101     def __str__(self):
102         return self.username
103 
104@@ -240,7 +207,6 @@
105         SiteProfileNotAvailable if this site does not allow profiles.
106         """
107         if not hasattr(self, '_profile_cache'):
108-            from django.conf import settings
109             if not settings.AUTH_PROFILE_MODULE:
110                 raise SiteProfileNotAvailable
111             try:
112@@ -251,6 +217,14 @@
113                 raise SiteProfileNotAvailable
114         return self._profile_cache
115 
116+# Grab the AUTH_USER_MODULE path from the settings
117+auth_user_module_path = settings.AUTH_USER_MODULE.split('.')
118+# Import the AUTH_USER_MODULE
119+# The [0:-1] holds the module path, [-1] holds the class name
120+auth_user_module = __import__('.'.join(user_module_path[0:-1]), {}, {}, ['.'.join(user_module_path[0:-1])])
121+# This is the custom User class
122+User = getattr(user_module, user_module_path[-1])
123+
124 class Message(models.Model):
125     """The message system is a lightweight way to queue messages for given users. A message is associated with a User instance (so it is only applicable for registered users). There's no concept of expiration or timestamps. Messages are created by the Django admin after successful actions. For example, "The poll Foo was created successfully." is a message.
126     """
127Index: django/conf/global_settings.py
128===================================================================
129--- django/conf/global_settings.py      (revision 4061)
130+++ django/conf/global_settings.py      (working copy)
131@@ -315,3 +315,6 @@
132 # The name of the database to use for testing purposes.
133 # If None, a name of 'test_' + DATABASE_NAME will be assumed
134 TEST_DATABASE_NAME = None
135+
136+# The class to use as the default AUTH_USER for the authentication system.
137+AUTH_USER_MODULE = 'django.contrib.auth.users.models.DefaultUser'