Skip to content

Commit

Permalink
Upgraded django.contrib.auth to be compatible with time zone support.
Browse files Browse the repository at this point in the history
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17122 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
aaugustin committed Nov 20, 2011
1 parent 4ac594f commit 03cfad4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 5 additions & 5 deletions django/contrib/auth/models.py
@@ -1,4 +1,3 @@
import datetime
import urllib

from django.core.exceptions import ImproperlyConfigured
Expand All @@ -7,6 +6,7 @@
from django.db.models.manager import EmptyManager
from django.utils.encoding import smart_str
from django.utils.translation import ugettext_lazy as _
from django.utils import timezone

from django.contrib import auth
from django.contrib.auth.signals import user_logged_in
Expand All @@ -21,7 +21,7 @@ def update_last_login(sender, user, **kwargs):
A signal receiver which updates the last_login date for
the user logging in.
"""
user.last_login = datetime.datetime.now()
user.last_login = timezone.now()
user.save()
user_logged_in.connect(update_last_login)

Expand Down Expand Up @@ -91,7 +91,7 @@ def create_user(self, username, email=None, password=None):
"""
Creates and saves a User with the given username, email and password.
"""
now = datetime.datetime.now()
now = timezone.now()

# Normalize the address by lowercasing the domain part of the email
# address.
Expand Down Expand Up @@ -181,8 +181,8 @@ class User(models.Model):
is_staff = models.BooleanField(_('staff status'), default=False, help_text=_("Designates whether the user can log into this admin site."))
is_active = models.BooleanField(_('active'), default=True, help_text=_("Designates whether this user should be treated as active. Unselect this instead of deleting accounts."))
is_superuser = models.BooleanField(_('superuser status'), default=False, help_text=_("Designates that this user has all permissions without explicitly assigning them."))
last_login = models.DateTimeField(_('last login'), default=datetime.datetime.now)
date_joined = models.DateTimeField(_('date joined'), default=datetime.datetime.now)
last_login = models.DateTimeField(_('last login'), default=timezone.now)
date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
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."))
user_permissions = models.ManyToManyField(Permission, verbose_name=_('user permissions'), blank=True)
Expand Down
3 changes: 3 additions & 0 deletions django/contrib/auth/tests/remote_user.py
Expand Up @@ -4,6 +4,7 @@
from django.contrib.auth.backends import RemoteUserBackend
from django.contrib.auth.models import User
from django.test import TestCase
from django.utils import timezone


class RemoteUserTest(TestCase):
Expand Down Expand Up @@ -80,6 +81,8 @@ def test_last_login(self):
user = User.objects.create(username='knownuser')
# Set last_login to something so we can determine if it changes.
default_login = datetime(2000, 1, 1)
if settings.USE_TZ:
default_login = default_login.replace(tzinfo=timezone.utc)
user.last_login = default_login
user.save()

Expand Down

0 comments on commit 03cfad4

Please sign in to comment.