X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/4496d7188a21ea6706e3b8a9ca5742c64767c134..133a8f939cdfa69dd6a7caeafed158aa38d20092:/forum/models/meta.py?ds=sidebyside diff --git a/forum/models/meta.py b/forum/models/meta.py index 7e82137..c01c018 100644 --- a/forum/models/meta.py +++ b/forum/models/meta.py @@ -1,7 +1,6 @@ from base import * -import re -class Vote(MetaContent, UserContent): +class Vote(MetaContent, CancelableContent, UserContent): VOTE_UP = +1 VOTE_DOWN = -1 VOTE_CHOICES = ( @@ -11,7 +10,6 @@ class Vote(MetaContent, UserContent): vote = models.SmallIntegerField(choices=VOTE_CHOICES) voted_at = models.DateTimeField(default=datetime.datetime.now) - canceled = models.BooleanField(default=False) active = ActiveObjectManager() @@ -27,28 +25,23 @@ class Vote(MetaContent, UserContent): post.__dict__[field] = post.__dict__[field] + diff post.save() + def cancel(self): + if super(Vote, self).cancel(): + self._update_post_vote_count(-1) + def save(self, *args, **kwargs): super(Vote, self).save(*args, **kwargs) if self._is_new: self._update_post_vote_count(1) - def cancel(self): - if not self.canceled: - self.canceled = True - self.save() - self._update_post_vote_count(-1) - vote_canceled.send(sender=Vote, instance=self) - def is_upvote(self): return self.vote == self.VOTE_UP def is_downvote(self): return self.vote == self.VOTE_DOWN -vote_canceled = django.dispatch.Signal(providing_args=['instance']) class FlaggedItem(MetaContent, UserContent): - """A flag on a Question or Answer indicating offensive content.""" flagged_at = models.DateTimeField(default=datetime.datetime.now) reason = models.CharField(max_length=300, null=True) canceled = models.BooleanField(default=False) @@ -78,75 +71,5 @@ class FlaggedItem(MetaContent, UserContent): self._update_post_flag_count(-1) -class Comment(MetaContent, UserContent, DeletableContent): - comment = models.CharField(max_length=300) - added_at = models.DateTimeField(default=datetime.datetime.now) - score = models.IntegerField(default=0) - liked_by = models.ManyToManyField(User, through='LikedComment', related_name='comments_liked') - - class Meta(MetaContent.Meta): - ordering = ('-added_at',) - db_table = u'comment' - - def _update_post_comment_count(self, diff): - post = self.node.leaf - post.comment_count = post.comment_count + diff - post.save() - - def save(self, *args, **kwargs): - super(Comment,self).save(*args, **kwargs) - - if self._is_new: - self._update_post_comment_count(1) - - try: - ping_google() - except Exception: - logging.debug('problem pinging google did you register you sitemap with google?') - - def mark_deleted(self, user): - if super(Comment, self).mark_deleted(user): - self._update_post_comment_count(-1) - - def unmark_deleted(self): - if super(Comment, self).unmark_deleted(): - self._update_post_comment_count(1) - - def is_reply_to(self, user): - inreply = re.search('@\w+', self.comment) - if inreply is not None: - return user.username.startswith(inreply.group(0)) - - return False - - def __unicode__(self): - return self.comment - - -class LikedComment(models.Model): - comment = models.ForeignKey(Comment) - user = models.ForeignKey(User) - added_at = models.DateTimeField(default=datetime.datetime.now) - canceled = models.BooleanField(default=False) - - active = ActiveObjectManager() - - class Meta: - app_label = 'forum' - - def _update_comment_score(self, diff): - self.comment.score = self.comment.score + diff - self.comment.save() - - def save(self, *args, **kwargs): - super(LikedComment, self).save(*args, **kwargs) - if self._is_new: - self._update_comment_score(1) - - def cancel(self): - if not self.canceled: - self.canceled = True - self.save() - self._update_comment_score(-1)