Skip to content

Commit

Permalink
Merge pull request #113 from funkybob/feature/now
Browse files Browse the repository at this point in the history
Remove custom now() function
  • Loading branch information
zhang-z committed Jan 1, 2016
2 parents 7dc21ef + 5944862 commit bfeb533
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions notifications/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import datetime
from django.conf import settings
from django.contrib.contenttypes.models import ContentType

from django import get_version
from django.utils import timezone

from distutils.version import StrictVersion

if StrictVersion(get_version()) >= StrictVersion('1.8.0'):
Expand All @@ -23,18 +23,6 @@
from django.contrib.auth.models import Group


def now():
# Needs to be be a function as USE_TZ can change based on if we are testing or not.
_now = datetime.datetime.now
if getattr(settings, 'USE_TZ'):
try:
from django.utils import timezone
_now = timezone.now
except ImportError:
pass
return _now()


# SOFT_DELETE = getattr(settings, 'NOTIFICATIONS_SOFT_DELETE', False)
def is_soft_delete():
# TODO: SOFT_DELETE = getattr(settings, ...) doesn't work with "override_settings" decorator in unittest
Expand Down Expand Up @@ -181,7 +169,7 @@ class Notification(models.Model):
action_object_object_id = models.CharField(max_length=255, blank=True, null=True)
action_object = GenericForeignKey('action_object_content_type', 'action_object_object_id')

timestamp = models.DateTimeField(default=now)
timestamp = models.DateTimeField(default=timezone.now)

public = models.BooleanField(default=True)
deleted = models.BooleanField(default=False)
Expand Down Expand Up @@ -257,7 +245,7 @@ def notify_handler(verb, **kwargs):
]
public = bool(kwargs.pop('public', True))
description = kwargs.pop('description', None)
timestamp = kwargs.pop('timestamp', now())
timestamp = kwargs.pop('timestamp', timezone.now())
level = kwargs.pop('level', Notification.LEVELS.info)

# Check if User or Group
Expand Down

0 comments on commit bfeb533

Please sign in to comment.