{% trans 'No results found.' %}
+diff --git a/boards/models/base.py b/boards/models/base.py new file mode 100644 --- /dev/null +++ b/boards/models/base.py @@ -0,0 +1,10 @@ +__author__ = 'neko259' + + +class Viewable(): + def __init__(self): + pass + + def get_view(self, *args, **kwargs): + """Get an HTML view for a model""" + pass \ No newline at end of file diff --git a/boards/models/post.py b/boards/models/post.py --- a/boards/models/post.py +++ b/boards/models/post.py @@ -10,10 +10,12 @@ import hashlib from django.core.cache import cache from django.core.urlresolvers import reverse from django.db import models, transaction +from django.template.loader import render_to_string from django.utils import timezone from markupfield.fields import MarkupField +from boards.models.base import Viewable + from boards.models.thread import Thread - from neboard import settings from boards import thumbs @@ -193,7 +195,7 @@ class PostManager(models.Manager): return ppd -class Post(models.Model): +class Post(models.Model, Viewable): """A post is a message.""" objects = PostManager() @@ -357,4 +359,38 @@ class Post(models.Model): return self.thread_new def get_referenced_posts(self): - return self.referenced_posts.only('id', 'thread_new') \ No newline at end of file + return self.referenced_posts.only('id', 'thread_new') + + def get_text(self): + return self.text + + def get_view(self, moderator=False, need_open_link=False, + truncated=False, *args, **kwargs): + if 'is_opening' in kwargs: + is_opening = kwargs['is_opening'] + else: + is_opening = self.is_opening() + + if 'thread' in kwargs: + thread = kwargs['thread'] + else: + thread = self.get_thread() + + if 'can_bump' in kwargs: + can_bump = kwargs['can_bump'] + else: + can_bump = thread.can_bump() + + opening_post_id = thread.get_opening_post_id() + + return render_to_string('boards/post.html', { + 'post': self, + 'moderator': moderator, + 'is_opening': is_opening, + 'thread': thread, + 'bumpable': can_bump, + 'need_open_link': need_open_link, + 'truncated': truncated, + 'opening_post_id': opening_post_id, + }) + diff --git a/boards/models/tag.py b/boards/models/tag.py --- a/boards/models/tag.py +++ b/boards/models/tag.py @@ -1,6 +1,9 @@ +from django.template.loader import render_to_string from boards.models import Thread, Post from django.db import models from django.db.models import Count, Sum +from django.core.urlresolvers import reverse +from boards.models.base import Viewable __author__ = 'neko259' @@ -26,7 +29,7 @@ class TagManager(models.Manager): return tags -class Tag(models.Model): +class Tag(models.Model, Viewable): """ 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 @@ -126,3 +129,11 @@ class Tag(models.Model): posts_count = 0 return posts_count + + 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, + }) \ No newline at end of file diff --git a/boards/search_indexes.py b/boards/search_indexes.py --- a/boards/search_indexes.py +++ b/boards/search_indexes.py @@ -1,5 +1,5 @@ from haystack import indexes -from boards.models import Post +from boards.models import Post, Tag __author__ = 'neko259' @@ -11,4 +11,14 @@ class PostIndex(indexes.SearchIndex, ind return Post def index_queryset(self, using=None): - return self.get_model().objects.all() \ No newline at end of file + return self.get_model().objects.all() + + +class TagIndex(indexes.SearchIndex, indexes.Indexable): + text = indexes.CharField(document=True, use_template=True) + + def get_model(self): + return Tag + + def index_queryset(self, using=None): + return self.get_model().objects.get_not_empty_tags() diff --git a/boards/templates/boards/post.html b/boards/templates/boards/tag.html copy from boards/templates/boards/post.html copy to boards/templates/boards/tag.html --- a/boards/templates/boards/post.html +++ b/boards/templates/boards/tag.html @@ -1,96 +1,3 @@ -{% load i18n %} -{% load board %} -{% load cache %} - -{% get_current_language as LANGUAGE_CODE %} - -{% spaceless %} - {% cache 600 post post.id post.last_edit_time thread.archived bumpable truncated moderator LANGUAGE_CODE need_open_link %} - {% if thread.archived %} -
{% trans 'No results found.' %}
+