Ticket #3011: 3011-r10115.diff

File 3011-r10115.diff, 2.9 KB (added by seocam, 6 years ago)

New patch against the trunk [10115]

  • django/conf/global_settings.py

     
    379379# The number of days a password reset link is valid for
    380380PASSWORD_RESET_TIMEOUT_DAYS = 3
    381381
     382# The class to use as the default AUTH_USER for the authentication system.
     383AUTH_USER_MODULE = None
     384
    382385###########
    383386# TESTING #
    384387###########
  • django/contrib/auth/models.py

     
    11import datetime
    22import urllib
    33
     4from django.conf import settings
    45from django.contrib import auth
    56from django.core.exceptions import ImproperlyConfigured
    67from django.db import models
     
    119120        from random import choice
    120121        return ''.join([choice(allowed_chars) for i in range(length)])
    121122
    122 class User(models.Model):
     123class UserTemplate(models.Model):
    123124    """Users within the Django authentication system are represented by this model.
    124125
    125126    Username and password are required. Other fields are optional.
     
    142143    class Meta:
    143144        verbose_name = _('user')
    144145        verbose_name_plural = _('users')
     146        abstract = True
    145147
    146148    def __unicode__(self):
    147149        return self.username
     
    287289                raise SiteProfileNotAvailable
    288290        return self._profile_cache
    289291
     292if settings.AUTH_USER_MODULE is not None:
     293    # Grab the AUTH_USER_MODULE path and classname from the settings. 
     294    # auth_user_module_parts[0] = module path 
     295    # auth_user_module_parts[1] = class name 
     296    auth_user_module_parts = settings.AUTH_USER_MODULE.rsplit('.', 1) 
     297    auth_user_module = __import__(auth_user_module_parts[0], {}, {}, [auth_user_module_parts[0]]) 
     298    # Store the auth_user model so it is accessible with the standard 
     299    # 'from django.contrib.auth.models import User' 
     300    User = getattr(auth_user_module, auth_user_module_parts[1]) 
     301
     302    # Add te User model to the django models cache 
     303    # These two lines allow the custom auth_user model to play nicely with syncdb 
     304    # and other systems that rely on functions like 
     305    # django.db.models.loading.get_model(...) 
     306    from django.db.models.loading import cache 
     307    cache.register_models('auth', User)
     308     
     309    # We need to remove whatever we used as the AUTH_USER_MODUlE from the
     310    # db cache so apps like contenttypes don't think that it's part
     311    # of contrib.auth
     312    del cache.app_models['auth'][auth_user_module_parts[1].lower()]
     313else:
     314    class User(UserTemplate):
     315        class Meta:
     316            verbose_name = _('user')
     317            verbose_name_plural = _('users')
     318     
     319
    290320class Message(models.Model):
    291321    """
    292322    The message system is a lightweight way to queue messages for given
Back to Top