Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Add some support to Signup Application for Django 1.4 Timezones #40

Closed
wants to merge 1 commit into from

2 participants

Donald Stufft Brian Rosner
Donald Stufft

This change will use django.utils.timezones.now() instead of datetime.datetime.now() when it is available.

django.utils.timezone.now() will return a naive datetime when USE_TZ = False and an aware datetime when USE_TZ = True.

Brian Rosner
Owner

This has been done in django-user-accounts (the future of Pinax account app)

Brian Rosner brosner closed this March 19, 2012
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.

Feb 04, 2012
Donald Stufft Django 1.4 Timezone support for signups 93827fe
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 11 additions and 6 deletions. Show diff stats Hide diff stats

  1. 17  pinax/apps/signup_codes/models.py
17  pinax/apps/signup_codes/models.py
@@ -13,6 +13,11 @@
13 13
 
14 14
 from pinax.apps.signup_codes.signals import signup_code_used
15 15
 
  16
+try:
  17
+    from django.utils.timezone import now
  18
+except ImportError:
  19
+    now = datetime.datetime.now
  20
+
16 21
 
17 22
 class SignupCode(models.Model):
18 23
     
@@ -23,8 +28,8 @@ class SignupCode(models.Model):
23 28
     email = models.EmailField(blank=True)
24 29
     notes = models.TextField(blank=True)
25 30
     sent = models.DateTimeField(null=True, blank=True)
26  
-    created = models.DateTimeField(default=datetime.datetime.now, editable=False)
27  
-    
  31
+    created = models.DateTimeField(default=now, editable=False)
  32
+
28 33
     # calculated
29 34
     use_count = models.PositiveIntegerField(editable=False, default=0)
30 35
     
@@ -33,7 +38,7 @@ def __unicode__(self):
33 38
     
34 39
     @classmethod
35 40
     def create(cls, email, expiry, group=None):
36  
-        expiry = datetime.datetime.now() + datetime.timedelta(hours=expiry)
  41
+        expiry = now() + datetime.timedelta(hours=expiry)
37 42
         bits = [
38 43
             settings.SECRET_KEY,
39 44
             email,
@@ -56,7 +61,7 @@ def check(cls, code):
56 61
                 if signup_code.max_uses and signup_code.max_uses < signup_code.use_count + 1:
57 62
                     return False
58 63
                 else:
59  
-                    if signup_code.expiry and datetime.datetime.now() > signup_code.expiry:
  64
+                    if signup_code.expiry and now() > signup_code.expiry:
60 65
                         return False
61 66
                     else:
62 67
                         return signup_code
@@ -88,7 +93,7 @@ def send(self, group=None):
88 93
         subject = render_to_string("signup_codes/invite_user_subject.txt", ctx)
89 94
         message = render_to_string("signup_codes/invite_user.txt", ctx)
90 95
         send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [self.email])
91  
-        self.sent = datetime.datetime.now()
  96
+        self.sent = now()
92 97
         self.save()
93 98
 
94 99
 
@@ -96,7 +101,7 @@ class SignupCodeResult(models.Model):
96 101
     
97 102
     signup_code = models.ForeignKey(SignupCode)
98 103
     user = models.ForeignKey(User)
99  
-    timestamp = models.DateTimeField(default=datetime.datetime.now)
  104
+    timestamp = models.DateTimeField(default=now)
100 105
 
101 106
 
102 107
 @receiver(post_save, sender=SignupCodeResult)
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.