Show More
@@ -1,74 +1,80 b'' | |||||
1 | {% load i18n %} |
|
1 | {% load i18n %} | |
2 | {% load board %} |
|
2 | {% load board %} | |
3 |
|
3 | |||
4 | {% spaceless %} |
|
4 | {% spaceless %} | |
5 | {% if post.thread_new.archived %} |
|
5 | {% if post.thread_new.archived %} | |
6 | <div class="post archive_post" id="{{ post.id }}"> |
|
6 | <div class="post archive_post" id="{{ post.id }}"> | |
7 | {% elif post.thread_new.can_bump %} |
|
7 | {% elif post.thread_new.can_bump %} | |
8 | <div class="post" id="{{ post.id }}"> |
|
8 | <div class="post" id="{{ post.id }}"> | |
9 | {% else %} |
|
9 | {% else %} | |
10 | <div class="post dead_post" id="{{ post.id }}"> |
|
10 | <div class="post dead_post" id="{{ post.id }}"> | |
11 | {% endif %} |
|
11 | {% endif %} | |
12 |
|
12 | |||
13 | {% if post.image %} |
|
13 | {% if post.image %} | |
14 | <div class="image"> |
|
14 | <div class="image"> | |
15 | <a |
|
15 | <a | |
16 | class="thumb" |
|
16 | class="thumb" | |
17 | href="{{ post.image.url }}"><img |
|
17 | href="{{ post.image.url }}"><img | |
18 | src="{{ post.image.url_200x150 }}" |
|
18 | src="{{ post.image.url_200x150 }}" | |
19 | alt="{{ post.id }}" |
|
19 | alt="{{ post.id }}" | |
20 | width="{{ post.image_pre_width }}" |
|
20 | width="{{ post.image_pre_width }}" | |
21 | height="{{ post.image_pre_height }}" |
|
21 | height="{{ post.image_pre_height }}" | |
22 | data-width="{{ post.image_width }}" |
|
22 | data-width="{{ post.image_width }}" | |
23 | data-height="{{ post.image_height }}"/> |
|
23 | data-height="{{ post.image_height }}"/> | |
24 | </a> |
|
24 | </a> | |
25 | </div> |
|
25 | </div> | |
26 | {% endif %} |
|
26 | {% endif %} | |
27 | <div class="message"> |
|
27 | <div class="message"> | |
28 | <div class="post-info"> |
|
28 | <div class="post-info"> | |
29 | <span class="title">{{ post.title }}</span> |
|
29 | <span class="title">{{ post.title }}</span> | |
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;">>></a>] |
|
34 | [<a href="#" onclick="javascript:addQuickReply('{{ post.id }}') | |
|
35 | ; return false;">>></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 |
|
|
44 | [<a href="{% url 'delete' post_id=post.id %}" | |
39 | >{% trans 'Delete' %}</a>] |
|
45 | >{% trans 'Delete' %}</a>] | |
40 |
|
|
46 | ({{ post.poster_ip }}) | |
41 |
|
|
47 | [<a href="{% url 'ban' post_id=post.id %}?next={{ request.path }}" | |
42 | >{% trans 'Ban IP' %}</a>] |
|
48 | >{% trans 'Ban IP' %}</a>] | |
43 |
|
|
49 | </span> | |
44 | {% endif %} |
|
50 | {% endif %} | |
45 | </div> |
|
51 | </div> | |
46 | {% autoescape off %} |
|
52 | {% autoescape off %} | |
47 | {% if truncated %} |
|
53 | {% if truncated %} | |
48 | {{ post.text.rendered|truncatewords_html:50 }} |
|
54 | {{ post.text.rendered|truncatewords_html:50 }} | |
49 | {% else %} |
|
55 | {% else %} | |
50 | {{ post.text.rendered }} |
|
56 | {{ post.text.rendered }} | |
51 | {% endif %} |
|
57 | {% endif %} | |
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 %}">>>{{ ref_post.id }}</a |
|
63 | <a href="{% post_url ref_post.id %}">>>{{ 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> | |
63 | {% if post.is_opening and post.thread_new.tags.exists %} |
|
69 | {% if post.is_opening and post.thread_new.tags.exists %} | |
64 | <div class="metadata"> |
|
70 | <div class="metadata"> | |
65 | <span class="tags"> |
|
71 | <span class="tags"> | |
66 | {% for tag in post.thread_new.get_tags %} |
|
72 | {% for tag in post.thread_new.get_tags %} | |
67 | <a class="tag" href="{% url 'tag' tag.name %}"> |
|
73 | <a class="tag" href="{% url 'tag' tag.name %}"> | |
68 | #{{ tag.name }}</a>{% if not forloop.last %},{% endif %} |
|
74 | #{{ tag.name }}</a>{% if not forloop.last %},{% endif %} | |
69 | {% endfor %} |
|
75 | {% endfor %} | |
70 | </span> |
|
76 | </span> | |
71 | </div> |
|
77 | </div> | |
72 | {% endif %} |
|
78 | {% endif %} | |
73 | </div> |
|
79 | </div> | |
74 | {% endspaceless %} |
|
80 | {% endspaceless %} |
@@ -1,254 +1,149 b'' | |||||
1 | {% extends "boards/base.html" %} |
|
1 | {% extends "boards/base.html" %} | |
2 |
|
2 | |||
3 | {% load i18n %} |
|
3 | {% load i18n %} | |
4 | {% load cache %} |
|
4 | {% load cache %} | |
5 | {% load board %} |
|
5 | {% load board %} | |
6 | {% load static %} |
|
6 | {% load static %} | |
7 |
|
7 | |||
8 | {% block head %} |
|
8 | {% block head %} | |
9 | {% if tag %} |
|
9 | {% if tag %} | |
10 | <title>Neboard - {{ tag.name }}</title> |
|
10 | <title>Neboard - {{ tag.name }}</title> | |
11 | {% else %} |
|
11 | {% else %} | |
12 | <title>Neboard</title> |
|
12 | <title>Neboard</title> | |
13 | {% endif %} |
|
13 | {% endif %} | |
14 |
|
14 | |||
15 | {% if current_page.has_previous %} |
|
15 | {% if current_page.has_previous %} | |
16 | <link rel="prev" href=" |
|
16 | <link rel="prev" href=" | |
17 | {% if tag %} |
|
17 | {% if tag %} | |
18 | {% url "tag" tag_name=tag page=current_page.previous_page_number %} |
|
18 | {% url "tag" tag_name=tag page=current_page.previous_page_number %} | |
19 | {% else %} |
|
19 | {% else %} | |
20 | {% url "index" page=current_page.previous_page_number %} |
|
20 | {% url "index" page=current_page.previous_page_number %} | |
21 | {% endif %} |
|
21 | {% endif %} | |
22 | " /> |
|
22 | " /> | |
23 | {% endif %} |
|
23 | {% endif %} | |
24 | {% if current_page.has_next %} |
|
24 | {% if current_page.has_next %} | |
25 | <link rel="next" href=" |
|
25 | <link rel="next" href=" | |
26 | {% if tag %} |
|
26 | {% if tag %} | |
27 | {% url "tag" tag_name=tag page=current_page.next_page_number %} |
|
27 | {% url "tag" tag_name=tag page=current_page.next_page_number %} | |
28 | {% else %} |
|
28 | {% else %} | |
29 | {% url "index" page=current_page.next_page_number %} |
|
29 | {% url "index" page=current_page.next_page_number %} | |
30 | {% endif %} |
|
30 | {% endif %} | |
31 | " /> |
|
31 | " /> | |
32 | {% endif %} |
|
32 | {% endif %} | |
33 |
|
33 | |||
34 | {% endblock %} |
|
34 | {% endblock %} | |
35 |
|
35 | |||
36 | {% block content %} |
|
36 | {% block content %} | |
37 |
|
37 | |||
38 | {% get_current_language as LANGUAGE_CODE %} |
|
38 | {% get_current_language as LANGUAGE_CODE %} | |
39 |
|
39 | |||
40 | {% if tag %} |
|
40 | {% if tag %} | |
41 | <div class="tag_info"> |
|
41 | <div class="tag_info"> | |
42 | <h2> |
|
42 | <h2> | |
43 | {% if tag in user.fav_tags.all %} |
|
43 | {% if tag in user.fav_tags.all %} | |
44 | <a href="{% url 'tag_unsubscribe' tag.name %}?next={{ request.path }}" |
|
44 | <a href="{% url 'tag_unsubscribe' tag.name %}?next={{ request.path }}" | |
45 | class="fav">β </a> |
|
45 | class="fav">β </a> | |
46 | {% else %} |
|
46 | {% else %} | |
47 | <a href="{% url 'tag_subscribe' tag.name %}?next={{ request.path }}" |
|
47 | <a href="{% url 'tag_subscribe' tag.name %}?next={{ request.path }}" | |
48 | class="not_fav">β </a> |
|
48 | class="not_fav">β </a> | |
49 | {% endif %} |
|
49 | {% endif %} | |
50 | #{{ tag.name }} |
|
50 | #{{ tag.name }} | |
51 | </h2> |
|
51 | </h2> | |
52 | </div> |
|
52 | </div> | |
53 | {% endif %} |
|
53 | {% endif %} | |
54 |
|
54 | |||
55 | {% if threads %} |
|
55 | {% if threads %} | |
56 | {% if current_page.has_previous %} |
|
56 | {% if current_page.has_previous %} | |
57 | <div class="page_link"> |
|
57 | <div class="page_link"> | |
58 | <a href=" |
|
58 | <a href=" | |
59 | {% if tag %} |
|
59 | {% if tag %} | |
60 | {% url "tag" tag_name=tag page=current_page.previous_page_number %} |
|
60 | {% url "tag" tag_name=tag page=current_page.previous_page_number %} | |
61 | {% else %} |
|
61 | {% else %} | |
62 | {% url "index" page=current_page.previous_page_number %} |
|
62 | {% url "index" page=current_page.previous_page_number %} | |
63 | {% endif %} |
|
63 | {% endif %} | |
64 | ">{% trans "Previous page" %}</a> |
|
64 | ">{% trans "Previous page" %}</a> | |
65 | </div> |
|
65 | </div> | |
66 | {% endif %} |
|
66 | {% endif %} | |
67 |
|
67 | |||
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 |
|
|
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 %}">>>{{ 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"> | |
141 | <a href="{% url 'thread' thread.op.id %}"> |
|
75 | <a href="{% url 'thread' thread.op.id %}"> | |
142 | {% blocktrans with count=thread.skipped_replies %}Skipped {{ count }} replies. Open thread to see all replies.{% endblocktrans %} |
|
76 | {% blocktrans with count=thread.skipped_replies %}Skipped {{ count }} replies. Open thread to see all replies.{% endblocktrans %} | |
143 | </a> |
|
77 | </a> | |
144 | </div> |
|
78 | </div> | |
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 |
{% |
|
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 %}">>>{{ 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 %} | |
191 | </div> |
|
86 | </div> | |
192 | {% endcache %} |
|
87 | {% endcache %} | |
193 | {% endfor %} |
|
88 | {% endfor %} | |
194 |
|
89 | |||
195 | {% if current_page.has_next %} |
|
90 | {% if current_page.has_next %} | |
196 | <div class="page_link"> |
|
91 | <div class="page_link"> | |
197 | <a href=" |
|
92 | <a href=" | |
198 | {% if tag %} |
|
93 | {% if tag %} | |
199 | {% url "tag" tag_name=tag page=current_page.next_page_number %} |
|
94 | {% url "tag" tag_name=tag page=current_page.next_page_number %} | |
200 | {% else %} |
|
95 | {% else %} | |
201 | {% url "index" page=current_page.next_page_number %} |
|
96 | {% url "index" page=current_page.next_page_number %} | |
202 | {% endif %} |
|
97 | {% endif %} | |
203 | ">{% trans "Next page" %}</a> |
|
98 | ">{% trans "Next page" %}</a> | |
204 | </div> |
|
99 | </div> | |
205 | {% endif %} |
|
100 | {% endif %} | |
206 | {% else %} |
|
101 | {% else %} | |
207 | <div class="post"> |
|
102 | <div class="post"> | |
208 | {% trans 'No threads exist. Create the first one!' %}</div> |
|
103 | {% trans 'No threads exist. Create the first one!' %}</div> | |
209 | {% endif %} |
|
104 | {% endif %} | |
210 |
|
105 | |||
211 | <div class="post-form-w"> |
|
106 | <div class="post-form-w"> | |
212 | <script src="{% static 'js/panel.js' %}"></script> |
|
107 | <script src="{% static 'js/panel.js' %}"></script> | |
213 | <div class="post-form"> |
|
108 | <div class="post-form"> | |
214 | <div class="form-title">{% trans "Create new thread" %}</div> |
|
109 | <div class="form-title">{% trans "Create new thread" %}</div> | |
215 | <form enctype="multipart/form-data" method="post">{% csrf_token %} |
|
110 | <form enctype="multipart/form-data" method="post">{% csrf_token %} | |
216 | {{ form.as_div }} |
|
111 | {{ form.as_div }} | |
217 | <div class="form-submit"> |
|
112 | <div class="form-submit"> | |
218 | <input type="submit" value="{% trans "Post" %}"/> |
|
113 | <input type="submit" value="{% trans "Post" %}"/> | |
219 | </div> |
|
114 | </div> | |
220 | </form> |
|
115 | </form> | |
221 | <div> |
|
116 | <div> | |
222 | {% trans 'Tags must be delimited by spaces. Text or image is required.' %} |
|
117 | {% trans 'Tags must be delimited by spaces. Text or image is required.' %} | |
223 | </div> |
|
118 | </div> | |
224 | <div><a href="{% url "staticpage" name="help" %}"> |
|
119 | <div><a href="{% url "staticpage" name="help" %}"> | |
225 | {% trans 'Text syntax' %}</a></div> |
|
120 | {% trans 'Text syntax' %}</a></div> | |
226 | </div> |
|
121 | </div> | |
227 | </div> |
|
122 | </div> | |
228 |
|
123 | |||
229 | {% endblock %} |
|
124 | {% endblock %} | |
230 |
|
125 | |||
231 | {% block metapanel %} |
|
126 | {% block metapanel %} | |
232 |
|
127 | |||
233 | <span class="metapanel"> |
|
128 | <span class="metapanel"> | |
234 | <b><a href="{% url "authors" %}">Neboard</a> 1.6 Amon</b> |
|
129 | <b><a href="{% url "authors" %}">Neboard</a> 1.6 Amon</b> | |
235 | {% trans "Pages:" %}[ |
|
130 | {% trans "Pages:" %}[ | |
236 | {% for page in paginator.page_range %} |
|
131 | {% for page in paginator.page_range %} | |
237 | <a |
|
132 | <a | |
238 | {% ifequal page current_page.number %} |
|
133 | {% ifequal page current_page.number %} | |
239 | class="current_page" |
|
134 | class="current_page" | |
240 | {% endifequal %} |
|
135 | {% endifequal %} | |
241 | href=" |
|
136 | href=" | |
242 | {% if tag %} |
|
137 | {% if tag %} | |
243 | {% url "tag" tag_name=tag page=page %} |
|
138 | {% url "tag" tag_name=tag page=page %} | |
244 | {% else %} |
|
139 | {% else %} | |
245 | {% url "index" page=page %} |
|
140 | {% url "index" page=page %} | |
246 | {% endif %} |
|
141 | {% endif %} | |
247 | ">{{ page }}</a> |
|
142 | ">{{ page }}</a> | |
248 | {% if not forloop.last %},{% endif %} |
|
143 | {% if not forloop.last %},{% endif %} | |
249 | {% endfor %} |
|
144 | {% endfor %} | |
250 | ] |
|
145 | ] | |
251 | [<a href="rss/">RSS</a>] |
|
146 | [<a href="rss/">RSS</a>] | |
252 | </span> |
|
147 | </span> | |
253 |
|
148 | |||
254 | {% endblock %} |
|
149 | {% endblock %} |
@@ -1,145 +1,79 b'' | |||||
1 | {% extends "boards/base.html" %} |
|
1 | {% extends "boards/base.html" %} | |
2 |
|
2 | |||
3 | {% load i18n %} |
|
3 | {% load i18n %} | |
4 | {% load cache %} |
|
4 | {% load cache %} | |
5 | {% load static from staticfiles %} |
|
5 | {% load static from staticfiles %} | |
6 | {% load board %} |
|
6 | {% load board %} | |
7 |
|
7 | |||
8 | {% block head %} |
|
8 | {% block head %} | |
9 | <title>{{ thread.get_opening_post.get_title|striptags|truncatewords:10 }} - Neboard</title> |
|
9 | <title>{{ thread.get_opening_post.get_title|striptags|truncatewords:10 }} - Neboard</title> | |
10 | {% endblock %} |
|
10 | {% endblock %} | |
11 |
|
11 | |||
12 | {% block content %} |
|
12 | {% block content %} | |
13 | {% spaceless %} |
|
13 | {% spaceless %} | |
14 | {% get_current_language as LANGUAGE_CODE %} |
|
14 | {% get_current_language as LANGUAGE_CODE %} | |
15 |
|
15 | |||
16 | {% cache 600 thread_view thread.id thread.last_edit_time moderator LANGUAGE_CODE %} |
|
16 | {% cache 600 thread_view thread.id thread.last_edit_time moderator LANGUAGE_CODE %} | |
17 |
|
17 | |||
18 | <div class="image-mode-tab"> |
|
18 | <div class="image-mode-tab"> | |
19 | <a class="current_mode" href="{% url 'thread' thread.get_opening_post.id %}">{% trans 'Normal mode' %}</a>, |
|
19 | <a class="current_mode" href="{% url 'thread' thread.get_opening_post.id %}">{% trans 'Normal mode' %}</a>, | |
20 | <a href="{% url 'thread_mode' thread.get_opening_post.id 'gallery' %}">{% trans 'Gallery mode' %}</a> |
|
20 | <a href="{% url 'thread_mode' thread.get_opening_post.id 'gallery' %}">{% trans 'Gallery mode' %}</a> | |
21 | </div> |
|
21 | </div> | |
22 |
|
22 | |||
23 | {% if bumpable %} |
|
23 | {% if bumpable %} | |
24 | <div class="bar-bg"> |
|
24 | <div class="bar-bg"> | |
25 | <div class="bar-value" style="width:{{ bumplimit_progress }}%" id="bumplimit_progress"> |
|
25 | <div class="bar-value" style="width:{{ bumplimit_progress }}%" id="bumplimit_progress"> | |
26 | </div> |
|
26 | </div> | |
27 | <div class="bar-text"> |
|
27 | <div class="bar-text"> | |
28 | <span id="left_to_limit">{{ posts_left }}</span> {% trans 'posts to bumplimit' %} |
|
28 | <span id="left_to_limit">{{ posts_left }}</span> {% trans 'posts to bumplimit' %} | |
29 | </div> |
|
29 | </div> | |
30 | </div> |
|
30 | </div> | |
31 | {% endif %} |
|
31 | {% endif %} | |
32 | <div class="thread"> |
|
32 | <div class="thread"> | |
33 | {% for post in posts %} |
|
33 | {% for post in posts %} | |
34 |
{% |
|
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;">>></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 %}">>>{{ 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 %} | |
104 |
|
38 | |||
105 | {% if not thread.archived %} |
|
39 | {% if not thread.archived %} | |
106 |
|
40 | |||
107 | <div class="post-form-w"> |
|
41 | <div class="post-form-w"> | |
108 | <script src="{% static 'js/panel.js' %}"></script> |
|
42 | <script src="{% static 'js/panel.js' %}"></script> | |
109 | <div class="form-title">{% trans "Reply to thread" %} #{{ thread.get_opening_post.id }}</div> |
|
43 | <div class="form-title">{% trans "Reply to thread" %} #{{ thread.get_opening_post.id }}</div> | |
110 | <div class="post-form"> |
|
44 | <div class="post-form"> | |
111 | <form id="form" enctype="multipart/form-data" method="post" |
|
45 | <form id="form" enctype="multipart/form-data" method="post" | |
112 | >{% csrf_token %} |
|
46 | >{% csrf_token %} | |
113 | {{ form.as_div }} |
|
47 | {{ form.as_div }} | |
114 | <div class="form-submit"> |
|
48 | <div class="form-submit"> | |
115 | <input type="submit" value="{% trans "Post" %}"/> |
|
49 | <input type="submit" value="{% trans "Post" %}"/> | |
116 | </div> |
|
50 | </div> | |
117 | </form> |
|
51 | </form> | |
118 | <div><a href="{% url "staticpage" name="help" %}"> |
|
52 | <div><a href="{% url "staticpage" name="help" %}"> | |
119 | {% trans 'Text syntax' %}</a></div> |
|
53 | {% trans 'Text syntax' %}</a></div> | |
120 | </div> |
|
54 | </div> | |
121 | </div> |
|
55 | </div> | |
122 |
|
56 | |||
123 | <script src="{% static 'js/jquery.form.min.js' %}"></script> |
|
57 | <script src="{% static 'js/jquery.form.min.js' %}"></script> | |
124 | <script src="{% static 'js/thread_update.js' %}"></script> |
|
58 | <script src="{% static 'js/thread_update.js' %}"></script> | |
125 | {% endif %} |
|
59 | {% endif %} | |
126 |
|
60 | |||
127 | <script src="{% static 'js/thread.js' %}"></script> |
|
61 | <script src="{% static 'js/thread.js' %}"></script> | |
128 |
|
62 | |||
129 | {% endspaceless %} |
|
63 | {% endspaceless %} | |
130 | {% endblock %} |
|
64 | {% endblock %} | |
131 |
|
65 | |||
132 | {% block metapanel %} |
|
66 | {% block metapanel %} | |
133 |
|
67 | |||
134 | {% get_current_language as LANGUAGE_CODE %} |
|
68 | {% get_current_language as LANGUAGE_CODE %} | |
135 |
|
69 | |||
136 | <span class="metapanel" data-last-update="{{ last_update }}"> |
|
70 | <span class="metapanel" data-last-update="{{ last_update }}"> | |
137 | {% cache 600 thread_meta thread.last_edit_time moderator LANGUAGE_CODE %} |
|
71 | {% cache 600 thread_meta thread.last_edit_time moderator LANGUAGE_CODE %} | |
138 | <span id="reply-count">{{ thread.get_reply_count }}</span> {% trans 'replies' %}, |
|
72 | <span id="reply-count">{{ thread.get_reply_count }}</span> {% trans 'replies' %}, | |
139 | <span id="image-count">{{ thread.get_images_count }}</span> {% trans 'images' %}. |
|
73 | <span id="image-count">{{ thread.get_images_count }}</span> {% trans 'images' %}. | |
140 | {% trans 'Last update: ' %}<span id="last-update">{{ thread.last_edit_time }}</span> |
|
74 | {% trans 'Last update: ' %}<span id="last-update">{{ thread.last_edit_time }}</span> | |
141 | [<a href="rss/">RSS</a>] |
|
75 | [<a href="rss/">RSS</a>] | |
142 | {% endcache %} |
|
76 | {% endcache %} | |
143 | </span> |
|
77 | </span> | |
144 |
|
78 | |||
145 | {% endblock %} |
|
79 | {% endblock %} |
@@ -1,49 +1,71 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() | |
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 | ||||
|
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 |
@@ -1,206 +1,205 b'' | |||||
1 | from datetime import datetime |
|
1 | from datetime import datetime | |
2 | import json |
|
2 | import json | |
3 | from django.db import transaction |
|
3 | from django.db import transaction | |
4 | from django.http import HttpResponse |
|
4 | from django.http import HttpResponse | |
5 | from django.shortcuts import get_object_or_404, render |
|
5 | from django.shortcuts import get_object_or_404, render | |
6 | from django.template import RequestContext |
|
6 | from django.template import RequestContext | |
7 | from django.utils import timezone |
|
7 | from django.utils import timezone | |
8 | from boards.forms import PostForm, PlainErrorList |
|
8 | from boards.forms import PostForm, PlainErrorList | |
9 | from boards.models import Post, Thread, Tag |
|
9 | from boards.models import Post, Thread, Tag | |
10 | from boards.views import _datetime_to_epoch, _new_post, \ |
|
10 | from boards.views import _datetime_to_epoch, _new_post, \ | |
11 | _ban_current_user |
|
11 | _ban_current_user | |
12 |
|
12 | |||
13 | __author__ = 'neko259' |
|
13 | __author__ = 'neko259' | |
14 |
|
14 | |||
15 | PARAMETER_TRUNCATED = 'truncated' |
|
15 | PARAMETER_TRUNCATED = 'truncated' | |
16 | PARAMETER_TAG = 'tag' |
|
16 | PARAMETER_TAG = 'tag' | |
17 | PARAMETER_OFFSET = 'offset' |
|
17 | PARAMETER_OFFSET = 'offset' | |
18 | PARAMETER_DIFF_TYPE = 'type' |
|
18 | PARAMETER_DIFF_TYPE = 'type' | |
19 |
|
19 | |||
20 | DIFF_TYPE_HTML = 'html' |
|
20 | DIFF_TYPE_HTML = 'html' | |
21 | DIFF_TYPE_JSON = 'json' |
|
21 | DIFF_TYPE_JSON = 'json' | |
22 |
|
22 | |||
23 | STATUS_OK = 'ok' |
|
23 | STATUS_OK = 'ok' | |
24 | STATUS_ERROR = 'error' |
|
24 | STATUS_ERROR = 'error' | |
25 |
|
25 | |||
26 |
|
26 | |||
27 | @transaction.atomic |
|
27 | @transaction.atomic | |
28 | def api_get_threaddiff(request, thread_id, last_update_time): |
|
28 | def api_get_threaddiff(request, thread_id, last_update_time): | |
29 | """Get posts that were changed or added since time""" |
|
29 | """Get posts that were changed or added since time""" | |
30 |
|
30 | |||
31 | thread = get_object_or_404(Post, id=thread_id).thread_new |
|
31 | thread = get_object_or_404(Post, id=thread_id).thread_new | |
32 |
|
32 | |||
33 | filter_time = datetime.fromtimestamp(float(last_update_time) / 1000000, |
|
33 | filter_time = datetime.fromtimestamp(float(last_update_time) / 1000000, | |
34 | timezone.get_current_timezone()) |
|
34 | timezone.get_current_timezone()) | |
35 |
|
35 | |||
36 | json_data = { |
|
36 | json_data = { | |
37 | 'added': [], |
|
37 | 'added': [], | |
38 | 'updated': [], |
|
38 | 'updated': [], | |
39 | 'last_update': None, |
|
39 | 'last_update': None, | |
40 | } |
|
40 | } | |
41 | added_posts = Post.objects.filter(thread_new=thread, |
|
41 | added_posts = Post.objects.filter(thread_new=thread, | |
42 | pub_time__gt=filter_time) \ |
|
42 | pub_time__gt=filter_time) \ | |
43 | .order_by('pub_time') |
|
43 | .order_by('pub_time') | |
44 | updated_posts = Post.objects.filter(thread_new=thread, |
|
44 | updated_posts = Post.objects.filter(thread_new=thread, | |
45 | pub_time__lte=filter_time, |
|
45 | pub_time__lte=filter_time, | |
46 | last_edit_time__gt=filter_time) |
|
46 | last_edit_time__gt=filter_time) | |
47 |
|
47 | |||
48 | diff_type = DIFF_TYPE_HTML |
|
48 | diff_type = DIFF_TYPE_HTML | |
49 | if PARAMETER_DIFF_TYPE in request.GET: |
|
49 | if PARAMETER_DIFF_TYPE in request.GET: | |
50 | diff_type = request.GET[PARAMETER_DIFF_TYPE] |
|
50 | diff_type = request.GET[PARAMETER_DIFF_TYPE] | |
51 |
|
51 | |||
52 | for post in added_posts: |
|
52 | for post in added_posts: | |
53 | json_data['added'].append(_get_post_data(post.id, diff_type, request)) |
|
53 | json_data['added'].append(_get_post_data(post.id, diff_type, request)) | |
54 | for post in updated_posts: |
|
54 | for post in updated_posts: | |
55 | json_data['updated'].append(_get_post_data(post.id, diff_type, request)) |
|
55 | json_data['updated'].append(_get_post_data(post.id, diff_type, request)) | |
56 | json_data['last_update'] = _datetime_to_epoch(thread.last_edit_time) |
|
56 | json_data['last_update'] = _datetime_to_epoch(thread.last_edit_time) | |
57 |
|
57 | |||
58 | return HttpResponse(content=json.dumps(json_data)) |
|
58 | return HttpResponse(content=json.dumps(json_data)) | |
59 |
|
59 | |||
60 |
|
60 | |||
61 | def api_add_post(request, opening_post_id): |
|
61 | def api_add_post(request, opening_post_id): | |
62 | """ |
|
62 | """ | |
63 | Add a post and return the JSON response for it |
|
63 | Add a post and return the JSON response for it | |
64 | """ |
|
64 | """ | |
65 |
|
65 | |||
66 | opening_post = get_object_or_404(Post, id=opening_post_id) |
|
66 | opening_post = get_object_or_404(Post, id=opening_post_id) | |
67 |
|
67 | |||
68 | status = STATUS_OK |
|
68 | status = STATUS_OK | |
69 | errors = [] |
|
69 | errors = [] | |
70 |
|
70 | |||
71 | if request.method == 'POST': |
|
71 | if request.method == 'POST': | |
72 | form = PostForm(request.POST, request.FILES, |
|
72 | form = PostForm(request.POST, request.FILES, | |
73 | error_class=PlainErrorList) |
|
73 | error_class=PlainErrorList) | |
74 | form.session = request.session |
|
74 | form.session = request.session | |
75 |
|
75 | |||
76 | #if form.need_to_ban: |
|
76 | #if form.need_to_ban: | |
77 | # # Ban user because he is suspected to be a bot |
|
77 | # # Ban user because he is suspected to be a bot | |
78 | # _ban_current_user(request) |
|
78 | # _ban_current_user(request) | |
79 | # status = STATUS_ERROR |
|
79 | # status = STATUS_ERROR | |
80 | if form.is_valid(): |
|
80 | if form.is_valid(): | |
81 | _new_post(request, form, opening_post, html_response=False) |
|
81 | _new_post(request, form, opening_post, html_response=False) | |
82 | else: |
|
82 | else: | |
83 | status = STATUS_ERROR |
|
83 | status = STATUS_ERROR | |
84 | errors = form.as_json_errors() |
|
84 | errors = form.as_json_errors() | |
85 |
|
85 | |||
86 | response = { |
|
86 | response = { | |
87 | 'status': status, |
|
87 | 'status': status, | |
88 | 'errors': errors, |
|
88 | 'errors': errors, | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | return HttpResponse(content=json.dumps(response)) |
|
91 | return HttpResponse(content=json.dumps(response)) | |
92 |
|
92 | |||
93 |
|
93 | |||
94 | def get_post(request, post_id): |
|
94 | def get_post(request, post_id): | |
95 | """ |
|
95 | """ | |
96 | Get the html of a post. Used for popups. Post can be truncated if used |
|
96 | Get the html of a post. Used for popups. Post can be truncated if used | |
97 | in threads list with 'truncated' get parameter. |
|
97 | in threads list with 'truncated' get parameter. | |
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 | |
105 | if PARAMETER_TRUNCATED in request.GET: |
|
104 | if PARAMETER_TRUNCATED in request.GET: | |
106 | context[PARAMETER_TRUNCATED] = True |
|
105 | context[PARAMETER_TRUNCATED] = True | |
107 |
|
106 | |||
108 | return render(request, 'boards/post.html', context) |
|
107 | return render(request, 'boards/post.html', context) | |
109 |
|
108 | |||
110 |
|
109 | |||
111 | # TODO Test this |
|
110 | # TODO Test this | |
112 | def api_get_threads(request, count): |
|
111 | def api_get_threads(request, count): | |
113 | """ |
|
112 | """ | |
114 | Get the JSON thread opening posts list. |
|
113 | Get the JSON thread opening posts list. | |
115 | Parameters that can be used for filtering: |
|
114 | Parameters that can be used for filtering: | |
116 | tag, offset (from which thread to get results) |
|
115 | tag, offset (from which thread to get results) | |
117 | """ |
|
116 | """ | |
118 |
|
117 | |||
119 | if PARAMETER_TAG in request.GET: |
|
118 | if PARAMETER_TAG in request.GET: | |
120 | tag_name = request.GET[PARAMETER_TAG] |
|
119 | tag_name = request.GET[PARAMETER_TAG] | |
121 | if tag_name is not None: |
|
120 | if tag_name is not None: | |
122 | tag = get_object_or_404(Tag, name=tag_name) |
|
121 | tag = get_object_or_404(Tag, name=tag_name) | |
123 | threads = tag.threads.filter(archived=False) |
|
122 | threads = tag.threads.filter(archived=False) | |
124 | else: |
|
123 | else: | |
125 | threads = Thread.objects.filter(archived=False) |
|
124 | threads = Thread.objects.filter(archived=False) | |
126 |
|
125 | |||
127 | if PARAMETER_OFFSET in request.GET: |
|
126 | if PARAMETER_OFFSET in request.GET: | |
128 | offset = request.GET[PARAMETER_OFFSET] |
|
127 | offset = request.GET[PARAMETER_OFFSET] | |
129 | offset = int(offset) if offset is not None else 0 |
|
128 | offset = int(offset) if offset is not None else 0 | |
130 | else: |
|
129 | else: | |
131 | offset = 0 |
|
130 | offset = 0 | |
132 |
|
131 | |||
133 | threads = threads.order_by('-bump_time') |
|
132 | threads = threads.order_by('-bump_time') | |
134 | threads = threads[offset:offset + int(count)] |
|
133 | threads = threads[offset:offset + int(count)] | |
135 |
|
134 | |||
136 | opening_posts = [] |
|
135 | opening_posts = [] | |
137 | for thread in threads: |
|
136 | for thread in threads: | |
138 | opening_post = thread.get_opening_post() |
|
137 | opening_post = thread.get_opening_post() | |
139 |
|
138 | |||
140 | # TODO Add tags, replies and images count |
|
139 | # TODO Add tags, replies and images count | |
141 | opening_posts.append(_get_post_data(opening_post.id, |
|
140 | opening_posts.append(_get_post_data(opening_post.id, | |
142 | include_last_update=True)) |
|
141 | include_last_update=True)) | |
143 |
|
142 | |||
144 | return HttpResponse(content=json.dumps(opening_posts)) |
|
143 | return HttpResponse(content=json.dumps(opening_posts)) | |
145 |
|
144 | |||
146 |
|
145 | |||
147 | # TODO Test this |
|
146 | # TODO Test this | |
148 | def api_get_tags(request): |
|
147 | def api_get_tags(request): | |
149 | """ |
|
148 | """ | |
150 | Get all tags or user tags. |
|
149 | Get all tags or user tags. | |
151 | """ |
|
150 | """ | |
152 |
|
151 | |||
153 | # TODO Get favorite tags for the given user ID |
|
152 | # TODO Get favorite tags for the given user ID | |
154 |
|
153 | |||
155 | tags = Tag.objects.get_not_empty_tags() |
|
154 | tags = Tag.objects.get_not_empty_tags() | |
156 | tag_names = [] |
|
155 | tag_names = [] | |
157 | for tag in tags: |
|
156 | for tag in tags: | |
158 | tag_names.append(tag.name) |
|
157 | tag_names.append(tag.name) | |
159 |
|
158 | |||
160 | return HttpResponse(content=json.dumps(tag_names)) |
|
159 | return HttpResponse(content=json.dumps(tag_names)) | |
161 |
|
160 | |||
162 |
|
161 | |||
163 | # TODO The result can be cached by the thread last update time |
|
162 | # TODO The result can be cached by the thread last update time | |
164 | # TODO Test this |
|
163 | # TODO Test this | |
165 | def api_get_thread_posts(request, opening_post_id): |
|
164 | def api_get_thread_posts(request, opening_post_id): | |
166 | """ |
|
165 | """ | |
167 | Get the JSON array of thread posts |
|
166 | Get the JSON array of thread posts | |
168 | """ |
|
167 | """ | |
169 |
|
168 | |||
170 | opening_post = get_object_or_404(Post, id=opening_post_id) |
|
169 | opening_post = get_object_or_404(Post, id=opening_post_id) | |
171 | thread = opening_post.thread_new |
|
170 | thread = opening_post.thread_new | |
172 | posts = thread.get_replies() |
|
171 | posts = thread.get_replies() | |
173 |
|
172 | |||
174 | json_data = { |
|
173 | json_data = { | |
175 | 'posts': [], |
|
174 | 'posts': [], | |
176 | 'last_update': None, |
|
175 | 'last_update': None, | |
177 | } |
|
176 | } | |
178 | json_post_list = [] |
|
177 | json_post_list = [] | |
179 |
|
178 | |||
180 | for post in posts: |
|
179 | for post in posts: | |
181 | json_post_list.append(_get_post_data(post.id)) |
|
180 | json_post_list.append(_get_post_data(post.id)) | |
182 | json_data['last_update'] = _datetime_to_epoch(thread.last_edit_time) |
|
181 | json_data['last_update'] = _datetime_to_epoch(thread.last_edit_time) | |
183 | json_data['posts'] = json_post_list |
|
182 | json_data['posts'] = json_post_list | |
184 |
|
183 | |||
185 | return HttpResponse(content=json.dumps(json_data)) |
|
184 | return HttpResponse(content=json.dumps(json_data)) | |
186 |
|
185 | |||
187 |
|
186 | |||
188 | # TODO Add pub time and replies |
|
187 | # TODO Add pub time and replies | |
189 | def _get_post_data(post_id, format_type=DIFF_TYPE_JSON, request=None, |
|
188 | def _get_post_data(post_id, format_type=DIFF_TYPE_JSON, request=None, | |
190 | include_last_update=False): |
|
189 | include_last_update=False): | |
191 | if format_type == DIFF_TYPE_HTML: |
|
190 | if format_type == DIFF_TYPE_HTML: | |
192 | return get_post(request, post_id).content.strip() |
|
191 | return get_post(request, post_id).content.strip() | |
193 | elif format_type == DIFF_TYPE_JSON: |
|
192 | elif format_type == DIFF_TYPE_JSON: | |
194 | post = get_object_or_404(Post, id=post_id) |
|
193 | post = get_object_or_404(Post, id=post_id) | |
195 | post_json = { |
|
194 | post_json = { | |
196 | 'id': post.id, |
|
195 | 'id': post.id, | |
197 | 'title': post.title, |
|
196 | 'title': post.title, | |
198 | 'text': post.text.rendered, |
|
197 | 'text': post.text.rendered, | |
199 | } |
|
198 | } | |
200 | if post.image: |
|
199 | if post.image: | |
201 | post_json['image'] = post.image.url |
|
200 | post_json['image'] = post.image.url | |
202 | post_json['image_preview'] = post.image.url_200x150 |
|
201 | post_json['image_preview'] = post.image.url_200x150 | |
203 | if include_last_update: |
|
202 | if include_last_update: | |
204 | post_json['bump_time'] = _datetime_to_epoch( |
|
203 | post_json['bump_time'] = _datetime_to_epoch( | |
205 | post.thread_new.bump_time) |
|
204 | post.thread_new.bump_time) | |
206 | return post_json |
|
205 | return post_json |
General Comments 0
You need to be logged in to leave comments.
Login now