Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Upgraded django.contrib.comments to be compatible with time zone supp…

…ort.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17123 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 1510c3efda4d3dfdb49060f1ed66929c07dbf73a 1 parent 03cfad4
@aaugustin aaugustin authored
View
4 django/contrib/comments/forms.py
@@ -1,4 +1,3 @@
-import datetime
import time
from django import forms
from django.forms.util import ErrorDict
@@ -8,6 +7,7 @@
from django.utils.crypto import salted_hmac, constant_time_compare
from django.utils.encoding import force_unicode
from django.utils.text import get_text_list
+from django.utils import timezone
from django.utils.translation import ungettext, ugettext_lazy as _
COMMENT_MAX_LENGTH = getattr(settings,'COMMENT_MAX_LENGTH', 3000)
@@ -138,7 +138,7 @@ def get_comment_create_data(self):
user_email = self.cleaned_data["email"],
user_url = self.cleaned_data["url"],
comment = self.cleaned_data["comment"],
- submit_date = datetime.datetime.now(),
+ submit_date = timezone.now(),
site_id = settings.SITE_ID,
is_public = True,
is_removed = False,
View
6 django/contrib/comments/models.py
@@ -1,4 +1,3 @@
-import datetime
from django.contrib.auth.models import User
from django.contrib.comments.managers import CommentManager
from django.contrib.contenttypes import generic
@@ -7,6 +6,7 @@
from django.db import models
from django.core import urlresolvers
from django.utils.translation import ugettext_lazy as _
+from django.utils import timezone
from django.conf import settings
COMMENT_MAX_LENGTH = getattr(settings,'COMMENT_MAX_LENGTH',3000)
@@ -81,7 +81,7 @@ def __unicode__(self):
def save(self, *args, **kwargs):
if self.submit_date is None:
- self.submit_date = datetime.datetime.now()
+ self.submit_date = timezone.now()
super(Comment, self).save(*args, **kwargs)
def _get_userinfo(self):
@@ -187,5 +187,5 @@ def __unicode__(self):
def save(self, *args, **kwargs):
if self.flag_date is None:
- self.flag_date = datetime.datetime.now()
+ self.flag_date = timezone.now()
super(CommentFlag, self).save(*args, **kwargs)
View
5 django/contrib/comments/moderation.py
@@ -63,6 +63,7 @@ class EntryModerator(CommentModerator):
from django.template import Context, loader
from django.contrib import comments
from django.contrib.sites.models import Site
+from django.utils import timezone
class AlreadyModerated(Exception):
"""
@@ -207,7 +208,7 @@ def allow(self, comment, content_object, request):
return False
if self.auto_close_field and self.close_after is not None:
close_after_date = getattr(content_object, self.auto_close_field)
- if close_after_date is not None and self._get_delta(datetime.datetime.now(), close_after_date).days >= self.close_after:
+ if close_after_date is not None and self._get_delta(timezone.now(), close_after_date).days >= self.close_after:
return False
return True
@@ -223,7 +224,7 @@ def moderate(self, comment, content_object, request):
"""
if self.auto_moderate_field and self.moderate_after is not None:
moderate_after_date = getattr(content_object, self.auto_moderate_field)
- if moderate_after_date is not None and self._get_delta(datetime.datetime.now(), moderate_after_date).days >= self.moderate_after:
+ if moderate_after_date is not None and self._get_delta(timezone.now(), moderate_after_date).days >= self.moderate_after:
return True
return False
Please sign in to comment.
Something went wrong with that request. Please try again.