##// END OF EJS Templates
Do not cache the thread view because it cannot load new replies after browser is restarted.
Do not cache the thread view because it cannot load new replies after browser is restarted.

File last commit:

r740:7c2d35f4 2.0-dev
r858:2bce3a47 default
Show More
tag.py
78 lines | 1.9 KiB | text/x-python | PythonLexer
neko259
Added tag search. Refactored search to show any model results in a list.
r692 from django.template.loader import render_to_string
neko259
Split up user models
r386 from django.db import models
neko259
Use aggregation to get tags popularity
r607 from django.db.models import Count, Sum
neko259
Added tag search. Refactored search to show any model results in a list.
r692 from django.core.urlresolvers import reverse
neko259
Removed obsolete import
r732
from boards.models import Thread
neko259
Added tag search. Refactored search to show any model results in a list.
r692 from boards.models.base import Viewable
neko259
Split up tag module from post module
r385
neko259
Removed obsolete import
r732
neko259
Split up tag module from post module
r385 __author__ = 'neko259'
class TagManager(models.Manager):
def get_not_empty_tags(self):
neko259
Small updates to the tag model docstrings.
r623 """
Gets tags that have non-archived threads.
"""
neko259
Split up tag module from post module
r385 tags = self.annotate(Count('threads')) \
neko259
Include tags that have only archived threads to the general tags list
r700 .filter(threads__count__gt=0).order_by('name')
neko259
Split up tag module from post module
r385
return tags
neko259
Added tag search. Refactored search to show any model results in a list.
r692 class Tag(models.Model, Viewable):
neko259
Split up tag module from post module
r385 """
neko259
Split up post model into post and thread to normalise models. Still need some refactoring
r398 A tag is a text node assigned to the thread. The tag serves as a board
section. There can be multiple tags for each thread
neko259
Split up tag module from post module
r385 """
objects = TagManager()
class Meta:
app_label = 'boards'
neko259
Optimized thread view and threads list
r649 ordering = ('name',)
neko259
Split up tag module from post module
r385
neko259
Small speedups. Added index on the name column for tag
r609 name = models.CharField(max_length=100, db_index=True)
neko259
Split up post model into post and thread to normalise models. Still need some refactoring
r398 threads = models.ManyToManyField(Thread, null=True,
neko259
Split up tag module from post module
r385 blank=True, related_name='tag+')
def __unicode__(self):
return self.name
def is_empty(self):
neko259
Small updates to the tag model docstrings.
r623 """
Checks if the tag has some threads.
"""
neko259
Speed up tag list generation a bit
r606 return self.get_thread_count() == 0
neko259
Split up tag module from post module
r385
neko259
Speed up tag list generation a bit
r606 def get_thread_count(self):
neko259
Split up tag module from post module
r385 return self.threads.count()
neko259
Speed up tag list generation a bit
r606 def get_post_count(self, archived=False):
neko259
Small updates to the tag model docstrings.
r623 """
Gets posts count for the tag's threads.
"""
neko259
Speed up tag list generation a bit
r606 posts_count = 0
neko259
Use aggregation to get tags popularity
r607 threads = self.threads.filter(archived=archived)
if threads.exists():
neko259
Code cleanup. Update only edited fields while performing thread archiving or post editing. Remove image when post is removed
r715 posts_count = threads.annotate(posts_count=Count('replies')) \
.aggregate(posts_sum=Sum('posts_count'))['posts_sum']
neko259
Use aggregation to get tags popularity
r607
if not posts_count:
posts_count = 0
neko259
Speed up tag list generation a bit
r606
return posts_count
neko259
Added tag search. Refactored search to show any model results in a list.
r692
def get_url(self):
return reverse('tag', kwargs={'tag_name': self.name})
def get_view(self, *args, **kwargs):
return render_to_string('boards/tag.html', {
'tag': self,
neko259
Include tags that have only archived threads to the general tags list
r700 })