Show More
@@ -1,62 +1,55 b'' | |||
|
1 | 1 | import xml.etree.ElementTree as et |
|
2 | import xml.dom.minidom | |
|
3 | 2 | |
|
4 | 3 | from django.http import HttpResponse, Http404 |
|
5 | 4 | from boards.models import GlobalId, Post |
|
6 | 5 | from boards.models.post.sync import SyncManager |
|
7 | 6 | |
|
8 | 7 | |
|
9 | 8 | def response_list(request): |
|
10 | 9 | request_xml = request.body |
|
11 | 10 | |
|
12 | 11 | if request_xml is None or len(request_xml) == 0: |
|
13 | 12 | return HttpResponse(content='Use the API') |
|
14 | 13 | |
|
15 | 14 | response_xml = SyncManager.generate_response_list() |
|
16 | 15 | |
|
17 | 16 | return HttpResponse(content=response_xml) |
|
18 | 17 | |
|
19 | 18 | |
|
20 | 19 | def response_get(request): |
|
21 | 20 | """ |
|
22 | 21 | Processes a GET request with post ID list and returns the posts XML list. |
|
23 | 22 | Request should contain an 'xml' post attribute with the actual request XML. |
|
24 | 23 | """ |
|
25 | 24 | |
|
26 | 25 | request_xml = request.body |
|
27 | 26 | |
|
28 | 27 | if request_xml is None or len(request_xml) == 0: |
|
29 | 28 | return HttpResponse(content='Use the API') |
|
30 | 29 | |
|
31 | 30 | posts = [] |
|
32 | 31 | |
|
33 | 32 | root_tag = et.fromstring(request_xml) |
|
34 | 33 | model_tag = root_tag[0] |
|
35 | 34 | for id_tag in model_tag: |
|
36 | 35 | global_id, exists = GlobalId.from_xml_element(id_tag) |
|
37 | 36 | if exists: |
|
38 | 37 | posts.append(Post.objects.get(global_id=global_id)) |
|
39 | 38 | |
|
40 | 39 | response_xml = SyncManager.generate_response_get(posts) |
|
41 | 40 | |
|
42 | 41 | return HttpResponse(content=response_xml) |
|
43 | 42 | |
|
44 | 43 | |
|
45 | 44 | def get_post_sync_data(request, post_id): |
|
46 | 45 | try: |
|
47 | 46 | post = Post.objects.get(id=post_id) |
|
48 | 47 | except Post.DoesNotExist: |
|
49 | 48 | raise Http404() |
|
50 | 49 | |
|
51 | 50 | xml_str = SyncManager.generate_response_get([post]) |
|
52 | 51 | |
|
53 | xml_repr = xml.dom.minidom.parseString(xml_str) | |
|
54 | xml_repr = xml_repr.toprettyxml() | |
|
55 | ||
|
56 | content = '=Global ID=\n%s\n\n=XML=\n%s' \ | |
|
57 | % (post.global_id, xml_repr) | |
|
58 | ||
|
59 | 52 | return HttpResponse( |
|
60 |
content_type='text/ |
|
|
61 |
content= |
|
|
62 | ) No newline at end of file | |
|
53 | content_type='text/xml; charset=utf-8', | |
|
54 | content=xml_str, | |
|
55 | ) |
General Comments 0
You need to be logged in to leave comments.
Login now