diff --git a/boards/models/tag.py b/boards/models/tag.py --- a/boards/models/tag.py +++ b/boards/models/tag.py @@ -15,6 +15,10 @@ ARCHIVE_POPULARITY_MODIFIER = 0.5 class TagManager(models.Manager): def get_not_empty_tags(self): + """ + Gets tags that have non-archived threads. + """ + tags = self.annotate(Count('threads')) \ .filter(threads__count__gt=0).filter(threads__archived=False) \ .order_by('name') @@ -42,13 +46,22 @@ class Tag(models.Model): return self.name def is_empty(self): + """ + Checks if the tag has some threads. + """ + return self.get_thread_count() == 0 def get_thread_count(self): return self.threads.count() def get_popularity(self): - all_post_count = Post.objects.all().count() + """ + Gets tag's popularity value as a percentage of overall board post + count. + """ + + all_post_count = Post.objects.count() tag_reply_count = 0.0 @@ -61,6 +74,10 @@ class Tag(models.Model): return popularity def get_linked_tags(self): + """ + Gets tags linked to the current one. + """ + tag_list = [] self.get_linked_tags_list(tag_list) @@ -80,7 +97,9 @@ class Tag(models.Model): linked_tag.get_linked_tags_list(tag_list) def get_font_value(self): - """Get tag font value to differ most popular tags in the list""" + """ + Gets tag font value to differ most popular tags in the list + """ popularity = self.get_popularity() @@ -91,6 +110,10 @@ class Tag(models.Model): return str(font_value) def get_post_count(self, archived=False): + """ + Gets posts count for the tag's threads. + """ + posts_count = 0 threads = self.threads.filter(archived=archived)