##// END OF EJS Templates
Fixed thread RSS
Fixed thread RSS

File last commit:

r520:44953ced default
r580:7081c21d default
Show More
tag.py
91 lines | 2.3 KiB | text/x-python | PythonLexer
neko259
Split up post model into post and thread to normalise models. Still need some refactoring
r398 from boards.models import Thread
neko259
Split up user models
r386 from django.db import models
from django.db.models import Count
neko259
Split up tag module from post module
r385
__author__ = 'neko259'
TAG_FONT_MULTIPLIER = 0.1
neko259
Another changes to the popularity code
r520 MAX_TAG_FONT = 3
neko259
Added new popularity counter for tags
r509
neko259
Another changes to the popularity code
r520 OPENING_POST_POPULARITY = 0.3
REPLY_POPULARITY = 0.06
neko259
Small changes to the tag popularity code
r519 ARCHIVE_POPULARITY_MODIFIER = 0.1
neko259
Split up tag module from post module
r385
class TagManager(models.Manager):
def get_not_empty_tags(self):
tags = self.annotate(Count('threads')) \
.filter(threads__count__gt=0).order_by('name')
return tags
class Tag(models.Model):
"""
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'
name = models.CharField(max_length=100)
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+')
linked = models.ForeignKey('Tag', null=True, blank=True)
def __unicode__(self):
return self.name
def is_empty(self):
return self.get_post_count() == 0
def get_post_count(self):
return self.threads.count()
neko259
Added new popularity counter for tags
r509 def get_popularity(self):
popularity = 0.0
for thread in self.threads.all():
reply_count = thread.get_reply_count()
neko259
Small changes to the tag popularity code
r519 thread_popularity = 0.0
thread_popularity += REPLY_POPULARITY * reply_count
thread_popularity += OPENING_POST_POPULARITY
neko259
Added new popularity counter for tags
r509 if thread.archived:
neko259
Small changes to the tag popularity code
r519 thread_popularity *= ARCHIVE_POPULARITY_MODIFIER
popularity += thread_popularity
neko259
Added new popularity counter for tags
r509
return popularity
neko259
Split up tag module from post module
r385
def get_linked_tags(self):
tag_list = []
self.get_linked_tags_list(tag_list)
return tag_list
def get_linked_tags_list(self, tag_list=[]):
"""
Returns the list of tags linked to current. The list can be got
through returned value or tag_list parameter
"""
linked_tag = self.linked
if linked_tag and not (linked_tag in tag_list):
tag_list.append(linked_tag)
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"""
neko259
Added new popularity counter for tags
r509 popularity = self.get_popularity()
neko259
Split up tag module from post module
r385
neko259
Small changes to the tag popularity code
r519 font_value = 1 + (popularity - 1) * TAG_FONT_MULTIPLIER
font_value = min(font_value, MAX_TAG_FONT)
neko259
Split up tag module from post module
r385
neko259
Small changes to the tag popularity code
r519 return str(font_value)