1 from django.utils.translation import ugettext as _
\r
4 class Vote(models.Model):
\r
5 user = models.ForeignKey(User, related_name="votes")
\r
6 node = models.ForeignKey(Node, related_name="votes")
\r
7 value = models.SmallIntegerField()
\r
8 action = models.ForeignKey(Action, unique=True, related_name="vote")
\r
9 voted_at = models.DateTimeField(default=datetime.datetime.now)
\r
13 unique_together = ('user', 'node')
\r
16 class Flag(models.Model):
\r
17 user = models.ForeignKey(User, related_name="flags")
\r
18 node = models.ForeignKey(Node, related_name="flags")
\r
19 reason = models.CharField(max_length=300)
\r
20 action = models.ForeignKey(Action, unique=True, related_name="flag")
\r
21 flagged_at = models.DateTimeField(default=datetime.datetime.now)
\r
25 unique_together = ('user', 'node')
\r
27 class BadgeManager(models.Manager):
\r
28 use_for_related_fields = True
\r
30 def get(self, *args, **kwargs):
\r
32 pk = [v for (k,v) in kwargs.items() if k in ('pk', 'pk__exact', 'id', 'id__exact')][0]
\r
34 return super(BadgeManager, self).get(*args, **kwargs)
\r
36 from forum.badges.base import BadgesMeta
\r
37 badge = BadgesMeta.by_id.get(int(pk), None)
\r
39 return super(BadgeManager, self).get(*args, **kwargs)
\r
42 class Badge(models.Model):
\r
47 type = models.SmallIntegerField()
\r
48 cls = models.CharField(max_length=50, null=True)
\r
49 awarded_count = models.PositiveIntegerField(default=0)
\r
51 awarded_to = models.ManyToManyField(User, through='Award', related_name='badges')
\r
53 objects = BadgeManager()
\r
57 cls = self.__dict__.get('_class', None)
\r
58 return cls and cls.name or _("Unknown")
\r
61 def description(self):
\r
62 cls = self.__dict__.get('_class', None)
\r
63 return cls and cls.description or _("No description available")
\r
66 def get_absolute_url(self):
\r
67 return ('badge', [], {'id': self.id, 'slug': slugify(self.name)})
\r
73 class Award(models.Model):
\r
74 user = models.ForeignKey(User)
\r
75 badge = models.ForeignKey('Badge', related_name="awards")
\r
76 node = models.ForeignKey(Node, null=True)
\r
78 awarded_at = models.DateTimeField(default=datetime.datetime.now)
\r
80 trigger = models.ForeignKey(Action, related_name="awards", null=True)
\r
81 action = models.ForeignKey(Action, related_name="award", unique=True)
\r
85 unique_together = ('user', 'badge', 'node')
\r