Skip to content

Commit

Permalink
Add support for django 1.4 timezones.
Browse files Browse the repository at this point in the history
  • Loading branch information
crass committed Mar 5, 2012
1 parent 8158c45 commit cce7516
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
8 changes: 7 additions & 1 deletion social/models.py
Expand Up @@ -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)
Expand All @@ -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()
7 changes: 6 additions & 1 deletion social/notification.py
Expand Up @@ -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 *
Expand Down Expand Up @@ -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__

Expand Down
7 changes: 6 additions & 1 deletion social/shortcuts.py
@@ -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):
Expand All @@ -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)

Expand Down
7 changes: 6 additions & 1 deletion social/templatetags/dropdown_tags.py
Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit cce7516

Please sign in to comment.