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