Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Adds Django 1.4 timezone support #5

Open
wants to merge 1 commit into from

6 participants

@madron

... and (hopefully) it doesn't break 1.3 compatibility. ;-)

@pennersr

Would it be possible to release a new pypi version that is Django 1.4 friendly as far as timezones are concerned?

I see users struggling with this, resulting in bug reports like pennersr/django-allauth#71. Ideally, I do not want to introduce yet another fork.

A mini maintenance release including just this would be greatly appreciated, thanks.

@josefdlange

I would benefit very much from this update to emailconfirmation.

@jmcvetta

Likewise, a maintenance release with this change would be much appreciated.

@fceruti

Is pinax project dead?

@jtauber
Owner

No, pinax project is not dead. But much of the functionality of this app has been rolled into Django User Accounts (https://github.com/pinax/django-user-accounts). We're still working out what best to do with legacy code like this but we will try to get an update out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 25, 2012
  1. @madron

    Django 1.4 Timezone support

    madron authored
This page is out of date. Refresh to see the latest.
Showing with 24 additions and 18 deletions.
  1. +24 −18 emailconfirmation/models.py
View
42 emailconfirmation/models.py
@@ -14,10 +14,16 @@
from emailconfirmation.signals import email_confirmed, email_confirmation_sent
+try:
+ from django.utils.timezone import now
+except ImportError:
+ now = datetime.datetime.now
+
+
# this code based in-part on django-registration
class EmailAddressManager(models.Manager):
-
+
def add_email(self, user, email):
try:
email_address = self.create(user=user, email=email)
@@ -25,13 +31,13 @@ def add_email(self, user, email):
return email_address
except IntegrityError:
return None
-
+
def get_primary(self, user):
try:
return self.get(user=user, primary=True)
except EmailAddress.DoesNotExist:
return None
-
+
def get_users_for(self, email):
"""
returns a list of users with the given email.
@@ -43,14 +49,14 @@ def get_users_for(self, email):
class EmailAddress(models.Model):
-
+
user = models.ForeignKey(User)
email = models.EmailField()
verified = models.BooleanField(default=False)
primary = models.BooleanField(default=False)
-
+
objects = EmailAddressManager()
-
+
def set_as_primary(self, conditional=False):
old_primary = EmailAddress.objects.get_primary(self.user)
if old_primary:
@@ -63,10 +69,10 @@ def set_as_primary(self, conditional=False):
self.user.email = self.email
self.user.save()
return True
-
+
def __unicode__(self):
return u"%s (%s)" % (self.email, self.user)
-
+
class Meta:
verbose_name = _("email address")
verbose_name_plural = _("email addresses")
@@ -76,7 +82,7 @@ class Meta:
class EmailConfirmationManager(models.Manager):
-
+
def confirm_email(self, confirmation_key):
try:
confirmation = self.get(confirmation_key=confirmation_key)
@@ -89,7 +95,7 @@ def confirm_email(self, confirmation_key):
email_address.save()
email_confirmed.send(sender=self.model, email_address=email_address)
return email_address
-
+
def send_confirmation(self, email_address):
salt = sha_constructor(str(random())).hexdigest()[:5]
confirmation_key = sha_constructor(salt + email_address.email).hexdigest()
@@ -123,7 +129,7 @@ def send_confirmation(self, email_address):
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [email_address.email])
confirmation = self.create(
email_address=email_address,
- sent=datetime.datetime.now(),
+ sent=now(),
confirmation_key=confirmation_key
)
email_confirmation_sent.send(
@@ -131,7 +137,7 @@ def send_confirmation(self, email_address):
confirmation=confirmation,
)
return confirmation
-
+
def delete_expired_confirmations(self):
for confirmation in self.all():
if confirmation.key_expired():
@@ -139,22 +145,22 @@ def delete_expired_confirmations(self):
class EmailConfirmation(models.Model):
-
+
email_address = models.ForeignKey(EmailAddress)
sent = models.DateTimeField()
confirmation_key = models.CharField(max_length=40)
-
+
objects = EmailConfirmationManager()
-
+
def key_expired(self):
expiration_date = self.sent + datetime.timedelta(
days=settings.EMAIL_CONFIRMATION_DAYS)
- return expiration_date <= datetime.datetime.now()
+ return expiration_date <= now()
key_expired.boolean = True
-
+
def __unicode__(self):
return u"confirmation for %s" % self.email_address
-
+
class Meta:
verbose_name = _("email confirmation")
verbose_name_plural = _("email confirmations")
Something went wrong with that request. Please try again.