Show More
@@ -15,6 +15,10 b' from boards.views import _datetime_to_ep' | |||||
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' | |||
|
19 | ||||
|
20 | DIFF_TYPE_HTML = 'html' | |||
|
21 | DIFF_TYPE_JSON = 'json' | |||
18 |
|
22 | |||
19 |
|
23 | |||
20 | @transaction.atomic |
|
24 | @transaction.atomic | |
@@ -37,10 +41,15 b' def api_get_threaddiff(request, thread_i' | |||||
37 | updated_posts = Post.objects.filter(thread_new=thread, |
|
41 | updated_posts = Post.objects.filter(thread_new=thread, | |
38 | pub_time__lte=filter_time, |
|
42 | pub_time__lte=filter_time, | |
39 | last_edit_time__gt=filter_time) |
|
43 | last_edit_time__gt=filter_time) | |
|
44 | ||||
|
45 | diff_type = DIFF_TYPE_HTML | |||
|
46 | if PARAMETER_DIFF_TYPE in request.GET: | |||
|
47 | diff_type = request.GET[PARAMETER_DIFF_TYPE] | |||
|
48 | ||||
40 | for post in added_posts: |
|
49 | for post in added_posts: | |
41 |
json_data['added'].append(get_post( |
|
50 | json_data['added'].append(_get_post_data(post.id, diff_type, request)) | |
42 | for post in updated_posts: |
|
51 | for post in updated_posts: | |
43 |
json_data['updated'].append(get_post( |
|
52 | json_data['updated'].append(_get_post_data(post.id, diff_type, request)) | |
44 | json_data['last_update'] = _datetime_to_epoch(thread.last_edit_time) |
|
53 | json_data['last_update'] = _datetime_to_epoch(thread.last_edit_time) | |
45 |
|
54 | |||
46 | return HttpResponse(content=json.dumps(json_data)) |
|
55 | return HttpResponse(content=json.dumps(json_data)) | |
@@ -127,16 +136,8 b' def api_get_threads(request, count):' | |||||
127 | for thread in threads: |
|
136 | for thread in threads: | |
128 | opening_post = thread.get_opening_post() |
|
137 | opening_post = thread.get_opening_post() | |
129 |
|
138 | |||
130 |
# TODO Add |
|
139 | # TODO Add tags, replies and images count | |
131 | post_json = { |
|
140 | opening_posts.append(_get_post_data(opening_post.id)) | |
132 | 'id': opening_post.id, |
|
|||
133 | 'title': opening_post.title, |
|
|||
134 | 'text': opening_post.text.rendered, |
|
|||
135 | } |
|
|||
136 | if opening_post.image: |
|
|||
137 | post_json['image'] = opening_post.image.url |
|
|||
138 | post_json['image_preview'] = opening_post.image.url_200x150 |
|
|||
139 | opening_posts.append(post_json) |
|
|||
140 |
|
141 | |||
141 | return HttpResponse(content=json.dumps(opening_posts)) |
|
142 | return HttpResponse(content=json.dumps(opening_posts)) | |
142 |
|
143 | |||
@@ -171,7 +172,17 b' def api_get_thread_posts(request, openin' | |||||
171 | json_post_list = [] |
|
172 | json_post_list = [] | |
172 |
|
173 | |||
173 | for post in posts: |
|
174 | for post in posts: | |
174 | # TODO Add pub time and replies |
|
175 | json_post_list.append(_get_post_data(post.id)) | |
|
176 | ||||
|
177 | return HttpResponse(content=json.dumps(json_post_list)) | |||
|
178 | ||||
|
179 | ||||
|
180 | # TODO Add pub time and replies | |||
|
181 | def _get_post_data(post_id, format_type=DIFF_TYPE_JSON, request=None): | |||
|
182 | if format_type == DIFF_TYPE_HTML: | |||
|
183 | return get_post(request, post_id).content.strip() | |||
|
184 | elif format_type == DIFF_TYPE_JSON: | |||
|
185 | post = get_object_or_404(Post, id=post_id) | |||
175 | post_json = { |
|
186 | post_json = { | |
176 | 'id': post.id, |
|
187 | 'id': post.id, | |
177 | 'title': post.title, |
|
188 | 'title': post.title, | |
@@ -180,6 +191,4 b' def api_get_thread_posts(request, openin' | |||||
180 | if post.image: |
|
191 | if post.image: | |
181 | post_json['image'] = post.image.url |
|
192 | post_json['image'] = post.image.url | |
182 | post_json['image_preview'] = post.image.url_200x150 |
|
193 | post_json['image_preview'] = post.image.url_200x150 | |
183 | json_post_list.append(post_json) |
|
194 | return post_json | |
184 |
|
||||
185 | return HttpResponse(content=json.dumps(json_post_list)) |
|
@@ -7,30 +7,50 b' Tha data is returned in the json format ' | |||||
7 |
|
7 | |||
8 | # METHODS # |
|
8 | # METHODS # | |
9 |
|
9 | |||
|
10 | ## Threads ## | |||
|
11 | ||||
10 | /api/threads/N/?offset=M&tag=O |
|
12 | /api/threads/N/?offset=M&tag=O | |
11 |
|
13 | |||
12 | Get a thread list. You will get N threads (required parameter) starting from |
|
14 | Get a thread list. You will get ``N`` threads (required parameter) starting from | |
13 | Mth one (optional parameter, default is 0) with the tag O (optional parameter, |
|
15 | ``M``th one (optional parameter, default is 0) with the tag ``O`` (optional parameter, | |
14 | threads with any tags are shown by default). |
|
16 | threads with any tags are shown by default). | |
15 |
|
17 | |||
|
18 | ## Tags ## | |||
|
19 | ||||
16 | /api/tags/ |
|
20 | /api/tags/ | |
17 |
|
21 | |||
18 | Get all active tag list. Active tag is a tag that has at least 1 active thread |
|
22 | Get all active tag list. Active tag is a tag that has at least 1 active thread | |
19 | associated with it. |
|
23 | associated with it. | |
20 |
|
24 | |||
|
25 | ## Thread ## | |||
|
26 | ||||
21 | /api/thread/N/ |
|
27 | /api/thread/N/ | |
22 |
|
28 | |||
23 | Get all Nth thread post. N is an opening post ID for the thread. |
|
29 | Get all ``N``th thread post. ``N`` is an opening post ID for the thread. | |
|
30 | ||||
|
31 | ## Thread diff ## | |||
|
32 | ||||
|
33 | /api/diff_thread/N/M/?type=O | |||
|
34 | ||||
|
35 | Get the diff of the thread with id=``N`` from the ``M`` timestamp in the ``O`` | |||
|
36 | format. 2 formats are available: ``html`` (used in AJAX thread update) and | |||
|
37 | ``json``. The default format is ``html``. Return list format: | |||
|
38 | ||||
|
39 | * ``added``: list of added posts | |||
|
40 | * ``updated``: list of updated posts | |||
|
41 | * ``last_update``: last update timestamp | |||
|
42 | ||||
|
43 | ## General info ## | |||
24 |
|
44 | |||
25 | In case of incorrect request you can get http error 404. |
|
45 | In case of incorrect request you can get http error 404. | |
26 |
|
46 | |||
27 | Response JSON contains: |
|
47 | Response JSON contains: | |
28 |
|
48 | |||
29 | * id |
|
49 | * ``id`` | |
30 | * title |
|
50 | * ``title`` | |
31 | * text |
|
51 | * ``text`` | |
32 | * image (if image available) |
|
52 | * ``image`` (if image available) | |
33 | * image_preview (if image available) |
|
53 | * ``image_preview`` (if image available) | |
34 |
|
54 | |||
35 | In future, it will also contain: |
|
55 | In future, it will also contain: | |
36 |
|
56 |
General Comments 0
You need to be logged in to leave comments.
Login now