##// END OF EJS Templates
Fixed tag ordering that was broken with latest change
neko259 -
r929:1ad4b54e default
parent child Browse files
Show More
@@ -1,70 +1,71 b''
1 1 from django.template.loader import render_to_string
2 2 from django.db import models
3 3 from django.db.models import Count
4 4 from django.core.urlresolvers import reverse
5 5
6 6 from boards.models.base import Viewable
7 7
8 8
9 9 __author__ = 'neko259'
10 10
11 11
12 12 class TagManager(models.Manager):
13 13
14 14 def get_not_empty_tags(self):
15 15 """
16 16 Gets tags that have non-archived threads.
17 17 """
18 18
19 19 return self.filter(thread__archived=False)\
20 .annotate(num_threads=Count('thread')).filter(num_threads__gt=0)
20 .annotate(num_threads=Count('thread')).filter(num_threads__gt=0)\
21 .order_by('-required')
21 22
22 23
23 24 class Tag(models.Model, Viewable):
24 25 """
25 26 A tag is a text node assigned to the thread. The tag serves as a board
26 27 section. There can be multiple tags for each thread
27 28 """
28 29
29 30 objects = TagManager()
30 31
31 32 class Meta:
32 33 app_label = 'boards'
33 34 ordering = ('name',)
34 35
35 36 name = models.CharField(max_length=100, db_index=True)
36 37 required = models.BooleanField(default=False)
37 38
38 39 def __str__(self):
39 40 return self.name
40 41
41 42 def is_empty(self) -> bool:
42 43 """
43 44 Checks if the tag has some threads.
44 45 """
45 46
46 47 return self.get_thread_count() == 0
47 48
48 49 def get_thread_count(self) -> int:
49 50 return self.get_threads().count()
50 51
51 52 def get_url(self):
52 53 return reverse('tag', kwargs={'tag_name': self.name})
53 54
54 55 def get_threads(self):
55 56 return self.thread_set.order_by('-bump_time')
56 57
57 58 def is_required(self):
58 59 return self.required
59 60
60 61 def get_view(self):
61 62 link = '<a class="tag" href="{}">{}</a>'.format(
62 63 self.get_url(), self.name)
63 64 if self.is_required():
64 65 link = '<b>{}</b>'.format(link)
65 66 return link
66 67
67 68 def get_search_view(self, *args, **kwargs):
68 69 return render_to_string('boards/tag.html', {
69 70 'tag': self,
70 71 })
General Comments 0
You need to be logged in to leave comments. Login now