diff --git a/notification/atomformat.py b/notification/atomformat.py index 756feeb8..2fe27a9c 100644 --- a/notification/atomformat.py +++ b/notification/atomformat.py @@ -28,8 +28,13 @@ # THE SOFTWARE. # +try: + from django.utils.timezone import now +except ImportError: + from datetime import datetime + now = datetime.now + from xml.sax.saxutils import XMLGenerator -from datetime import datetime GENERATOR_TEXT = 'django-atompub' @@ -232,7 +237,7 @@ def latest_updated(self): updates.sort() return updates[-1] else: - return datetime.now() # @@@ really we should allow a feed to define its "start" for this case + return now() # @@@ really we should allow a feed to define its "start" for this case def write_text_construct(self, handler, element_name, data): diff --git a/notification/feeds.py b/notification/feeds.py index 7c1f46d0..3620bd55 100644 --- a/notification/feeds.py +++ b/notification/feeds.py @@ -66,7 +66,11 @@ def feed_updated(self, user): # must be a feed_updated field as per the Atom specifications, however # there is no real data to go by, and an arbitrary date can be static. if qs.count() == 0: - return datetime.datetime(year=2008, month=7, day=1) + try: + from django.utils.timezone import utc + return datetime.datetime(year=2008, month=7, day=1, tzinfo=utc) + except ImportError: + return datetime.datetime(year=2008, month=7, day=1) return qs.latest("added").added def feed_links(self, user): diff --git a/notification/management/commands/remove_old_notices.py b/notification/management/commands/remove_old_notices.py index 1139bd49..0abe93b9 100644 --- a/notification/management/commands/remove_old_notices.py +++ b/notification/management/commands/remove_old_notices.py @@ -24,7 +24,11 @@ class Command(BaseCommand): def handle(self, *args, **options): dryrun = options['dryrun'] limit = time() - settings.NOTICES_MAX_AGE - limit = datetime.fromtimestamp(limit) + try: + from django.utils.timezone import make_aware, utc + limit = make_aware(datetime.fromtimestamp(limit), utc) + except ImportError: + limit = datetime.fromtimestamp(limit) notices = Notice.objects.filter(added__lte=limit) if dryrun: count = notices.count() diff --git a/notification/models.py b/notification/models.py index 2a2e3403..899fde25 100644 --- a/notification/models.py +++ b/notification/models.py @@ -1,10 +1,14 @@ -import datetime - try: import cPickle as pickle except ImportError: import pickle +try: + from django.utils.timezone import now +except ImportError: + from datetime import datetime + now = datetime.now + from django.db import models from django.db.models.query import QuerySet from django.conf import settings @@ -151,7 +155,7 @@ class Notice(models.Model): sender = models.ForeignKey(User, null=True, related_name="sent_notices", verbose_name=_("sender")) message = models.TextField(_("message")) notice_type = models.ForeignKey(NoticeType, verbose_name=_("notice type")) - added = models.DateTimeField(_("added"), default=datetime.datetime.now) + added = models.DateTimeField(_("added"), default=now) unseen = models.BooleanField(_("unseen"), default=True) archived = models.BooleanField(_("archived"), default=False) on_site = models.BooleanField(_("on site")) @@ -415,7 +419,7 @@ class ObservedItem(models.Model): notice_type = models.ForeignKey(NoticeType, verbose_name=_("notice type")) - added = models.DateTimeField(_("added"), default=datetime.datetime.now) + added = models.DateTimeField(_("added"), default=now) # the signal that will be listened to send the notice signal = models.TextField(verbose_name=_("signal"))