diff --git a/boards/urls.py b/boards/urls.py --- a/boards/urls.py +++ b/boards/urls.py @@ -30,7 +30,6 @@ urlpatterns = patterns('', # /boards/thread/ url(r'^thread/(?P\w+)/$', views.thread, name='thread'), - # /boards/theme/theme_name/ url(r'^settings/$', views.settings, name='settings'), url(r'^tags/$', views.all_tags, name='tags'), url(r'^captcha/', include('captcha.urls')), @@ -49,5 +48,9 @@ urlpatterns = patterns('', url(r'^tag/(?P\w+)/page/(?P\w+)/rss/$', TagThreadsFeed()), url(r'^thread/(?P\w+)/rss/$', ThreadPostsFeed()), + # i18n url(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict), + + # API + url(r'^get_post/(?P\w+)/$', views.get_post, name="get_post"), ) diff --git a/boards/views.py b/boards/views.py --- a/boards/views.py +++ b/boards/views.py @@ -1,7 +1,9 @@ import hashlib import string +from django.core import serializers from django.core.urlresolvers import reverse from django.http import HttpResponseRedirect +from django.http.response import HttpResponse from django.template import RequestContext from django.shortcuts import render, redirect, get_object_or_404 from django.utils import timezone @@ -244,6 +246,8 @@ def jump_to_post(request, post_id): def authors(request): + """Show authors list""" + context = _init_default_context(request) context['authors'] = boards.authors.authors @@ -251,6 +255,8 @@ def authors(request): def delete(request, post_id): + """Delete post""" + user = _get_user(request) post = get_object_or_404(Post, id=post_id) @@ -265,6 +271,8 @@ def delete(request, post_id): def ban(request, post_id): + """Ban user""" + user = _get_user(request) post = get_object_or_404(Post, id=post_id) @@ -276,16 +284,22 @@ def ban(request, post_id): def you_are_banned(request): + """Show the page that notifies that user is banned""" + context = _init_default_context(request) return render(request, 'boards/staticpages/banned.html', context) def page_404(request): + """Show page 404 (not found error)""" + context = _init_default_context(request) return render(request, 'boards/404.html', context) def tag_subscribe(request, tag_name): + """Add tag to favorites""" + user = _get_user(request) tag = get_object_or_404(Tag, name=tag_name) @@ -296,6 +310,8 @@ def tag_subscribe(request, tag_name): def tag_unsubscribe(request, tag_name): + """Remove tag from favorites""" + user = _get_user(request) tag = get_object_or_404(Tag, name=tag_name) @@ -306,10 +322,29 @@ def tag_unsubscribe(request, tag_name): def static_page(request, name): + """Show a static page that needs only tags list and a CSS""" + context = _init_default_context(request) return render(request, 'boards/staticpages/' + name + '.html', context) +def get_post(request, post_id): + """ + Get the JSON of a post. + This is used for replies preview and new posts loading. Also this can be + used as and API for external clients. + """ + + post = get_object_or_404(Post, id=post_id) + + json = serializers.serialize("json", [post], fields=( + "pub_time", "_text_rendered", "title", "text", "image", + "image_width", "image_height", "replies", "tags" + )) + + return HttpResponse(content=json) + + def _get_theme(request, user=None): """Get user's CSS theme"""