Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions notification/atomformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@
# THE SOFTWARE.
#

try:
from django.utils.timezone import now
except ImportError:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment telling something like "Django.utils.timezone introduced in Django 1.4" or "Backward compatibility for Django < 1.4" may be useful for the ones who read the code.

from datetime import datetime
now = datetime.now

from xml.sax.saxutils import XMLGenerator
from datetime import datetime


GENERATOR_TEXT = 'django-atompub'
Expand Down Expand Up @@ -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):
Expand Down
6 changes: 5 additions & 1 deletion notification/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about something like:

try:
    from django.utils.timezone import utc
except ImportError:
    utc = None
return datetime.datetime(year=2008, month=7, day=1, tzinfo=utc)

I mean:

  • same call to datetime.datetime()
  • ability to move the try/import/except to the beginning of the module ?

return qs.latest("added").added

def feed_links(self, user):
Expand Down
6 changes: 5 additions & 1 deletion notification/management/commands/remove_old_notices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 8 additions & 4 deletions notification/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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"))
Expand Down