##// END OF EJS Templates
Removed old and unused code. Added TODOs for future refactoring and optimization.
neko259 -
r176:27756a1b default
parent child Browse files
Show More
@@ -45,13 +45,11 b' class PostManager(models.Manager):'
45 45 last_edit_time=timezone.now(),
46 46 user=user)
47 47
48 if thread:
49 thread.replies.add(post)
50
51 48 if tags:
52 49 map(post.tags.add, tags)
53 50
54 51 if thread:
52 thread.replies.add(post)
55 53 thread.bump()
56 54 else:
57 55 self._delete_old_threads()
@@ -138,32 +136,20 b' class PostManager(models.Manager):'
138 136
139 137 map(self.delete_post, old_threads)
140 138
141 def _bump_thread(self, thread_id):
142 thread = self.get(id=thread_id)
143
144 if thread.can_bump():
145 thread.last_edit_time = timezone.now()
146 thread.save()
147
148 139
149 140 class TagManager(models.Manager):
141
150 142 def get_not_empty_tags(self):
151 143 all_tags = self.all().order_by('name')
152 144 tags = []
145
146 # TODO Use query here
153 147 for tag in all_tags:
154 148 if not tag.is_empty():
155 149 tags.append(tag)
156 150
157 151 return tags
158 152
159 def get_popular_tags(self):
160 all_tags = self.get_not_empty_tags()
161
162 sorted_tags = sorted(all_tags, key=lambda tag: tag.get_popularity(),
163 reverse=True)
164
165 return sorted_tags[:settings.POPULAR_TAGS]
166
167 153
168 154 class Tag(models.Model):
169 155 """
@@ -182,11 +168,11 b' class Tag(models.Model):'
182 168 return self.get_post_count() == 0
183 169
184 170 def get_post_count(self):
185 posts_with_tag = Post.objects.get_threads(tag=self)
171 posts_with_tag = Post.objects.filter(tag=self)
186 172 return posts_with_tag.count()
187 173
188 174 def get_popularity(self):
189 posts_with_tag = Post.objects.get_threads(tag=self)
175 posts_with_tag = Post.objects.filter(tag=self)
190 176 reply_count = 0
191 177 for post in posts_with_tag:
192 178 reply_count += post.get_reply_count()
@@ -227,7 +213,7 b' class Post(models.Model):'
227 213 poster_ip = models.GenericIPAddressField()
228 214 poster_user_agent = models.TextField()
229 215
230 # TODO Convert this field to ForeignKey
216 # TODO Remove this field after everything has been updated to 'thread'
231 217 parent = models.BigIntegerField(default=NO_PARENT)
232 218
233 219 thread = models.ForeignKey('Post', null=True, default=None)
@@ -249,15 +235,13 b' class Post(models.Model):'
249 235
250 236 return title
251 237
252 def _get_replies(self):
253 return self.replies
254
255 238 def get_reply_count(self):
256 239 return self.replies.count()
257 240
258 241 def get_images_count(self):
259 242 images_count = 1 if self.image else 0
260 243
244 # TODO Use query here
261 245 for reply in self.replies:
262 246 if reply.image:
263 247 images_count += 1
@@ -272,6 +256,8 b' class Post(models.Model):'
272 256 return post_count <= settings.MAX_POSTS_PER_THREAD
273 257
274 258 def bump(self):
259 """Bump (move to up) thread"""
260
275 261 if self.can_bump():
276 262 self.last_edit_time = timezone.now()
277 263 self.save()
@@ -335,6 +321,7 b' class Setting(models.Model):'
335 321
336 322
337 323 class Ban(models.Model):
324
338 325 ip = models.GenericIPAddressField()
339 326
340 327 def __unicode__(self):
General Comments 0
You need to be logged in to leave comments. Login now