Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Adds Django 1.4 timezone support #5

Open
wants to merge 1 commit into from

6 participants

Massimiliano Ravelli Raymond Penners Josef Lange Jason McVetta Francisco Ceruti James Tauber
Massimiliano Ravelli

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

Raymond Penners

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.

Josef Lange

I would benefit very much from this update to emailconfirmation.

Jason McVetta

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

Francisco Ceruti

Is pinax project dead?

James Tauber
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

Showing 1 unique commit by 1 author.

Apr 25, 2012
Massimiliano Ravelli Django 1.4 Timezone support afb53b0
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 24 additions and 18 deletions. Show diff stats Hide diff stats

  1. 42  emailconfirmation/models.py
42  emailconfirmation/models.py
@@ -14,10 +14,16 @@
14 14
 
15 15
 from emailconfirmation.signals import email_confirmed, email_confirmation_sent
16 16
 
  17
+try:
  18
+    from django.utils.timezone import now
  19
+except ImportError:
  20
+    now = datetime.datetime.now
  21
+
  22
+
17 23
 # this code based in-part on django-registration
18 24
 
19 25
 class EmailAddressManager(models.Manager):
20  
-    
  26
+
21 27
     def add_email(self, user, email):
22 28
         try:
23 29
             email_address = self.create(user=user, email=email)
@@ -25,13 +31,13 @@ def add_email(self, user, email):
25 31
             return email_address
26 32
         except IntegrityError:
27 33
             return None
28  
-    
  34
+
29 35
     def get_primary(self, user):
30 36
         try:
31 37
             return self.get(user=user, primary=True)
32 38
         except EmailAddress.DoesNotExist:
33 39
             return None
34  
-    
  40
+
35 41
     def get_users_for(self, email):
36 42
         """
37 43
         returns a list of users with the given email.
@@ -43,14 +49,14 @@ def get_users_for(self, email):
43 49
 
44 50
 
45 51
 class EmailAddress(models.Model):
46  
-    
  52
+
47 53
     user = models.ForeignKey(User)
48 54
     email = models.EmailField()
49 55
     verified = models.BooleanField(default=False)
50 56
     primary = models.BooleanField(default=False)
51  
-    
  57
+
52 58
     objects = EmailAddressManager()
53  
-    
  59
+
54 60
     def set_as_primary(self, conditional=False):
55 61
         old_primary = EmailAddress.objects.get_primary(self.user)
56 62
         if old_primary:
@@ -63,10 +69,10 @@ def set_as_primary(self, conditional=False):
63 69
         self.user.email = self.email
64 70
         self.user.save()
65 71
         return True
66  
-    
  72
+
67 73
     def __unicode__(self):
68 74
         return u"%s (%s)" % (self.email, self.user)
69  
-    
  75
+
70 76
     class Meta:
71 77
         verbose_name = _("email address")
72 78
         verbose_name_plural = _("email addresses")
@@ -76,7 +82,7 @@ class Meta:
76 82
 
77 83
 
78 84
 class EmailConfirmationManager(models.Manager):
79  
-    
  85
+
80 86
     def confirm_email(self, confirmation_key):
81 87
         try:
82 88
             confirmation = self.get(confirmation_key=confirmation_key)
@@ -89,7 +95,7 @@ def confirm_email(self, confirmation_key):
89 95
             email_address.save()
90 96
             email_confirmed.send(sender=self.model, email_address=email_address)
91 97
             return email_address
92  
-    
  98
+
93 99
     def send_confirmation(self, email_address):
94 100
         salt = sha_constructor(str(random())).hexdigest()[:5]
95 101
         confirmation_key = sha_constructor(salt + email_address.email).hexdigest()
@@ -123,7 +129,7 @@ def send_confirmation(self, email_address):
123 129
         send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [email_address.email])
124 130
         confirmation = self.create(
125 131
             email_address=email_address,
126  
-            sent=datetime.datetime.now(),
  132
+            sent=now(),
127 133
             confirmation_key=confirmation_key
128 134
         )
129 135
         email_confirmation_sent.send(
@@ -131,7 +137,7 @@ def send_confirmation(self, email_address):
131 137
             confirmation=confirmation,
132 138
         )
133 139
         return confirmation
134  
-    
  140
+
135 141
     def delete_expired_confirmations(self):
136 142
         for confirmation in self.all():
137 143
             if confirmation.key_expired():
@@ -139,22 +145,22 @@ def delete_expired_confirmations(self):
139 145
 
140 146
 
141 147
 class EmailConfirmation(models.Model):
142  
-    
  148
+
143 149
     email_address = models.ForeignKey(EmailAddress)
144 150
     sent = models.DateTimeField()
145 151
     confirmation_key = models.CharField(max_length=40)
146  
-    
  152
+
147 153
     objects = EmailConfirmationManager()
148  
-    
  154
+
149 155
     def key_expired(self):
150 156
         expiration_date = self.sent + datetime.timedelta(
151 157
             days=settings.EMAIL_CONFIRMATION_DAYS)
152  
-        return expiration_date <= datetime.datetime.now()
  158
+        return expiration_date <= now()
153 159
     key_expired.boolean = True
154  
-    
  160
+
155 161
     def __unicode__(self):
156 162
         return u"confirmation for %s" % self.email_address
157  
-    
  163
+
158 164
     class Meta:
159 165
         verbose_name = _("email confirmation")
160 166
         verbose_name_plural = _("email confirmations")
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.