4 from forum.modules import MODULES_PACKAGE
6 from django.utils.translation import ugettext as _
9 class ActiveTagManager(models.Manager):
10 def get_query_set(self):
11 qs = super(ActiveTagManager, self).get_query_set().exclude(used_count__lt=1)
13 CurrentUserHolder = None
15 moderation_import = 'from %s.moderation.startup import CurrentUserHolder' % MODULES_PACKAGE
16 exec moderation_import
18 if CurrentUserHolder is not None:
19 user = CurrentUserHolder.user
22 filter_content = not user.is_staff and not user.is_superuser
27 moderation_import = 'from %s.moderation.hooks import get_tag_ids' % MODULES_PACKAGE
28 exec moderation_import
29 qs = qs.exclude(id__in=get_tag_ids('deleted')).exclude(id__in=get_tag_ids('rejected')).exclude(
30 id__in=get_tag_ids('in_moderation')
36 name = models.CharField(max_length=255, unique=True)
37 created_by = models.ForeignKey(User, related_name='created_tags')
38 created_at = models.DateTimeField(default=datetime.datetime.now, blank=True, null=True)
39 marked_by = models.ManyToManyField(User, related_name="marked_tags", through="MarkedTag")
41 used_count = models.PositiveIntegerField(default=0)
43 active = ActiveTagManager()
44 objects = ActiveTagManager()
47 ordering = ('-used_count', 'name')
50 def __unicode__(self):
51 return u'%s' % self.name
53 def add_to_usage_count(self, value):
54 if self.used_count + value < 0:
57 self.used_count = models.F('used_count') + value
60 def get_absolute_url(self):
61 return ('tag_questions', (), {'tag': self.name})
63 class MarkedTag(models.Model):
64 TAG_MARK_REASONS = (('good', _('interesting')), ('bad', _('ignored')))
65 tag = models.ForeignKey(Tag, related_name='user_selections')
66 user = models.ForeignKey(User, related_name='tag_selections')
67 reason = models.CharField(max_length=16, choices=TAG_MARK_REASONS)