##// END OF EJS Templates
Removed old maintenance module, that was used prior to data migrations. Cleaned up requirements. Minor fix in the tag model
neko259 -
r731:f96ca2ca 2.0-dev
parent child Browse files
Show More
@@ -1,100 +1,102 b''
1 from django.template.loader import render_to_string
1 from django.template.loader import render_to_string
2 from boards.models import Thread, Post
2 from boards.models import Thread, Post
3 from django.db import models
3 from django.db import models
4 from django.db.models import Count, Sum
4 from django.db.models import Count, Sum
5 from django.core.urlresolvers import reverse
5 from django.core.urlresolvers import reverse
6 from boards.models.base import Viewable
6 from boards.models.base import Viewable
7
7
8 __author__ = 'neko259'
8 __author__ = 'neko259'
9
9
10
10
11 class TagManager(models.Manager):
11 class TagManager(models.Manager):
12
12
13 def get_not_empty_tags(self):
13 def get_not_empty_tags(self):
14 """
14 """
15 Gets tags that have non-archived threads.
15 Gets tags that have non-archived threads.
16 """
16 """
17
17
18 tags = self.annotate(Count('threads')) \
18 tags = self.annotate(Count('threads')) \
19 .filter(threads__count__gt=0).order_by('name')
19 .filter(threads__count__gt=0).order_by('name')
20
20
21 return tags
21 return tags
22
22
23
23
24 class Tag(models.Model, Viewable):
24 class Tag(models.Model, Viewable):
25 """
25 """
26 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
27 section. There can be multiple tags for each thread
27 section. There can be multiple tags for each thread
28 """
28 """
29
29
30 objects = TagManager()
30 objects = TagManager()
31
31
32 class Meta:
32 class Meta:
33 app_label = 'boards'
33 app_label = 'boards'
34 ordering = ('name',)
34 ordering = ('name',)
35
35
36 name = models.CharField(max_length=100, db_index=True)
36 name = models.CharField(max_length=100, db_index=True)
37 threads = models.ManyToManyField(Thread, null=True,
37 threads = models.ManyToManyField(Thread, null=True,
38 blank=True, related_name='tag+')
38 blank=True, related_name='tag+')
39 linked = models.ForeignKey('Tag', null=True, blank=True)
39 linked = models.ForeignKey('Tag', null=True, blank=True)
40
40
41 def __unicode__(self):
41 def __unicode__(self):
42 return self.name
42 return self.name
43
43
44 def is_empty(self):
44 def is_empty(self):
45 """
45 """
46 Checks if the tag has some threads.
46 Checks if the tag has some threads.
47 """
47 """
48
48
49 return self.get_thread_count() == 0
49 return self.get_thread_count() == 0
50
50
51 def get_thread_count(self):
51 def get_thread_count(self):
52 return self.threads.count()
52 return self.threads.count()
53
53
54 def get_linked_tags(self):
54 def get_linked_tags(self):
55 """
55 """
56 Gets tags linked to the current one.
56 Gets tags linked to the current one.
57 """
57 """
58
58
59 tag_list = []
59 tag_list = []
60 self.get_linked_tags_list(tag_list)
60 self.get_linked_tags_list(tag_list)
61
61
62 return tag_list
62 return tag_list
63
63
64 def get_linked_tags_list(self, tag_list=[]):
64 def get_linked_tags_list(self, tag_list=None):
65 """
65 """
66 Returns the list of tags linked to current. The list can be got
66 Returns the list of tags linked to current. The list can be got
67 through returned value or tag_list parameter
67 through returned value or tag_list parameter
68 """
68 """
69 if not tag_list:
70 tag_list = []
69
71
70 linked_tag = self.linked
72 linked_tag = self.linked
71
73
72 if linked_tag and not (linked_tag in tag_list):
74 if linked_tag and not (linked_tag in tag_list):
73 tag_list.append(linked_tag)
75 tag_list.append(linked_tag)
74
76
75 linked_tag.get_linked_tags_list(tag_list)
77 linked_tag.get_linked_tags_list(tag_list)
76
78
77 def get_post_count(self, archived=False):
79 def get_post_count(self, archived=False):
78 """
80 """
79 Gets posts count for the tag's threads.
81 Gets posts count for the tag's threads.
80 """
82 """
81
83
82 posts_count = 0
84 posts_count = 0
83
85
84 threads = self.threads.filter(archived=archived)
86 threads = self.threads.filter(archived=archived)
85 if threads.exists():
87 if threads.exists():
86 posts_count = threads.annotate(posts_count=Count('replies')) \
88 posts_count = threads.annotate(posts_count=Count('replies')) \
87 .aggregate(posts_sum=Sum('posts_count'))['posts_sum']
89 .aggregate(posts_sum=Sum('posts_count'))['posts_sum']
88
90
89 if not posts_count:
91 if not posts_count:
90 posts_count = 0
92 posts_count = 0
91
93
92 return posts_count
94 return posts_count
93
95
94 def get_url(self):
96 def get_url(self):
95 return reverse('tag', kwargs={'tag_name': self.name})
97 return reverse('tag', kwargs={'tag_name': self.name})
96
98
97 def get_view(self, *args, **kwargs):
99 def get_view(self, *args, **kwargs):
98 return render_to_string('boards/tag.html', {
100 return render_to_string('boards/tag.html', {
99 'tag': self,
101 'tag': self,
100 })
102 })
@@ -1,10 +1,10 b''
1 south
1 line_profiler
2 line_profiler
2 haystack
3 haystack
3 pillow
4 pillow
4 django>=1.6
5 django>=1.6
5 django_cleanup
6 django_cleanup
6 django-markupfield
7 django-markupfield
7 markdown
8 markdown
8 python-markdown
9 django-simple-captcha
9 django-simple-captcha
10 line-profiler
10 line-profiler
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now