Show More
@@ -30,7 +30,6 b" urlpatterns = patterns(''," | |||
|
30 | 30 | |
|
31 | 31 | # /boards/thread/ |
|
32 | 32 | url(r'^thread/(?P<post_id>\w+)/$', views.thread, name='thread'), |
|
33 | # /boards/theme/theme_name/ | |
|
34 | 33 | url(r'^settings/$', views.settings, name='settings'), |
|
35 | 34 | url(r'^tags/$', views.all_tags, name='tags'), |
|
36 | 35 | url(r'^captcha/', include('captcha.urls')), |
@@ -49,5 +48,9 b" urlpatterns = patterns(''," | |||
|
49 | 48 | url(r'^tag/(?P<tag_name>\w+)/page/(?P<page>\w+)/rss/$', TagThreadsFeed()), |
|
50 | 49 | url(r'^thread/(?P<post_id>\w+)/rss/$', ThreadPostsFeed()), |
|
51 | 50 | |
|
51 | # i18n | |
|
52 | 52 | url(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict), |
|
53 | ||
|
54 | # API | |
|
55 | url(r'^get_post/(?P<post_id>\w+)/$', views.get_post, name="get_post"), | |
|
53 | 56 | ) |
@@ -1,7 +1,9 b'' | |||
|
1 | 1 | import hashlib |
|
2 | 2 | import string |
|
3 | from django.core import serializers | |
|
3 | 4 | from django.core.urlresolvers import reverse |
|
4 | 5 | from django.http import HttpResponseRedirect |
|
6 | from django.http.response import HttpResponse | |
|
5 | 7 | from django.template import RequestContext |
|
6 | 8 | from django.shortcuts import render, redirect, get_object_or_404 |
|
7 | 9 | from django.utils import timezone |
@@ -244,6 +246,8 b' def jump_to_post(request, post_id):' | |||
|
244 | 246 | |
|
245 | 247 | |
|
246 | 248 | def authors(request): |
|
249 | """Show authors list""" | |
|
250 | ||
|
247 | 251 | context = _init_default_context(request) |
|
248 | 252 | context['authors'] = boards.authors.authors |
|
249 | 253 | |
@@ -251,6 +255,8 b' def authors(request):' | |||
|
251 | 255 | |
|
252 | 256 | |
|
253 | 257 | def delete(request, post_id): |
|
258 | """Delete post""" | |
|
259 | ||
|
254 | 260 | user = _get_user(request) |
|
255 | 261 | post = get_object_or_404(Post, id=post_id) |
|
256 | 262 | |
@@ -265,6 +271,8 b' def delete(request, post_id):' | |||
|
265 | 271 | |
|
266 | 272 | |
|
267 | 273 | def ban(request, post_id): |
|
274 | """Ban user""" | |
|
275 | ||
|
268 | 276 | user = _get_user(request) |
|
269 | 277 | post = get_object_or_404(Post, id=post_id) |
|
270 | 278 | |
@@ -276,16 +284,22 b' def ban(request, post_id):' | |||
|
276 | 284 | |
|
277 | 285 | |
|
278 | 286 | def you_are_banned(request): |
|
287 | """Show the page that notifies that user is banned""" | |
|
288 | ||
|
279 | 289 | context = _init_default_context(request) |
|
280 | 290 | return render(request, 'boards/staticpages/banned.html', context) |
|
281 | 291 | |
|
282 | 292 | |
|
283 | 293 | def page_404(request): |
|
294 | """Show page 404 (not found error)""" | |
|
295 | ||
|
284 | 296 | context = _init_default_context(request) |
|
285 | 297 | return render(request, 'boards/404.html', context) |
|
286 | 298 | |
|
287 | 299 | |
|
288 | 300 | def tag_subscribe(request, tag_name): |
|
301 | """Add tag to favorites""" | |
|
302 | ||
|
289 | 303 | user = _get_user(request) |
|
290 | 304 | tag = get_object_or_404(Tag, name=tag_name) |
|
291 | 305 | |
@@ -296,6 +310,8 b' def tag_subscribe(request, tag_name):' | |||
|
296 | 310 | |
|
297 | 311 | |
|
298 | 312 | def tag_unsubscribe(request, tag_name): |
|
313 | """Remove tag from favorites""" | |
|
314 | ||
|
299 | 315 | user = _get_user(request) |
|
300 | 316 | tag = get_object_or_404(Tag, name=tag_name) |
|
301 | 317 | |
@@ -306,10 +322,29 b' def tag_unsubscribe(request, tag_name):' | |||
|
306 | 322 | |
|
307 | 323 | |
|
308 | 324 | def static_page(request, name): |
|
325 | """Show a static page that needs only tags list and a CSS""" | |
|
326 | ||
|
309 | 327 | context = _init_default_context(request) |
|
310 | 328 | return render(request, 'boards/staticpages/' + name + '.html', context) |
|
311 | 329 | |
|
312 | 330 | |
|
331 | def get_post(request, post_id): | |
|
332 | """ | |
|
333 | Get the JSON of a post. | |
|
334 | This is used for replies preview and new posts loading. Also this can be | |
|
335 | used as and API for external clients. | |
|
336 | """ | |
|
337 | ||
|
338 | post = get_object_or_404(Post, id=post_id) | |
|
339 | ||
|
340 | json = serializers.serialize("json", [post], fields=( | |
|
341 | "pub_time", "_text_rendered", "title", "text", "image", | |
|
342 | "image_width", "image_height", "replies", "tags" | |
|
343 | )) | |
|
344 | ||
|
345 | return HttpResponse(content=json) | |
|
346 | ||
|
347 | ||
|
313 | 348 | def _get_theme(request, user=None): |
|
314 | 349 | """Get user's CSS theme""" |
|
315 | 350 |
General Comments 0
You need to be logged in to leave comments.
Login now