mirror of https://github.com/django/django.git
Style fixes.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7038 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
ff707f502c
commit
332e68d550
|
@ -1,25 +1,27 @@
|
|||
import datetime
|
||||
|
||||
from django.db import models
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.sites.models import Site
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.conf import settings
|
||||
import datetime
|
||||
|
||||
MIN_PHOTO_DIMENSION = 5
|
||||
MAX_PHOTO_DIMENSION = 1000
|
||||
|
||||
# option codes for comment-form hidden fields
|
||||
# Option codes for comment-form hidden fields.
|
||||
PHOTOS_REQUIRED = 'pr'
|
||||
PHOTOS_OPTIONAL = 'pa'
|
||||
RATINGS_REQUIRED = 'rr'
|
||||
RATINGS_OPTIONAL = 'ra'
|
||||
IS_PUBLIC = 'ip'
|
||||
|
||||
# what users get if they don't have any karma
|
||||
# What users get if they don't have any karma.
|
||||
DEFAULT_KARMA = 5
|
||||
KARMA_NEEDED_BEFORE_DISPLAYED = 3
|
||||
|
||||
|
||||
class CommentManager(models.Manager):
|
||||
def get_security_hash(self, options, photo_options, rating_options, target):
|
||||
"""
|
||||
|
@ -61,7 +63,9 @@ class CommentManager(models.Manager):
|
|||
return True
|
||||
return False
|
||||
|
||||
|
||||
class Comment(models.Model):
|
||||
"""A comment by a registered user."""
|
||||
user = models.ForeignKey(User, raw_id_admin=True)
|
||||
content_type = models.ForeignKey(ContentType)
|
||||
object_id = models.IntegerField(_('object ID'))
|
||||
|
@ -86,10 +90,12 @@ class Comment(models.Model):
|
|||
is_removed = models.BooleanField(_('is removed'), help_text=_('Check this box if the comment is inappropriate. A "This comment has been removed" message will be displayed instead.'))
|
||||
site = models.ForeignKey(Site)
|
||||
objects = CommentManager()
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('comment')
|
||||
verbose_name_plural = _('comments')
|
||||
ordering = ('-submit_date',)
|
||||
|
||||
class Admin:
|
||||
fields = (
|
||||
(None, {'fields': ('content_type', 'object_id', 'site')}),
|
||||
|
@ -134,7 +140,7 @@ class Comment(models.Model):
|
|||
get_content_object.short_description = _('Content object')
|
||||
|
||||
def _fill_karma_cache(self):
|
||||
"Helper function that populates good/bad karma caches"
|
||||
"""Helper function that populates good/bad karma caches."""
|
||||
good, bad = 0, 0
|
||||
for k in self.karmascore_set:
|
||||
if k.score == -1:
|
||||
|
@ -163,8 +169,9 @@ class Comment(models.Model):
|
|||
{'user': self.user.username, 'date': self.submit_date,
|
||||
'comment': self.comment, 'domain': self.site.domain, 'url': self.get_absolute_url()}
|
||||
|
||||
|
||||
class FreeComment(models.Model):
|
||||
# A FreeComment is a comment by a non-registered user.
|
||||
"""A comment by a non-registered user."""
|
||||
content_type = models.ForeignKey(ContentType)
|
||||
object_id = models.IntegerField(_('object ID'))
|
||||
comment = models.TextField(_('comment'), max_length=3000)
|
||||
|
@ -175,10 +182,12 @@ class FreeComment(models.Model):
|
|||
# TODO: Change this to is_removed, like Comment
|
||||
approved = models.BooleanField(_('approved by staff'))
|
||||
site = models.ForeignKey(Site)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('free comment')
|
||||
verbose_name_plural = _('free comments')
|
||||
ordering = ('-submit_date',)
|
||||
|
||||
class Admin:
|
||||
fields = (
|
||||
(None, {'fields': ('content_type', 'object_id', 'site')}),
|
||||
|
@ -212,6 +221,7 @@ class FreeComment(models.Model):
|
|||
|
||||
get_content_object.short_description = _('Content object')
|
||||
|
||||
|
||||
class KarmaScoreManager(models.Manager):
|
||||
def vote(self, user_id, comment_id, score):
|
||||
try:
|
||||
|
@ -233,12 +243,14 @@ class KarmaScoreManager(models.Manager):
|
|||
return DEFAULT_KARMA
|
||||
return int(round((4.5 * score) + 5.5))
|
||||
|
||||
|
||||
class KarmaScore(models.Model):
|
||||
user = models.ForeignKey(User)
|
||||
comment = models.ForeignKey(Comment)
|
||||
score = models.SmallIntegerField(_('score'), db_index=True)
|
||||
scored_date = models.DateTimeField(_('score date'), auto_now=True)
|
||||
objects = KarmaScoreManager()
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('karma score')
|
||||
verbose_name_plural = _('karma scores')
|
||||
|
@ -247,6 +259,7 @@ class KarmaScore(models.Model):
|
|||
def __unicode__(self):
|
||||
return _("%(score)d rating by %(user)s") % {'score': self.score, 'user': self.user}
|
||||
|
||||
|
||||
class UserFlagManager(models.Manager):
|
||||
def flag(self, comment, user):
|
||||
"""
|
||||
|
@ -265,11 +278,13 @@ class UserFlagManager(models.Manager):
|
|||
mail_managers('Comment flagged', message, fail_silently=True)
|
||||
f.save()
|
||||
|
||||
|
||||
class UserFlag(models.Model):
|
||||
user = models.ForeignKey(User)
|
||||
comment = models.ForeignKey(Comment)
|
||||
flag_date = models.DateTimeField(_('flag date'), auto_now_add=True)
|
||||
objects = UserFlagManager()
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('user flag')
|
||||
verbose_name_plural = _('user flags')
|
||||
|
@ -278,10 +293,12 @@ class UserFlag(models.Model):
|
|||
def __unicode__(self):
|
||||
return _("Flag by %r") % self.user
|
||||
|
||||
|
||||
class ModeratorDeletion(models.Model):
|
||||
user = models.ForeignKey(User, verbose_name='moderator')
|
||||
comment = models.ForeignKey(Comment)
|
||||
deletion_date = models.DateTimeField(_('deletion date'), auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('moderator deletion')
|
||||
verbose_name_plural = _('moderator deletions')
|
||||
|
|
Loading…
Reference in New Issue