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
This commit is contained in:
Aymeric Augustin 2011-11-20 10:58:20 +00:00
parent 03cfad4198
commit 1510c3efda
3 changed files with 8 additions and 7 deletions

View File

@ -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,

View File

@ -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)

View File

@ -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