Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for my issue: django 1.4 USE_TZ compat #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 persistent_messages/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link

Choose a reason for hiding this comment

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

The code is good, but the comment is wrong.

from django.utils.timezone import now

This only works with Django 1.4+

@philomat it would be good if an updated release was available which worked with Django 1.4 directly

def get_user(request):
if hasattr(request, 'user') and request.user.__class__ != AnonymousUser:
Expand All @@ -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
Expand Down