Style fixes.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7038 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Gary Wilson Jr 2008-01-28 05:27:39 +00:00
parent ff707f502c
commit 332e68d550
1 changed files with 22 additions and 5 deletions

View File

@ -1,25 +1,27 @@
import datetime
from django.db import models from django.db import models
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.conf import settings from django.conf import settings
import datetime
MIN_PHOTO_DIMENSION = 5 MIN_PHOTO_DIMENSION = 5
MAX_PHOTO_DIMENSION = 1000 MAX_PHOTO_DIMENSION = 1000
# option codes for comment-form hidden fields # Option codes for comment-form hidden fields.
PHOTOS_REQUIRED = 'pr' PHOTOS_REQUIRED = 'pr'
PHOTOS_OPTIONAL = 'pa' PHOTOS_OPTIONAL = 'pa'
RATINGS_REQUIRED = 'rr' RATINGS_REQUIRED = 'rr'
RATINGS_OPTIONAL = 'ra' RATINGS_OPTIONAL = 'ra'
IS_PUBLIC = 'ip' 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 DEFAULT_KARMA = 5
KARMA_NEEDED_BEFORE_DISPLAYED = 3 KARMA_NEEDED_BEFORE_DISPLAYED = 3
class CommentManager(models.Manager): class CommentManager(models.Manager):
def get_security_hash(self, options, photo_options, rating_options, target): def get_security_hash(self, options, photo_options, rating_options, target):
""" """
@ -61,7 +63,9 @@ class CommentManager(models.Manager):
return True return True
return False return False
class Comment(models.Model): class Comment(models.Model):
"""A comment by a registered user."""
user = models.ForeignKey(User, raw_id_admin=True) user = models.ForeignKey(User, raw_id_admin=True)
content_type = models.ForeignKey(ContentType) content_type = models.ForeignKey(ContentType)
object_id = models.IntegerField(_('object ID')) 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.')) 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) site = models.ForeignKey(Site)
objects = CommentManager() objects = CommentManager()
class Meta: class Meta:
verbose_name = _('comment') verbose_name = _('comment')
verbose_name_plural = _('comments') verbose_name_plural = _('comments')
ordering = ('-submit_date',) ordering = ('-submit_date',)
class Admin: class Admin:
fields = ( fields = (
(None, {'fields': ('content_type', 'object_id', 'site')}), (None, {'fields': ('content_type', 'object_id', 'site')}),
@ -134,7 +140,7 @@ class Comment(models.Model):
get_content_object.short_description = _('Content object') get_content_object.short_description = _('Content object')
def _fill_karma_cache(self): 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 good, bad = 0, 0
for k in self.karmascore_set: for k in self.karmascore_set:
if k.score == -1: if k.score == -1:
@ -163,8 +169,9 @@ class Comment(models.Model):
{'user': self.user.username, 'date': self.submit_date, {'user': self.user.username, 'date': self.submit_date,
'comment': self.comment, 'domain': self.site.domain, 'url': self.get_absolute_url()} 'comment': self.comment, 'domain': self.site.domain, 'url': self.get_absolute_url()}
class FreeComment(models.Model): 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) content_type = models.ForeignKey(ContentType)
object_id = models.IntegerField(_('object ID')) object_id = models.IntegerField(_('object ID'))
comment = models.TextField(_('comment'), max_length=3000) comment = models.TextField(_('comment'), max_length=3000)
@ -175,10 +182,12 @@ class FreeComment(models.Model):
# TODO: Change this to is_removed, like Comment # TODO: Change this to is_removed, like Comment
approved = models.BooleanField(_('approved by staff')) approved = models.BooleanField(_('approved by staff'))
site = models.ForeignKey(Site) site = models.ForeignKey(Site)
class Meta: class Meta:
verbose_name = _('free comment') verbose_name = _('free comment')
verbose_name_plural = _('free comments') verbose_name_plural = _('free comments')
ordering = ('-submit_date',) ordering = ('-submit_date',)
class Admin: class Admin:
fields = ( fields = (
(None, {'fields': ('content_type', 'object_id', 'site')}), (None, {'fields': ('content_type', 'object_id', 'site')}),
@ -212,6 +221,7 @@ class FreeComment(models.Model):
get_content_object.short_description = _('Content object') get_content_object.short_description = _('Content object')
class KarmaScoreManager(models.Manager): class KarmaScoreManager(models.Manager):
def vote(self, user_id, comment_id, score): def vote(self, user_id, comment_id, score):
try: try:
@ -233,12 +243,14 @@ class KarmaScoreManager(models.Manager):
return DEFAULT_KARMA return DEFAULT_KARMA
return int(round((4.5 * score) + 5.5)) return int(round((4.5 * score) + 5.5))
class KarmaScore(models.Model): class KarmaScore(models.Model):
user = models.ForeignKey(User) user = models.ForeignKey(User)
comment = models.ForeignKey(Comment) comment = models.ForeignKey(Comment)
score = models.SmallIntegerField(_('score'), db_index=True) score = models.SmallIntegerField(_('score'), db_index=True)
scored_date = models.DateTimeField(_('score date'), auto_now=True) scored_date = models.DateTimeField(_('score date'), auto_now=True)
objects = KarmaScoreManager() objects = KarmaScoreManager()
class Meta: class Meta:
verbose_name = _('karma score') verbose_name = _('karma score')
verbose_name_plural = _('karma scores') verbose_name_plural = _('karma scores')
@ -247,6 +259,7 @@ class KarmaScore(models.Model):
def __unicode__(self): def __unicode__(self):
return _("%(score)d rating by %(user)s") % {'score': self.score, 'user': self.user} return _("%(score)d rating by %(user)s") % {'score': self.score, 'user': self.user}
class UserFlagManager(models.Manager): class UserFlagManager(models.Manager):
def flag(self, comment, user): def flag(self, comment, user):
""" """
@ -265,11 +278,13 @@ class UserFlagManager(models.Manager):
mail_managers('Comment flagged', message, fail_silently=True) mail_managers('Comment flagged', message, fail_silently=True)
f.save() f.save()
class UserFlag(models.Model): class UserFlag(models.Model):
user = models.ForeignKey(User) user = models.ForeignKey(User)
comment = models.ForeignKey(Comment) comment = models.ForeignKey(Comment)
flag_date = models.DateTimeField(_('flag date'), auto_now_add=True) flag_date = models.DateTimeField(_('flag date'), auto_now_add=True)
objects = UserFlagManager() objects = UserFlagManager()
class Meta: class Meta:
verbose_name = _('user flag') verbose_name = _('user flag')
verbose_name_plural = _('user flags') verbose_name_plural = _('user flags')
@ -278,10 +293,12 @@ class UserFlag(models.Model):
def __unicode__(self): def __unicode__(self):
return _("Flag by %r") % self.user return _("Flag by %r") % self.user
class ModeratorDeletion(models.Model): class ModeratorDeletion(models.Model):
user = models.ForeignKey(User, verbose_name='moderator') user = models.ForeignKey(User, verbose_name='moderator')
comment = models.ForeignKey(Comment) comment = models.ForeignKey(Comment)
deletion_date = models.DateTimeField(_('deletion date'), auto_now_add=True) deletion_date = models.DateTimeField(_('deletion date'), auto_now_add=True)
class Meta: class Meta:
verbose_name = _('moderator deletion') verbose_name = _('moderator deletion')
verbose_name_plural = _('moderator deletions') verbose_name_plural = _('moderator deletions')