Ticket #3011: 3011.diff

File 3011.diff, 8.6 KB (added by Gary Wilson <gary.wilson@…>, 17 years ago)

patch against [4462]

  • django/contrib/auth/auth/models.py

    === added directory 'django/contrib/auth/auth'
    === added file 'django/contrib/auth/auth/models.py'
     
     1from django.core import validators
     2from django.db import backend, connection, models
     3from django.utils.translation import gettext_lazy as _
     4from django.contrib.auth.models import Group, Permission, UserManager, UserTemplate
     5
     6class User(models.Model, UserTemplate):
     7    """Users within the Django authentication system are represented by this model.
     8
     9    Username and password are required. Other fields are optional.
     10    """
     11    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)."))
     12    first_name = models.CharField(_('first name'), maxlength=30, blank=True)
     13    last_name = models.CharField(_('last name'), maxlength=30, blank=True)
     14    email = models.EmailField(_('e-mail address'), blank=True)
     15    password = models.CharField(_('password'), maxlength=128, help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>."))
     16    is_staff = models.BooleanField(_('staff status'), default=False, help_text=_("Designates whether the user can log into this admin site."))
     17    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."))
     18    is_superuser = models.BooleanField(_('superuser status'), default=False, help_text=_("Designates that this user has all permissions without explicitly assigning them."))
     19    last_login = models.DateTimeField(_('last login'), default=models.LazyDate())
     20    date_joined = models.DateTimeField(_('date joined'), default=models.LazyDate())
     21    groups = models.ManyToManyField(Group, verbose_name=_('groups'), blank=True,
     22        help_text=_("In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in."))
     23    user_permissions = models.ManyToManyField(Permission, verbose_name=_('user permissions'), blank=True, filter_interface=models.HORIZONTAL)
     24    objects = UserManager()
     25    class Meta:
     26        verbose_name = _('user')
     27        verbose_name_plural = _('users')
     28        ordering = ('username',)
     29        db_table = 'auth_user'
     30    class Admin:
     31        fields = (
     32            (None, {'fields': ('username', 'password')}),
     33            (_('Personal info'), {'fields': ('first_name', 'last_name', 'email')}),
     34            (_('Permissions'), {'fields': ('is_staff', 'is_active', 'is_superuser', 'user_permissions')}),
     35            (_('Important dates'), {'fields': ('last_login', 'date_joined')}),
     36            (_('Groups'), {'fields': ('groups',)}),
     37        )
     38        list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff')
     39        list_filter = ('is_staff', 'is_superuser')
     40        search_fields = ('username', 'first_name', 'last_name', 'email')
     41
     42    def __str__(self):
     43        return self.username
  • django/conf/global_settings.py

    === modified file 'django/conf/global_settings.py'
     
    315315# The name of the database to use for testing purposes.
    316316# If None, a name of 'test_' + DATABASE_NAME will be assumed
    317317TEST_DATABASE_NAME = None
     318
     319# The class to use as the default AUTH_USER for the authentication system.
     320AUTH_USER_MODULE = 'django.contrib.auth.auth.models.User'
  • django/contrib/auth/models.py

    === modified file 'django/contrib/auth/models.py'
     
    33from django.db import backend, connection, models
    44from django.contrib.contenttypes.models import ContentType
    55from django.utils.translation import gettext_lazy as _
     6from django.conf import settings
    67import datetime
    78
    89def check_password(raw_password, enc_password):
     
    8283        from random import choice
    8384        return ''.join([choice(allowed_chars) for i in range(length)])
    8485
    85 class User(models.Model):
    86     """Users within the Django authentication system are represented by this model.
    87 
    88     Username and password are required. Other fields are optional.
    89     """
    90     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)."))
    91     first_name = models.CharField(_('first name'), maxlength=30, blank=True)
    92     last_name = models.CharField(_('last name'), maxlength=30, blank=True)
    93     email = models.EmailField(_('e-mail address'), blank=True)
    94     password = models.CharField(_('password'), maxlength=128, help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>."))
    95     is_staff = models.BooleanField(_('staff status'), default=False, help_text=_("Designates whether the user can log into this admin site."))
    96     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."))
    97     is_superuser = models.BooleanField(_('superuser status'), default=False, help_text=_("Designates that this user has all permissions without explicitly assigning them."))
    98     last_login = models.DateTimeField(_('last login'), default=models.LazyDate())
    99     date_joined = models.DateTimeField(_('date joined'), default=models.LazyDate())
    100     groups = models.ManyToManyField(Group, verbose_name=_('groups'), blank=True,
    101         help_text=_("In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in."))
    102     user_permissions = models.ManyToManyField(Permission, verbose_name=_('user permissions'), blank=True, filter_interface=models.HORIZONTAL)
    103     objects = UserManager()
    104     class Meta:
    105         verbose_name = _('user')
    106         verbose_name_plural = _('users')
    107         ordering = ('username',)
    108     class Admin:
    109         fields = (
    110             (None, {'fields': ('username', 'password')}),
    111             (_('Personal info'), {'fields': ('first_name', 'last_name', 'email')}),
    112             (_('Permissions'), {'fields': ('is_staff', 'is_active', 'is_superuser', 'user_permissions')}),
    113             (_('Important dates'), {'fields': ('last_login', 'date_joined')}),
    114             (_('Groups'), {'fields': ('groups',)}),
    115         )
    116         list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff')
    117         list_filter = ('is_staff', 'is_superuser')
    118         search_fields = ('username', 'first_name', 'last_name', 'email')
    119 
    120     def __str__(self):
    121         return self.username
    122 
     86class UserTemplate:
    12387    def get_absolute_url(self):
    12488        return "/users/%s/" % self.username
    12589
     
    240204        SiteProfileNotAvailable if this site does not allow profiles.
    241205        """
    242206        if not hasattr(self, '_profile_cache'):
    243             from django.conf import settings
    244207            if not settings.AUTH_PROFILE_MODULE:
    245208                raise SiteProfileNotAvailable
    246209            try:
     
    250213            except (ImportError, ImproperlyConfigured):
    251214                raise SiteProfileNotAvailable
    252215        return self._profile_cache
     216   
     217
     218# Grab the AUTH_USER_MODULE path and classname from the settings.
     219# auth_user_module_parts[0] = module path
     220# auth_user_module_parts[1] = class name
     221auth_user_module_parts = settings.AUTH_USER_MODULE.rsplit('.', 1)
     222auth_user_module = __import__(auth_user_module_parts[0], {}, {}, [auth_user_module_parts[0]])
     223# Store the auth_user model so it is accessible with the standard 'from django.contrib.auth.models import User'
     224User = getattr(auth_user_module, auth_user_module_parts[1])
     225
     226# Add the User model to the django db _app_models cache
     227# These two lines allow the custom auth_user model to play nicely with syncdb and other systems that rely
     228# on functions like django.db.models.loading.get_model(...)
     229from django.db.models.loading import _app_models
     230_app_models['auth'].update({'user':User})
    253231
    254232class Message(models.Model):
    255233    """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.
Back to Top