1. Jacco Flenter
  2. django-scm_core

Commits

Jacco Flenter  committed 27ee735

usage of django.utils.timezone.now is used instead of datetime.now (timezone
aware)

  • Participants
  • Parent commits 602672a
  • Branches default

Comments (0)

Files changed (2)

File scm_core/models.py

View file
  • Ignore whitespace
 from hashlib import sha1
-from datetime import datetime
+#from datetime import datetime
+from django.utils import timezone
 
 from django.db import models
 
 
     def filter(self, *args, **kwargs):
         kwargs['publish_state'] = PUBLISH_STATE_PUBLISHED
-        kwargs['publish_date__lte'] = datetime.now
+        kwargs['publish_date__lte'] = timezone.now
 
         return super(LiveManager, self).filter(*args, **kwargs)
 
     def all(self, *args, **kwargs):
         kwargs['publish_state'] = PUBLISH_STATE_PUBLISHED
-        kwargs['publish_date__lte'] = datetime.now
+        kwargs['publish_date__lte'] = timezone.now
         return self.filter(*args, **kwargs)
 
     def count(self, *args, **kwargs):
         kwargs['publish_state'] = PUBLISH_STATE_PUBLISHED
-        kwargs['publish_date__lte'] = datetime.now
+        kwargs['publish_date__lte'] = timezone.now
         return self.filter(*args, **kwargs).count()
 
     def get(self, *args, **kwargs):
         kwargs['publish_state'] = PUBLISH_STATE_PUBLISHED
-        kwargs['publish_date__lte'] = datetime.now
+        kwargs['publish_date__lte'] = timezone.now
 
         return super(LiveManager, self).get(*args, **kwargs)
 
     )
 
     publish_date = models.DateTimeField(
-        default=datetime.now,
+        default=timezone.now,
         verbose_name=_('publish date')
     )
     date_created = models.DateTimeField(
     )
 
     def is_published(self):
-        """returns true if the status == published and the datetime.now
+        """returns true if the status == published and the timezone.now
         is >= publish_date
         """
         if(
-            self.publish_date < datetime.now() and
+            self.publish_date < timezone.now() and
             self.publish_state == PUBLISH_STATE_PUBLISHED):
 
             return True

File scm_core/tests.py

View file
  • Ignore whitespace
 
         self.assertEqual(model_test.is_published(), True)
 
-        from datetime import datetime, timedelta
+        from datetime import timedelta
+        from django.utils import timezone
 
-        publish_date = datetime.now() + timedelta(days=3)
+        publish_date = timezone.now() + timedelta(days=3)
 
         model_test = TestingModel(
                 publish_date=publish_date,