Show More
@@ -63,5 +63,7 urlpatterns = patterns('', | |||
|
63 | 63 | url(r'^api/threads/(?P<count>\w+)/$', api.api_get_threads, |
|
64 | 64 | name='get_threads'), |
|
65 | 65 | url(r'api/tags/$', api.api_get_tags, name='get_tags'), |
|
66 | url(r'api/thread/(?P<opening_post_id>\w+)/$', api.api_get_thread_posts, | |
|
67 | name='get_thread'), | |
|
66 | 68 | |
|
67 | 69 | ) |
@@ -98,6 +98,7 def get_post(request, post_id): | |||
|
98 | 98 | return render(request, 'boards/post.html', context) |
|
99 | 99 | |
|
100 | 100 | |
|
101 | # TODO Test this | |
|
101 | 102 | def api_get_threads(request, count): |
|
102 | 103 | """ |
|
103 | 104 | Get the JSON thread opening posts list. |
@@ -142,6 +143,7 def api_get_threads(request, count): | |||
|
142 | 143 | return HttpResponse(content=json.dumps(opening_posts)) |
|
143 | 144 | |
|
144 | 145 | |
|
146 | # TODO Test this | |
|
145 | 147 | def api_get_tags(request): |
|
146 | 148 | """ |
|
147 | 149 | Get all tags or user tags. |
@@ -155,3 +157,33 def api_get_tags(request): | |||
|
155 | 157 | tag_names.append(tag.name) |
|
156 | 158 | |
|
157 | 159 | return HttpResponse(content=json.dumps(tag_names)) |
|
160 | ||
|
161 | ||
|
162 | # TODO The result can be cached by the thread last update time | |
|
163 | # TODO Test this | |
|
164 | def api_get_thread_posts(request, opening_post_id): | |
|
165 | """ | |
|
166 | Get the JSON array of thread posts | |
|
167 | """ | |
|
168 | ||
|
169 | opening_post = get_object_or_404(Post, id=opening_post_id) | |
|
170 | thread = opening_post.thread_new | |
|
171 | posts = thread.get_replies() | |
|
172 | ||
|
173 | json_post_list = [] | |
|
174 | ||
|
175 | for post in posts: | |
|
176 | # TODO Add pub time and replies | |
|
177 | post_json = { | |
|
178 | 'id' : post.id, | |
|
179 | 'title' : post.title, | |
|
180 | 'text' : post.text.rendered, | |
|
181 | } | |
|
182 | if post.image: | |
|
183 | post_json += { | |
|
184 | 'image' : post.image.url, | |
|
185 | 'image_preview' : post.image.url_200x150, | |
|
186 | } | |
|
187 | json_post_list.append(post_json) | |
|
188 | ||
|
189 | return HttpResponse(content=json.dumps(json_post_list)) |
General Comments 0
You need to be logged in to leave comments.
Login now