From b0636cb16a00e388758a4601374922c0b46aeda1 Mon Sep 17 00:00:00 2001 From: David Wheaton Date: Sun, 22 Apr 2012 18:49:09 -0700 Subject: [PATCH] django 1.4 timezone aware datetime fix --- persistent_messages/storage.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/persistent_messages/storage.py b/persistent_messages/storage.py index 67caf91..aac80c0 100644 --- a/persistent_messages/storage.py +++ b/persistent_messages/storage.py @@ -5,7 +5,12 @@ from django.contrib.auth.models import AnonymousUser from django.contrib.messages.storage.fallback import FallbackStorage from django.db.models import Q -import datetime + +try: + from django.utils.timezone import now # pre Django 1.4 +except ImportError: + from datetime import datetime # Django 1.4 + now = datetime.now def get_user(request): if hasattr(request, 'user') and request.user.__class__ != AnonymousUser: @@ -29,7 +34,7 @@ def __init__(self, *args, **kwargs): self.is_anonymous = not get_user(self.request).is_authenticated() def _message_queryset(self, exclude_unread=True): - qs = Message.objects.filter(user=get_user(self.request)).filter(Q(expires=None) | Q(expires__gt=datetime.datetime.now())) + qs = Message.objects.filter(user=get_user(self.request)).filter(Q(expires=None) | Q(expires__gt=now())) if exclude_unread: qs = qs.exclude(read=True) return qs