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