##// END OF EJS Templates
Use global thread ID instead of local one.
Use global thread ID instead of local one.

File last commit:

r932:f79c8862 default
r936:ff78113e decentral
Show More
tag.py
71 lines | 1.8 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
Optimized tag DB queries
r928 from django.db.models import Count
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
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
Optimized tag DB queries
r928 return self.filter(thread__archived=False)\
neko259
Fixed tag ordering that was broken with latest change
r929 .annotate(num_threads=Count('thread')).filter(num_threads__gt=0)\
neko259
Fixed tag ordering
r932 .order_by('-required', 'name')
neko259
Split up tag module from post module
r385
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
Added required tags. At least one such tag is needed to create a thread. All...
r922 required = models.BooleanField(default=False)
neko259
Split up tag module from post module
r385
neko259
Show thread, post and tag names in admin with python3
r875 def __str__(self):
neko259
Split up tag module from post module
r385 return self.name
neko259
Use threads' tags list to aggregate threads by tag
r908 def is_empty(self) -> bool:
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
Use threads' tags list to aggregate threads by tag
r908 def get_thread_count(self) -> int:
return self.get_threads().count()
neko259
Split up tag module from post module
r385
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})
neko259
Use threads' tags list to aggregate threads by tag
r908 def get_threads(self):
neko259
Optimized tag DB queries
r928 return self.thread_set.order_by('-bump_time')
neko259
Added required tags. At least one such tag is needed to create a thread. All...
r922
def is_required(self):
return self.required
def get_view(self):
link = '<a class="tag" href="{}">{}</a>'.format(
neko259
Optimized tag DB queries
r928 self.get_url(), self.name)
neko259
Added required tags. At least one such tag is needed to create a thread. All...
r922 if self.is_required():
link = '<b>{}</b>'.format(link)
return link
def get_search_view(self, *args, **kwargs):
return render_to_string('boards/tag.html', {
neko259
Optimized tag DB queries
r928 'tag': self,
})