Permalink
Browse files

Add support for django 1.4 timezones.

  • Loading branch information...
1 parent 8158c45 commit cce7516dbf16509ba1e6e4bb55c6c0b7c8b9c7d9 crass committed Mar 5, 2012
Showing with 25 additions and 4 deletions.
  1. +7 −1 social/models.py
  2. +6 −1 social/notification.py
  3. +6 −1 social/shortcuts.py
  4. +6 −1 social/templatetags/dropdown_tags.py
View
@@ -6,6 +6,12 @@
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
+try:
+ from django.utils.timezone import now
+except ImportError:
+ now = datetime.datetime.now
+
+
class SubscriptionManager(models.Manager):
def subscribe(self,user,obj):
ct = ContentType.objects.get_for_model(obj)
@@ -21,5 +27,5 @@ class Subscription(models.Model):
content_type = models.ForeignKey('contenttypes.ContentType')
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey()
- timestamp = models.DateTimeField(editable=False,default=datetime.datetime.now)
+ timestamp = models.DateTimeField(editable=False,default=now)
objects = SubscriptionManager()
@@ -10,6 +10,11 @@
from django.db.models import Model
from django.contrib.contenttypes.models import ContentType
+try:
+ from django.utils.timezone import now
+except ImportError:
+ now = datetime.datetime.now
+
import social
from models import Subscription
from .settings import *
@@ -180,7 +185,7 @@ def __getstate__(self):
self.display()
if not getattr(self, 'sent_at', False):
- self.sent_at = datetime.datetime.now()
+ self.sent_at = now()
return self.__dict__
View
@@ -1,5 +1,10 @@
import datetime
+try:
+ from django.utils.timezone import now
+except ImportError:
+ now = datetime.datetime.now
+
from notification import Notification, Lazy, Variable
def factory(*args, **kwargs):
@@ -16,7 +21,7 @@ def factory(*args, **kwargs):
kwargs[key] = Lazy(value)
if 'timestamp' not in kwargs.keys() and 'sent_at' not in kwargs.keys():
- kwargs['sent_at'] = datetime.datetime.now()
+ kwargs['sent_at'] = now()
return cls(**kwargs)
@@ -3,6 +3,11 @@
from django import template
from django.utils.translation import ugettext, ungettext
+try:
+ from django.utils.timezone import now
+except ImportError:
+ now = datetime.datetime.now
+
import social
register = template.Library()
@@ -44,7 +49,7 @@ def humanize_timesince(date):
if not date:
return ''
- delta = datetime.datetime.now() - date
+ delta = now() - date
num_years = delta.days / 365
if (num_years > 0):

0 comments on commit cce7516

Please sign in to comment.