Code

Ticket #3011: 3011.3.diff

File 3011.3.diff, 6.5 KB (added by Densetsu no Ero-sennin <densetsu.no.ero.sennin@…>, 7 years ago)

oh sorry, my previous patch was against newforms-admin branch, here's the patch against trunk [6023]

Line 
1Index: django/conf/global_settings.py
2===================================================================
3--- django/conf/global_settings.py      (revision 6023)
4+++ django/conf/global_settings.py      (working copy)
5@@ -328,6 +328,9 @@
6 
7 LOGIN_REDIRECT_URL = '/accounts/profile/'
8 
9+# The class to use as the default AUTH_USER for the authentication system.
10+AUTH_USER_MODULE = 'django.contrib.auth.default_user.User'
11+
12 ###########
13 # TESTING #
14 ###########
15Index: django/contrib/auth/default_user.py
16===================================================================
17--- django/contrib/auth/default_user.py (revision 0)
18+++ django/contrib/auth/default_user.py (revision 0)
19@@ -0,0 +1,27 @@
20+from django.db import models
21+from django.core import validators
22+from django.utils.translation import gettext_lazy as _
23+
24+from django.contrib.auth.models import Group, Permission, UserManager, UserTemplate
25+
26+import datetime
27+
28+class User(models.Model, UserTemplate):
29+    """Users within the Django authentication system are represented by this model.
30+
31+    Username and password are required. Other fields are optional.
32+    """
33+    username = models.CharField(_('username'), max_length=30, unique=True, validator_list=[validators.isAlphaNumeric], help_text=_("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores)."))
34+    first_name = models.CharField(_('first name'), max_length=30, blank=True)
35+    last_name = models.CharField(_('last name'), max_length=30, blank=True)
36+    email = models.EmailField(_('e-mail address'), blank=True)
37+    password = models.CharField(_('password'), max_length=128, help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>."))
38+    is_staff = models.BooleanField(_('staff status'), default=False, help_text=_("Designates whether the user can log into this admin site."))
39+    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."))
40+    is_superuser = models.BooleanField(_('superuser status'), default=False, help_text=_("Designates that this user has all permissions without explicitly assigning them."))
41+    last_login = models.DateTimeField(_('last login'), default=datetime.datetime.now)
42+    date_joined = models.DateTimeField(_('date joined'), default=datetime.datetime.now)
43+    groups = models.ManyToManyField(Group, verbose_name=_('groups'), blank=True,
44+        help_text=_("In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in."))
45+    user_permissions = models.ManyToManyField(Permission, verbose_name=_('user permissions'), blank=True)
46+    objects = UserManager()
47Index: django/contrib/auth/models.py
48===================================================================
49--- django/contrib/auth/models.py       (revision 6023)
50+++ django/contrib/auth/models.py       (working copy)
51@@ -4,6 +4,7 @@
52 from django.contrib.contenttypes.models import ContentType
53 from django.utils.encoding import smart_str
54 from django.utils.translation import ugettext_lazy as _
55+from django.conf import settings
56 import datetime
57 import urllib
58 
59@@ -103,26 +104,8 @@
60         from random import choice
61         return ''.join([choice(allowed_chars) for i in range(length)])
62 
63-class User(models.Model):
64-    """Users within the Django authentication system are represented by this model.
65 
66-    Username and password are required. Other fields are optional.
67-    """
68-    username = models.CharField(_('username'), max_length=30, unique=True, validator_list=[validators.isAlphaNumeric], help_text=_("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores)."))
69-    first_name = models.CharField(_('first name'), max_length=30, blank=True)
70-    last_name = models.CharField(_('last name'), max_length=30, blank=True)
71-    email = models.EmailField(_('e-mail address'), blank=True)
72-    password = models.CharField(_('password'), max_length=128, help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>."))
73-    is_staff = models.BooleanField(_('staff status'), default=False, help_text=_("Designates whether the user can log into this admin site."))
74-    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."))
75-    is_superuser = models.BooleanField(_('superuser status'), default=False, help_text=_("Designates that this user has all permissions without explicitly assigning them."))
76-    last_login = models.DateTimeField(_('last login'), default=datetime.datetime.now)
77-    date_joined = models.DateTimeField(_('date joined'), default=datetime.datetime.now)
78-    groups = models.ManyToManyField(Group, verbose_name=_('groups'), blank=True,
79-        help_text=_("In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in."))
80-    user_permissions = models.ManyToManyField(Permission, verbose_name=_('user permissions'), blank=True, filter_interface=models.HORIZONTAL)
81-    objects = UserManager()
82-
83+class UserTemplate(object):
84     class Meta:
85         verbose_name = _('user')
86         verbose_name_plural = _('users')
87@@ -280,6 +263,22 @@
88                 raise SiteProfileNotAvailable
89         return self._profile_cache
90 
91+
92+# Grab the AUTH_USER_MODULE path and classname from the settings.
93+# auth_user_module_parts[0] = module path
94+# auth_user_module_parts[1] = class name
95+auth_user_module_parts = settings.AUTH_USER_MODULE.rsplit('.', 1)
96+auth_user_module = __import__(auth_user_module_parts[0], {}, {}, [auth_user_module_parts[0]])
97+# Store the auth_user model so it is accessible with the standard 'from django.contrib.auth.models import User'
98+User = getattr(auth_user_module, auth_user_module_parts[1])
99+
100+# Add the User model to the django models cache
101+# These two lines allow the custom auth_user model to play nicely with syncdb and other systems that rely
102+# on functions like django.db.models.loading.get_model(...)
103+from django.db.models.loading import cache
104+cache.register_models('auth', User)
105+
106+
107 class Message(models.Model):
108     """
109     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.