##// END OF EJS Templates
Added template tag to render post the same way in all places (threads list, thread view, post view)
neko259 -
r537:32f43bd2 default
parent child Browse files
Show More
@@ -30,17 +30,23 b''
30 <a class="post_id" href="{% post_url post.id %}">
30 <a class="post_id" href="{% post_url post.id %}">
31 ({{ post.id }}) </a>
31 ({{ post.id }}) </a>
32 [<span class="pub_time">{{ post.pub_time }}</span>]
32 [<span class="pub_time">{{ post.pub_time }}</span>]
33 [<a href="#" onclick="javascript:addQuickReply('{{ post.id }}')
33 {% if not truncated %}
34 ; return false;">&gt;&gt;</a>]
34 [<a href="#" onclick="javascript:addQuickReply('{{ post.id }}')
35 ; return false;">&gt;&gt;</a>]
36 {% endif %}
37 {% if need_open_link %}
38 [<a class="link" href="
39 {% url 'thread' post.id %}#form">{% trans "Reply" %}</a>]
40 {% endif %}
35
41
36 {% if moderator %}
42 {% if moderator %}
37 <span class="moderator_info">
43 <span class="moderator_info">
38 [<a href="{% url 'delete' post_id=post.id %}"
44 [<a href="{% url 'delete' post_id=post.id %}"
39 >{% trans 'Delete' %}</a>]
45 >{% trans 'Delete' %}</a>]
40 ({{ post.poster_ip }})
46 ({{ post.poster_ip }})
41 [<a href="{% url 'ban' post_id=post.id %}?next={{ request.path }}"
47 [<a href="{% url 'ban' post_id=post.id %}?next={{ request.path }}"
42 >{% trans 'Ban IP' %}</a>]
48 >{% trans 'Ban IP' %}</a>]
43 </span>
49 </span>
44 {% endif %}
50 {% endif %}
45 </div>
51 </div>
46 {% autoescape off %}
52 {% autoescape off %}
@@ -52,11 +58,11 b''
52 {% endautoescape %}
58 {% endautoescape %}
53 {% if post.is_referenced %}
59 {% if post.is_referenced %}
54 <div class="refmap">
60 <div class="refmap">
55 {% trans "Replies" %}:
61 {% trans "Replies" %}:
56 {% for ref_post in post.get_sorted_referenced_posts %}
62 {% for ref_post in post.get_sorted_referenced_posts %}
57 <a href="{% post_url ref_post.id %}">&gt;&gt;{{ ref_post.id }}</a
63 <a href="{% post_url ref_post.id %}">&gt;&gt;{{ ref_post.id }}</a
58 >{% if not forloop.last %},{% endif %}
64 >{% if not forloop.last %},{% endif %}
59 {% endfor %}
65 {% endfor %}
60 </div>
66 </div>
61 {% endif %}
67 {% endif %}
62 </div>
68 </div>
@@ -68,73 +68,7 b''
68 {% for thread in threads %}
68 {% for thread in threads %}
69 {% cache 600 thread_short thread.thread.id thread.thread.last_edit_time moderator LANGUAGE_CODE %}
69 {% cache 600 thread_short thread.thread.id thread.thread.last_edit_time moderator LANGUAGE_CODE %}
70 <div class="thread">
70 <div class="thread">
71 {% if thread.bumpable %}
71 {% post_view_truncated thread.op True %}
72 <div class="post" id="{{ thread.op.id }}">
73 {% else %}
74 <div class="post dead_post" id="{{ thread.op.id }}">
75 {% endif %}
76 {% if thread.op.image %}
77 <div class="image">
78 <a class="thumb"
79 href="{{ thread.op.image.url }}"><img
80 src="{{ thread.op.image.url_200x150 }}"
81 alt="{{ thread.op.id }}"
82 width="{{ thread.op.image_pre_width }}"
83 height="{{ thread.op.image_pre_height }}"
84 data-width="{{ thread.op.image_width }}"
85 data-height="{{ thread.op.image_height }}"/>
86 </a>
87 </div>
88 {% endif %}
89 <div class="message">
90 <div class="post-info">
91 <span class="title">{{ thread.op.title }}</span>
92 <a class="post_id" href="{% url 'thread' thread.op.id %}"
93 > ({{ thread.op.id }})</a>
94 [{{ thread.op.pub_time }}]
95 [<a class="link" href="
96 {% url 'thread' thread.op.id %}#form"
97 >{% trans "Reply" %}</a>]
98
99 {% if moderator %}
100 <span class="moderator_info">
101 [<a href="
102 {% url 'delete' post_id=thread.op.id %}?next={{ request.path }}"
103 >{% trans 'Delete' %}</a>]
104 ({{ thread.op.poster_ip }})
105 [<a href="
106 {% url 'ban' post_id=thread.op.id %}?next={{ request.path }}"
107 >{% trans 'Ban IP' %}</a>]
108 </span>
109 {% endif %}
110 </div>
111 {% autoescape off %}
112 {{ thread.op.text.rendered|truncatewords_html:50 }}
113 {% endautoescape %}
114 {% if thread.op.is_referenced %}
115 <div class="refmap">
116 {% trans "Replies" %}:
117 {% for ref_post in thread.op.get_sorted_referenced_posts %}
118 <a href="{% post_url ref_post.id %}">&gt;&gt;{{ ref_post.id }}</a
119 >{% if not forloop.last %},{% endif %}
120 {% endfor %}
121 </div>
122 {% endif %}
123 </div>
124 <div class="metadata">
125 {{ thread.thread.get_images_count }} {% trans 'images' %}.
126 {% if thread.thread.tags %}
127 <span class="tags">
128 {% for tag in thread.thread.get_tags %}
129 <a class="tag" href="
130 {% url 'tag' tag_name=tag.name %}">
131 #{{ tag.name }}</a
132 >{% if not forloop.last %},{% endif %}
133 {% endfor %}
134 </span>
135 {% endif %}
136 </div>
137 </div>
138 {% if thread.last_replies.exists %}
72 {% if thread.last_replies.exists %}
139 {% if thread.skipped_replies %}
73 {% if thread.skipped_replies %}
140 <div class="skipped_replies">
74 <div class="skipped_replies">
@@ -145,46 +79,7 b''
145 {% endif %}
79 {% endif %}
146 <div class="last-replies">
80 <div class="last-replies">
147 {% for post in thread.last_replies %}
81 {% for post in thread.last_replies %}
148 {% if thread.bumpable %}
82 {% post_view_truncated post %}
149 <div class="post" id="{{ post.id }}">
150 {% else %}
151 <div class="post dead_post" id="{{ post.id }}">
152 {% endif %}
153 {% if post.image %}
154 <div class="image">
155 <a class="thumb"
156 href="{{ post.image.url }}"><img
157 src=" {{ post.image.url_200x150 }}"
158 alt="{{ post.id }}"
159 width="{{ post.image_pre_width }}"
160 height="{{ post.image_pre_height }}"
161 data-width="{{ post.image_width }}"
162 data-height="{{ post.image_height }}"/>
163 </a>
164 </div>
165 {% endif %}
166 <div class="message">
167 <div class="post-info">
168 <span class="title">{{ post.title }}</span>
169 <a class="post_id" href="
170 {% url 'thread' thread.op.id %}#{{ post.id }}">
171 ({{ post.id }})</a>
172 [{{ post.pub_time }}]
173 </div>
174 {% autoescape off %}
175 {{ post.text.rendered|truncatewords_html:50 }}
176 {% endautoescape %}
177 </div>
178 {% if post.is_referenced %}
179 <div class="refmap">
180 {% trans "Replies" %}:
181 {% for ref_post in post.get_sorted_referenced_posts %}
182 <a href="{% post_url ref_post.id %}">&gt;&gt;{{ ref_post.id }}</a
183 >{% if not forloop.last %},{% endif %}
184 {% endfor %}
185 </div>
186 {% endif %}
187 </div>
188 {% endfor %}
83 {% endfor %}
189 </div>
84 </div>
190 {% endif %}
85 {% endif %}
@@ -31,73 +31,7 b''
31 {% endif %}
31 {% endif %}
32 <div class="thread">
32 <div class="thread">
33 {% for post in posts %}
33 {% for post in posts %}
34 {% if bumpable %}
34 {% post_view post %}
35 <div class="post" id="{{ post.id }}">
36 {% elif thread.archived %}
37 <div class="post archive_post" id="{{ post.id }}">
38 {% else %}
39 <div class="post dead_post" id="{{ post.id }}">
40 {% endif %}
41 {% if post.image %}
42 <div class="image">
43 <a
44 class="thumb"
45 href="{{ post.image.url }}"><img
46 src="{{ post.image.url_200x150 }}"
47 alt="{{ post.id }}"
48 width="{{ post.image_pre_width }}"
49 height="{{ post.image_pre_height }}"
50 data-width="{{ post.image_width }}"
51 data-height="{{ post.image_height }}"/>
52 </a>
53 </div>
54 {% endif %}
55 <div class="message">
56 <div class="post-info">
57 <span class="title">{{ post.title }}</span>
58 <a class="post_id" href="#{{ post.id }}">
59 ({{ post.id }}) </a>
60 [<span class="pub_time">{{ post.pub_time }}</span>]
61 {% if not thread.archived %}
62 [<a href="#" onclick="javascript:addQuickReply('{{ post.id }}')
63 ; return false;">&gt;&gt;</a>]
64 {% endif %}
65
66 {% if moderator %}
67 <span class="moderator_info">
68 [<a href="{% url 'delete' post_id=post.id %}"
69 >{% trans 'Delete' %}</a>]
70 ({{ post.poster_ip }})
71 [<a href="{% url 'ban' post_id=post.id %}?next={{ request.path }}"
72 >{% trans 'Ban IP' %}</a>]
73 </span>
74 {% endif %}
75 </div>
76 {% autoescape off %}
77 {{ post.text.rendered }}
78 {% endautoescape %}
79 {% if post.is_referenced %}
80 <div class="refmap">
81 {% trans "Replies" %}:
82 {% for ref_post in post.get_sorted_referenced_posts %}
83 <a href="{% post_url ref_post.id %}">&gt;&gt;{{ ref_post.id }}</a
84 >{% if not forloop.last %},{% endif %}
85 {% endfor %}
86 </div>
87 {% endif %}
88 </div>
89 {% if forloop.first %}
90 <div class="metadata">
91 <span class="tags">
92 {% for tag in thread.get_tags %}
93 <a class="tag" href="{% url 'tag' tag.name %}">
94 #{{ tag.name }}</a
95 >{% if not forloop.last %},{% endif %}
96 {% endfor %}
97 </span>
98 </div>
99 {% endif %}
100 </div>
101 {% endfor %}
35 {% endfor %}
102 </div>
36 </div>
103 {% endcache %}
37 {% endcache %}
@@ -1,7 +1,7 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
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()
@@ -47,3 +47,25 b' def image_actions(*args, **kwargs):'
47 action['name'] + '</a>]'
47 action['name'] + '</a>]'
48
48
49 return result
49 return result
50
51
52 @register.inclusion_tag('boards/post.html', name='post_view')
53 def post_view(*args, **kwargs):
54 post = args[0]
55
56 return { 'post': post }
57
58
59 @register.inclusion_tag('boards/post.html', name='post_view_truncated')
60 def post_view_truncated(*args, **kwargs):
61 post = args[0]
62 if len(args) > 1:
63 need_open_link = args[1]
64 else:
65 need_open_link = False
66
67 return {
68 'post': post,
69 'truncated': True,
70 'need_open_link': need_open_link
71 } No newline at end of file
@@ -98,7 +98,6 b' def get_post(request, post_id):'
98 """
98 """
99
99
100 post = get_object_or_404(Post, id=post_id)
100 post = get_object_or_404(Post, id=post_id)
101 thread = post.thread_new
102
101
103 context = RequestContext(request)
102 context = RequestContext(request)
104 context['post'] = post
103 context['post'] = post
General Comments 0
You need to be logged in to leave comments. Login now