Show More
@@ -60,7 +60,7 b' class PostManager(models.Manager):' | |||
|
60 | 60 | threads = self.filter(parent=NO_PARENT, tags=tag) |
|
61 | 61 | else: |
|
62 | 62 | threads = self.filter(parent=NO_PARENT) |
|
63 |
threads = |
|
|
63 | threads = threads.order_by('-last_edit_time') | |
|
64 | 64 | |
|
65 | 65 | if page != self.ALL_PAGES: |
|
66 | 66 | thread_count = len(threads) |
@@ -87,7 +87,7 b' class PostManager(models.Manager):' | |||
|
87 | 87 | def exists(self, post_id): |
|
88 | 88 | posts = self.filter(id=post_id) |
|
89 | 89 | |
|
90 |
return |
|
|
90 | return posts.count() > 0 | |
|
91 | 91 | |
|
92 | 92 | def get_thread_page_count(self, tag=None): |
|
93 | 93 | if tag: |
@@ -95,7 +95,8 b' class PostManager(models.Manager):' | |||
|
95 | 95 | else: |
|
96 | 96 | threads = self.filter(parent=NO_PARENT) |
|
97 | 97 | |
|
98 |
return int(math.ceil( |
|
|
98 | return int(math.ceil(threads.count() / float( | |
|
99 | settings.THREADS_PER_PAGE))) | |
|
99 | 100 | |
|
100 | 101 | def _delete_old_threads(self): |
|
101 | 102 | """ |
@@ -103,8 +104,6 b' class PostManager(models.Manager):' | |||
|
103 | 104 | delete the old ones. |
|
104 | 105 | """ |
|
105 | 106 | |
|
106 | # TODO Try to find a better way to get the active thread count. | |
|
107 | ||
|
108 | 107 | # TODO Move old threads to the archive instead of deleting them. |
|
109 | 108 | # Maybe make some 'old' field in the model to indicate the thread |
|
110 | 109 | # must not be shown and be able for replying. |
@@ -114,7 +113,7 b' class PostManager(models.Manager):' | |||
|
114 | 113 | |
|
115 | 114 | if thread_count > settings.MAX_THREAD_COUNT: |
|
116 | 115 | num_threads_to_delete = thread_count - settings.MAX_THREAD_COUNT |
|
117 | old_threads = threads[-num_threads_to_delete:] | |
|
116 | old_threads = threads[thread_count - num_threads_to_delete:] | |
|
118 | 117 | |
|
119 | 118 | for thread in old_threads: |
|
120 | 119 | self.delete_post(thread) |
@@ -152,6 +151,8 b' class Tag(models.Model):' | |||
|
152 | 151 | section. There can be multiple tags for each message |
|
153 | 152 | """ |
|
154 | 153 | |
|
154 | OPENING_POST_WEIGHT = 5 | |
|
155 | ||
|
155 | 156 | objects = TagManager() |
|
156 | 157 | |
|
157 | 158 | name = models.CharField(max_length=100) |
@@ -166,13 +167,14 b' class Tag(models.Model):' | |||
|
166 | 167 | |
|
167 | 168 | def get_post_count(self): |
|
168 | 169 | posts_with_tag = Post.objects.get_threads(tag=self) |
|
169 |
return |
|
|
170 | return posts_with_tag.count() | |
|
170 | 171 | |
|
171 | 172 | def get_popularity(self): |
|
172 | 173 | posts_with_tag = Post.objects.get_threads(tag=self) |
|
173 | 174 | reply_count = 0 |
|
174 | 175 | for post in posts_with_tag: |
|
175 | 176 | reply_count += post.get_reply_count() |
|
177 | reply_count += self.OPENING_POST_WEIGHT | |
|
176 | 178 | |
|
177 | 179 | return reply_count |
|
178 | 180 | |
@@ -217,7 +219,7 b' class Post(models.Model):' | |||
|
217 | 219 | return Post.objects.filter(parent=self.id) |
|
218 | 220 | |
|
219 | 221 | def get_reply_count(self): |
|
220 |
return |
|
|
222 | return self._get_replies().count() | |
|
221 | 223 | |
|
222 | 224 | def get_images_count(self): |
|
223 | 225 | images_count = 1 if self.image else 0 |
General Comments 0
You need to be logged in to leave comments.
Login now