##// END OF EJS Templates
Added tag search. Refactored search to show any model results in a list.
neko259 -
r692:d0013853 1.8-dev
parent child Browse files
Show More
@@ -0,0 +1,10 b''
1 __author__ = 'neko259'
2
3
4 class Viewable():
5 def __init__(self):
6 pass
7
8 def get_view(self, *args, **kwargs):
9 """Get an HTML view for a model"""
10 pass No newline at end of file
@@ -10,10 +10,12 b' import hashlib'
10 from django.core.cache import cache
10 from django.core.cache import cache
11 from django.core.urlresolvers import reverse
11 from django.core.urlresolvers import reverse
12 from django.db import models, transaction
12 from django.db import models, transaction
13 from django.template.loader import render_to_string
13 from django.utils import timezone
14 from django.utils import timezone
14 from markupfield.fields import MarkupField
15 from markupfield.fields import MarkupField
16 from boards.models.base import Viewable
17
15 from boards.models.thread import Thread
18 from boards.models.thread import Thread
16
17 from neboard import settings
19 from neboard import settings
18 from boards import thumbs
20 from boards import thumbs
19
21
@@ -193,7 +195,7 b' class PostManager(models.Manager):'
193 return ppd
195 return ppd
194
196
195
197
196 class Post(models.Model):
198 class Post(models.Model, Viewable):
197 """A post is a message."""
199 """A post is a message."""
198
200
199 objects = PostManager()
201 objects = PostManager()
@@ -357,4 +359,38 b' class Post(models.Model):'
357 return self.thread_new
359 return self.thread_new
358
360
359 def get_referenced_posts(self):
361 def get_referenced_posts(self):
360 return self.referenced_posts.only('id', 'thread_new') No newline at end of file
362 return self.referenced_posts.only('id', 'thread_new')
363
364 def get_text(self):
365 return self.text
366
367 def get_view(self, moderator=False, need_open_link=False,
368 truncated=False, *args, **kwargs):
369 if 'is_opening' in kwargs:
370 is_opening = kwargs['is_opening']
371 else:
372 is_opening = self.is_opening()
373
374 if 'thread' in kwargs:
375 thread = kwargs['thread']
376 else:
377 thread = self.get_thread()
378
379 if 'can_bump' in kwargs:
380 can_bump = kwargs['can_bump']
381 else:
382 can_bump = thread.can_bump()
383
384 opening_post_id = thread.get_opening_post_id()
385
386 return render_to_string('boards/post.html', {
387 'post': self,
388 'moderator': moderator,
389 'is_opening': is_opening,
390 'thread': thread,
391 'bumpable': can_bump,
392 'need_open_link': need_open_link,
393 'truncated': truncated,
394 'opening_post_id': opening_post_id,
395 })
396
@@ -1,6 +1,9 b''
1 from django.template.loader import render_to_string
1 from boards.models import Thread, Post
2 from boards.models import Thread, Post
2 from django.db import models
3 from django.db import models
3 from django.db.models import Count, Sum
4 from django.db.models import Count, Sum
5 from django.core.urlresolvers import reverse
6 from boards.models.base import Viewable
4
7
5 __author__ = 'neko259'
8 __author__ = 'neko259'
6
9
@@ -26,7 +29,7 b' class TagManager(models.Manager):'
26 return tags
29 return tags
27
30
28
31
29 class Tag(models.Model):
32 class Tag(models.Model, Viewable):
30 """
33 """
31 A tag is a text node assigned to the thread. The tag serves as a board
34 A tag is a text node assigned to the thread. The tag serves as a board
32 section. There can be multiple tags for each thread
35 section. There can be multiple tags for each thread
@@ -126,3 +129,11 b' class Tag(models.Model):'
126 posts_count = 0
129 posts_count = 0
127
130
128 return posts_count
131 return posts_count
132
133 def get_url(self):
134 return reverse('tag', kwargs={'tag_name': self.name})
135
136 def get_view(self, *args, **kwargs):
137 return render_to_string('boards/tag.html', {
138 'tag': self,
139 }) No newline at end of file
@@ -1,5 +1,5 b''
1 from haystack import indexes
1 from haystack import indexes
2 from boards.models import Post
2 from boards.models import Post, Tag
3
3
4 __author__ = 'neko259'
4 __author__ = 'neko259'
5
5
@@ -11,4 +11,14 b' class PostIndex(indexes.SearchIndex, ind'
11 return Post
11 return Post
12
12
13 def index_queryset(self, using=None):
13 def index_queryset(self, using=None):
14 return self.get_model().objects.all() No newline at end of file
14 return self.get_model().objects.all()
15
16
17 class TagIndex(indexes.SearchIndex, indexes.Indexable):
18 text = indexes.CharField(document=True, use_template=True)
19
20 def get_model(self):
21 return Tag
22
23 def index_queryset(self, using=None):
24 return self.get_model().objects.get_not_empty_tags()
@@ -1,96 +1,3 b''
1 {% load i18n %}
1 <div class="post">
2 {% load board %}
2 <a class="tag" href="{% url 'tag' tag_name=tag.name %}">#{{ tag.name }}</a>
3 {% load cache %}
3 </div> No newline at end of file
4
5 {% get_current_language as LANGUAGE_CODE %}
6
7 {% spaceless %}
8 {% cache 600 post post.id post.last_edit_time thread.archived bumpable truncated moderator LANGUAGE_CODE need_open_link %}
9 {% if thread.archived %}
10 <div class="post archive_post" id="{{ post.id }}">
11 {% elif bumpable %}
12 <div class="post" id="{{ post.id }}">
13 {% else %}
14 <div class="post dead_post" id="{{ post.id }}">
15 {% endif %}
16
17 <div class="post-info">
18 <a class="post_id" href="{% post_object_url post thread=thread %}"
19 {% if not truncated and not thread.archived %}
20 onclick="javascript:addQuickReply('{{ post.id }}'); return false;"
21 title="{% trans 'Quote' %}"
22 {% endif %}
23 >({{ post.id }}) </a>
24 <span class="title">{{ post.title }} </span>
25 <span class="pub_time">{{ post.pub_time }}</span>
26 {% if thread.archived %}
27 — {{ thread.bump_time }}
28 {% endif %}
29 {% if is_opening and need_open_link %}
30 {% if thread.archived %}
31 [<a class="link" href="{% url 'thread' post.id %}">{% trans "Open" %}</a>]
32 {% else %}
33 [<a class="link" href="{% url 'thread' post.id %}#form">{% trans "Reply" %}</a>]
34 {% endif %}
35 {% endif %}
36
37 {% if moderator %}
38 <span class="moderator_info">
39 [<a href="{% url 'post_admin' post_id=post.id %}"
40 >{% trans 'Edit' %}</a>]
41 [<a href="{% url 'delete' post_id=post.id %}"
42 >{% trans 'Delete' %}</a>]
43 ({{ post.poster_ip }})
44 [<a href="{% url 'ban' post_id=post.id %}?next={{ request.path }}"
45 >{% trans 'Ban IP' %}</a>]
46 </span>
47 {% endif %}
48 </div>
49 {% if post.image %}
50 <div class="image">
51 <a
52 class="thumb"
53 href="{{ post.image.url }}"><img
54 src="{{ post.image.url_200x150 }}"
55 alt="{{ post.id }}"
56 width="{{ post.image_pre_width }}"
57 height="{{ post.image_pre_height }}"
58 data-width="{{ post.image_width }}"
59 data-height="{{ post.image_height }}"/>
60 </a>
61 </div>
62 {% endif %}
63 <div class="message">
64 {% autoescape off %}
65 {% if truncated %}
66 {{ post.text.rendered|truncatewords_html:50 }}
67 {% else %}
68 {{ post.text.rendered }}
69 {% endif %}
70 {% endautoescape %}
71 {% if post.is_referenced %}
72 <div class="refmap">
73 {% autoescape off %}
74 {% trans "Replies" %}: {{ post.refmap }}
75 {% endautoescape %}
76 </div>
77 {% endif %}
78 </div>
79 {% endcache %}
80 {% if is_opening %}
81 {% cache 600 post_thread thread.id thread.last_edit_time LANGUAGE_CODE need_open_link %}
82 <div class="metadata">
83 {% if is_opening and need_open_link %}
84 {{ thread.get_images_count }} {% trans 'images' %}.
85 {% endif %}
86 <span class="tags">
87 {% for tag in thread.get_tags %}
88 <a class="tag" href="{% url 'tag' tag.name %}">
89 #{{ tag.name }}</a>{% if not forloop.last %},{% endif %}
90 {% endfor %}
91 </span>
92 </div>
93 {% endcache %}
94 {% endif %}
95 </div>
96 {% endspaceless %}
@@ -1,8 +1,7 b''
1 from django.shortcuts import get_object_or_404
1 from django.shortcuts import get_object_or_404
2 from boards.models import Post
3 from boards.views import thread, api
4 from django import template
2 from django import template
5
3
4
6 register = template.Library()
5 register = template.Library()
7
6
8 actions = [
7 actions = [
@@ -21,7 +20,7 b' actions = ['
21 def post_url(*args, **kwargs):
20 def post_url(*args, **kwargs):
22 post_id = args[0]
21 post_id = args[0]
23
22
24 post = get_object_or_404(Post, id=post_id)
23 post = get_object_or_404('Post', id=post_id)
25
24
26 return post.get_url()
25 return post.get_url()
27
26
@@ -53,6 +52,7 b' def image_actions(*args, **kwargs):'
53 return result
52 return result
54
53
55
54
55 # TODO Use get_view of a post instead of this
56 @register.inclusion_tag('boards/post.html', name='post_view')
56 @register.inclusion_tag('boards/post.html', name='post_view')
57 def post_view(post, moderator=False, need_open_link=False, truncated=False,
57 def post_view(post, moderator=False, need_open_link=False, truncated=False,
58 **kwargs):
58 **kwargs):
@@ -1,3 +1,4 b''
1 haystack
1 pillow
2 pillow
2 django>=1.6
3 django>=1.6
3 django_cleanup
4 django_cleanup
@@ -1,2 +1,1 b''
1 {{ object.title }}
1 {{ object.name }} No newline at end of file
2 {{ object.text }} No newline at end of file
@@ -14,9 +14,9 b''
14
14
15 {% if query %}
15 {% if query %}
16 {% for result in page.object_list %}
16 {% for result in page.object_list %}
17 {% post_view result.object %}
17 {{ result.object.get_view }}
18 {% empty %}
18 {% empty %}
19 <p>{% trans 'No results found.' %}</p>
19 <div class="post">{% trans 'No results found.' %}</div>
20 {% endfor %}
20 {% endfor %}
21
21
22 {% if page.has_previous or page.has_next %}
22 {% if page.has_previous or page.has_next %}
General Comments 0
You need to be logged in to leave comments. Login now