Show More
@@ -6,7 +6,10 b' from django.db.models import Count' | |||||
6 |
|
6 | |||
7 | TAG_FONT_MULTIPLIER = 0.1 |
|
7 | TAG_FONT_MULTIPLIER = 0.1 | |
8 | MAX_TAG_FONT = 10 |
|
8 | MAX_TAG_FONT = 10 | |
9 | OPENING_POST_POPULARITY_WEIGHT = 2 |
|
9 | ||
|
10 | OPENING_POST_POPULARITY = 0.5 | |||
|
11 | ARCHIVE_POPULARITY = 0.01 | |||
|
12 | REPLY_POPULARITY = 0.1 | |||
10 |
|
13 | |||
11 |
|
14 | |||
12 | class TagManager(models.Manager): |
|
15 | class TagManager(models.Manager): | |
@@ -43,15 +46,19 b' class Tag(models.Model):' | |||||
43 | def get_post_count(self): |
|
46 | def get_post_count(self): | |
44 | return self.threads.count() |
|
47 | return self.threads.count() | |
45 |
|
48 | |||
46 | # TODO Reenable this method after migration |
|
49 | def get_popularity(self): | |
47 | # def get_popularity(self): |
|
50 | popularity = 0.0 | |
48 | # posts_with_tag = Thread.objects.get_threads(tag=self) |
|
51 | ||
49 | # reply_count = 0 |
|
52 | for thread in self.threads.all(): | |
50 | # for post in posts_with_tag: |
|
53 | reply_count = thread.get_reply_count() | |
51 | # reply_count += post.get_reply_count() |
|
54 | ||
52 | # reply_count += OPENING_POST_POPULARITY_WEIGHT |
|
55 | if thread.archived: | |
53 | # |
|
56 | popularity += ARCHIVE_POPULARITY * reply_count | |
54 | # return reply_count |
|
57 | else: | |
|
58 | popularity += REPLY_POPULARITY * reply_count | |||
|
59 | popularity += OPENING_POST_POPULARITY | |||
|
60 | ||||
|
61 | return popularity | |||
55 |
|
62 | |||
56 | def get_linked_tags(self): |
|
63 | def get_linked_tags(self): | |
57 | tag_list = [] |
|
64 | tag_list = [] | |
@@ -75,10 +82,10 b' class Tag(models.Model):' | |||||
75 | def get_font_value(self): |
|
82 | def get_font_value(self): | |
76 | """Get tag font value to differ most popular tags in the list""" |
|
83 | """Get tag font value to differ most popular tags in the list""" | |
77 |
|
84 | |||
78 |
po |
|
85 | popularity = self.get_popularity() | |
79 |
if po |
|
86 | if popularity > MAX_TAG_FONT: | |
80 |
po |
|
87 | popularity = MAX_TAG_FONT | |
81 |
|
88 | |||
82 |
font_value = str(1 + (po |
|
89 | font_value = str(1 + (popularity - 1) * TAG_FONT_MULTIPLIER) | |
83 |
|
90 | |||
84 | return font_value No newline at end of file |
|
91 | return font_value |
@@ -84,6 +84,10 b' def index(request, page=DEFAULT_PAGE):' | |||||
84 |
|
84 | |||
85 |
|
85 | |||
86 | def archive(request, page=DEFAULT_PAGE): |
|
86 | def archive(request, page=DEFAULT_PAGE): | |
|
87 | """ | |||
|
88 | Get archived posts | |||
|
89 | """ | |||
|
90 | ||||
87 | context = _init_default_context(request) |
|
91 | context = _init_default_context(request) | |
88 |
|
92 | |||
89 | threads = [] |
|
93 | threads = [] |
General Comments 0
You need to be logged in to leave comments.
Login now