##// END OF EJS Templates
Some more optimization to the post html
neko259 -
r571:1c1f004f 1.7-dev
parent child Browse files
Show More
@@ -1,100 +1,105 b''
1 1 {% load i18n %}
2 2 {% load board %}
3 3 {% load cache %}
4 4
5 5 {% get_current_language as LANGUAGE_CODE %}
6 6
7 7 {% cache 600 post post.id thread.last_edit_time truncated moderator LANGUAGE_CODE need_open_link %}
8
9 {% with is_opening=post.is_opening %}
8 10 {% spaceless %}
9 11 {% with thread=post.thread_new %}
10 12 {% if thread.archived %}
11 13 <div class="post archive_post" id="{{ post.id }}">
12 14 {% elif thread.can_bump %}
13 15 <div class="post" id="{{ post.id }}">
14 16 {% else %}
15 17 <div class="post dead_post" id="{{ post.id }}">
16 18 {% endif %}
17 19
18 20 {% if post.image %}
19 21 <div class="image">
20 22 <a
21 23 class="thumb"
22 24 href="{{ post.image.url }}"><img
23 25 src="{{ post.image.url_200x150 }}"
24 26 alt="{{ post.id }}"
25 27 width="{{ post.image_pre_width }}"
26 28 height="{{ post.image_pre_height }}"
27 29 data-width="{{ post.image_width }}"
28 30 data-height="{{ post.image_height }}"/>
29 31 </a>
30 32 </div>
31 33 {% endif %}
32 34 <div class="message">
33 35 <div class="post-info">
34 36 <span class="title">{{ post.title }}</span>
35 <a class="post_id" href="{% post_url post.id %}">
36 ({{ post.id }}) </a>
37 {% cache 600 post_id post.id %}
38 <a class="post_id" href="{% post_url post.id %}">
39 ({{ post.id }}) </a>
40 {% endcache %}
37 41 [<span class="pub_time">{{ post.pub_time }}</span>]
38 42 {% if thread.archived %}
39 43 β€” [{{ thread.bump_time }}]
40 44 {% endif %}
41 45 {% if not truncated and not thread.archived %}
42 46 [<a href="#" onclick="javascript:addQuickReply('{{ post.id }}')
43 47 ; return false;">&gt;&gt;</a>]
44 48 {% endif %}
45 {% if post.is_opening and need_open_link %}
49 {% if is_opening and need_open_link %}
46 50 {% if post.thread_new.archived %}
47 51 [<a class="link" href="{% url 'thread' post.id %}">{% trans "Open" %}</a>]
48 52 {% else %}
49 53 [<a class="link" href="{% url 'thread' post.id %}#form">{% trans "Reply" %}</a>]
50 54 {% endif %}
51 55 {% endif %}
52 56
53 57 {% if moderator %}
54 58 <span class="moderator_info">
55 59 [<a href="{% url 'post_admin' post_id=post.id %}"
56 60 >{% trans 'Edit' %}</a>]
57 61 [<a href="{% url 'delete' post_id=post.id %}"
58 62 >{% trans 'Delete' %}</a>]
59 63 ({{ post.poster_ip }})
60 64 [<a href="{% url 'ban' post_id=post.id %}?next={{ request.path }}"
61 65 >{% trans 'Ban IP' %}</a>]
62 66 </span>
63 67 {% endif %}
64 68 </div>
65 69 {% autoescape off %}
66 70 {% if truncated %}
67 71 {{ post.text.rendered|truncatewords_html:50 }}
68 72 {% else %}
69 73 {{ post.text.rendered }}
70 74 {% endif %}
71 75 {% endautoescape %}
72 76 {% cache 600 post_replies post.id post.last_edit_time moderator LANGUAGE_CODE %}
73 {% if post.is_referenced %}
74 <div class="refmap">
75 {% trans "Replies" %}:
76 {% for ref_post in post.get_sorted_referenced_posts %}
77 <a href="{% post_url ref_post.id %}">&gt;&gt;{{ ref_post.id }}</a
78 >{% if not forloop.last %},{% endif %}
79 {% endfor %}
80 </div>
81 {% endif %}
77 {% if post.is_referenced %}
78 <div class="refmap">
79 {% trans "Replies" %}:
80 {% for ref_post in post.get_sorted_referenced_posts %}
81 <a href="{% post_url ref_post.id %}">&gt;&gt;{{ ref_post.id }}</a
82 >{% if not forloop.last %},{% endif %}
83 {% endfor %}
84 </div>
85 {% endif %}
82 86 {% endcache %}
83 87 </div>
84 {% if post.is_opening and thread.tags.exists %}
88 {% if is_opening and thread.tags.exists %}
85 89 <div class="metadata">
86 {% if post.is_opening and need_open_link %}
90 {% if is_opening and need_open_link %}
87 91 {{ thread.get_images_count }} {% trans 'images' %}.
88 92 {% endif %}
89 93 <span class="tags">
90 94 {% for tag in thread.get_tags %}
91 95 <a class="tag" href="{% url 'tag' tag.name %}">
92 96 #{{ tag.name }}</a>{% if not forloop.last %},{% endif %}
93 97 {% endfor %}
94 98 </span>
95 99 </div>
96 100 {% endif %}
97 101 </div>
98 102 {% endwith %}
99 103 {% endspaceless %}
104 {% endwith %}
100 105 {% endcache %}
@@ -1,76 +1,76 b''
1 1 from django.core.urlresolvers import reverse
2 2 from django.shortcuts import get_object_or_404
3 3 from boards.models import Post
4 4 from boards.views import thread, api
5 5 from django import template
6 6
7 7 register = template.Library()
8 8
9 9 actions = [
10 10 {
11 11 'name': 'google',
12 12 'link': 'http://google.com/searchbyimage?image_url=%s',
13 13 },
14 14 {
15 15 'name': 'iqdb',
16 16 'link': 'http://iqdb.org/?url=%s',
17 17 },
18 18 ]
19 19
20 20
21 21 @register.simple_tag(name='post_url')
22 22 def post_url(*args, **kwargs):
23 23 post_id = args[0]
24 24
25 25 post = get_object_or_404(Post, id=post_id)
26 26
27 27 if not post.is_opening():
28 28 link = reverse('thread', kwargs={
29 29 'post_id': post.thread_new.get_opening_post().id}) + '#' + str(
30 30 post_id)
31 31 else:
32 32 link = reverse('thread', kwargs={'post_id': post_id})
33 33
34 34 return link
35 35
36 36
37 37 @register.simple_tag(name='image_actions')
38 38 def image_actions(*args, **kwargs):
39 39 image_link = args[0]
40 40 if len(args) > 1:
41 41 image_link = 'http://' + args[1] + image_link # TODO https?
42 42
43 43 result = ''
44 44
45 45 for action in actions:
46 46 result += '[<a href="' + action['link'] % image_link + '">' + \
47 47 action['name'] + '</a>]'
48 48
49 49 return result
50 50
51 51
52 52 @register.inclusion_tag('boards/post.html', name='post_view')
53 53 def post_view(post, moderator=False):
54 54 """
55 55 Get post
56 56 """
57 57
58 58 return {
59 59 'post': post,
60 60 'moderator': moderator,
61 61 }
62 62
63 63
64 64 @register.inclusion_tag('boards/post.html', name='post_view_truncated')
65 65 def post_view_truncated(post, need_open_link=False, moderator=False):
66 66 """
67 67 Get post with truncated text. If the 'open' or 'reply' link is needed, pass
68 68 the second parameter as True.
69 69 """
70 70
71 71 return {
72 72 'post': post,
73 73 'truncated': True,
74 74 'need_open_link': need_open_link,
75 75 'moderator': moderator,
76 } No newline at end of file
76 }
General Comments 0
You need to be logged in to leave comments. Login now