# HG changeset patch # User neko259 # Date 2013-09-12 19:02:14 # Node ID 27756a1b723158310e6d8705a82c3e98de38c09e # Parent 2f4adb2ccad8f8795411ac7304d699fe5883514c Removed old and unused code. Added TODOs for future refactoring and optimization. diff --git a/boards/models.py b/boards/models.py --- a/boards/models.py +++ b/boards/models.py @@ -45,13 +45,11 @@ class PostManager(models.Manager): last_edit_time=timezone.now(), user=user) - if thread: - thread.replies.add(post) - if tags: map(post.tags.add, tags) if thread: + thread.replies.add(post) thread.bump() else: self._delete_old_threads() @@ -138,32 +136,20 @@ class PostManager(models.Manager): map(self.delete_post, old_threads) - def _bump_thread(self, thread_id): - thread = self.get(id=thread_id) - - if thread.can_bump(): - thread.last_edit_time = timezone.now() - thread.save() - class TagManager(models.Manager): + def get_not_empty_tags(self): all_tags = self.all().order_by('name') tags = [] + + # TODO Use query here for tag in all_tags: if not tag.is_empty(): tags.append(tag) return tags - def get_popular_tags(self): - all_tags = self.get_not_empty_tags() - - sorted_tags = sorted(all_tags, key=lambda tag: tag.get_popularity(), - reverse=True) - - return sorted_tags[:settings.POPULAR_TAGS] - class Tag(models.Model): """ @@ -182,11 +168,11 @@ class Tag(models.Model): return self.get_post_count() == 0 def get_post_count(self): - posts_with_tag = Post.objects.get_threads(tag=self) + posts_with_tag = Post.objects.filter(tag=self) return posts_with_tag.count() def get_popularity(self): - posts_with_tag = Post.objects.get_threads(tag=self) + posts_with_tag = Post.objects.filter(tag=self) reply_count = 0 for post in posts_with_tag: reply_count += post.get_reply_count() @@ -227,7 +213,7 @@ class Post(models.Model): poster_ip = models.GenericIPAddressField() poster_user_agent = models.TextField() - # TODO Convert this field to ForeignKey + # TODO Remove this field after everything has been updated to 'thread' parent = models.BigIntegerField(default=NO_PARENT) thread = models.ForeignKey('Post', null=True, default=None) @@ -249,15 +235,13 @@ class Post(models.Model): return title - def _get_replies(self): - return self.replies - def get_reply_count(self): return self.replies.count() def get_images_count(self): images_count = 1 if self.image else 0 + # TODO Use query here for reply in self.replies: if reply.image: images_count += 1 @@ -272,6 +256,8 @@ class Post(models.Model): return post_count <= settings.MAX_POSTS_PER_THREAD def bump(self): + """Bump (move to up) thread""" + if self.can_bump(): self.last_edit_time = timezone.now() self.save() @@ -335,6 +321,7 @@ class Setting(models.Model): class Ban(models.Model): + ip = models.GenericIPAddressField() def __unicode__(self):