From 1510c3efda4d3dfdb49060f1ed66929c07dbf73a Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sun, 20 Nov 2011 10:58:20 +0000 Subject: [PATCH] Upgraded django.contrib.comments to be compatible with time zone support. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17123 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/comments/forms.py | 4 ++-- django/contrib/comments/models.py | 6 +++--- django/contrib/comments/moderation.py | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/django/contrib/comments/forms.py b/django/contrib/comments/forms.py index 1c612362cc..05c4afebe1 100644 --- a/django/contrib/comments/forms.py +++ b/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.contrib.comments.models import Comment 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 @@ class CommentDetailsForm(CommentSecurityForm): 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, diff --git a/django/contrib/comments/models.py b/django/contrib/comments/models.py index 5e128d2edb..e0ef8b3d28 100644 --- a/django/contrib/comments/models.py +++ b/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.contrib.sites.models import Site 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 @@ class Comment(BaseCommentAbstractModel): 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 @@ class CommentFlag(models.Model): 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) diff --git a/django/contrib/comments/moderation.py b/django/contrib/comments/moderation.py index 17d61dadd6..9b206a5bad 100644 --- a/django/contrib/comments/moderation.py +++ b/django/contrib/comments/moderation.py @@ -63,6 +63,7 @@ from django.db.models.base import ModelBase 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 @@ class CommentModerator(object): 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 @@ class CommentModerator(object): """ 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