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 # We try to import the moderation module and if the import is successful we make the filtration
17 moderation_import = 'from %s.moderation.startup import CurrentUserHolder' % MODULES_PACKAGE
18 exec moderation_import
20 moderation_enabled= True
22 moderation_enabled = False
24 # If the moderation module has been enabled we make the filtration
25 if CurrentUserHolder is not None and moderation_enabled:
26 user = CurrentUserHolder.user
29 filter_content = not user.is_staff and not user.is_superuser
34 moderation_import = 'from %s.moderation.hooks import get_tag_ids' % MODULES_PACKAGE
35 exec moderation_import
36 qs = qs.exclude(id__in=get_tag_ids('deleted')).exclude(id__in=get_tag_ids('rejected')).exclude(
37 id__in=get_tag_ids('in_moderation')
43 name = models.CharField(max_length=255, unique=True)
44 created_by = models.ForeignKey(User, related_name='created_tags')
45 created_at = models.DateTimeField(default=datetime.datetime.now, blank=True, null=True)
46 marked_by = models.ManyToManyField(User, related_name="marked_tags", through="MarkedTag")
48 used_count = models.PositiveIntegerField(default=0)
50 active = ActiveTagManager()
51 objects = ActiveTagManager()
54 ordering = ('-used_count', 'name')
57 def __unicode__(self):
58 return u'%s' % self.name
60 def add_to_usage_count(self, value):
61 if self.used_count + value < 0:
64 self.used_count = models.F('used_count') + value
67 def get_absolute_url(self):
68 return ('tag_questions', (), {'tag': self.name})
70 class MarkedTag(models.Model):
71 TAG_MARK_REASONS = (('good', _('interesting')), ('bad', _('ignored')))
72 tag = models.ForeignKey(Tag, related_name='user_selections')
73 user = models.ForeignKey(User, related_name='tag_selections')
74 reason = models.CharField(max_length=16, choices=TAG_MARK_REASONS)