3 class Vote(MetaContent, CancelableContent, UserContent):
11 vote = models.SmallIntegerField(choices=VOTE_CHOICES)
12 voted_at = models.DateTimeField(default=datetime.datetime.now)
14 active = ActiveObjectManager()
16 class Meta(MetaContent.Meta):
19 def __unicode__(self):
20 return '[%s] voted at %s: %s' %(self.user, self.voted_at, self.vote)
22 def _update_post_vote_count(self, diff):
24 field = self.vote == 1 and 'vote_up_count' or 'vote_down_count'
25 post.__dict__[field] = post.__dict__[field] + diff
29 if super(Vote, self).cancel():
30 self._update_post_vote_count(-1)
32 def save(self, *args, **kwargs):
33 super(Vote, self).save(*args, **kwargs)
35 self._update_post_vote_count(1)
38 return self.vote == self.VOTE_UP
40 def is_downvote(self):
41 return self.vote == self.VOTE_DOWN
44 class FlaggedItem(MetaContent, UserContent):
45 flagged_at = models.DateTimeField(default=datetime.datetime.now)
46 reason = models.CharField(max_length=300, null=True)
47 canceled = models.BooleanField(default=False)
49 active = ActiveObjectManager()
51 class Meta(MetaContent.Meta):
52 db_table = u'flagged_item'
54 def __unicode__(self):
55 return '[%s] flagged at %s' %(self.user, self.flagged_at)
57 def _update_post_flag_count(self, diff):
59 post.offensive_flag_count = post.offensive_flag_count + diff
62 def save(self, *args, **kwargs):
63 super(FlaggedItem, self).save(*args, **kwargs)
65 self._update_post_flag_count(1)
71 self._update_post_flag_count(-1)