##// END OF EJS Templates
Some progress in the sync
neko259 -
r1144:a82e4e4d decentral
parent child Browse files
Show More
@@ -1,6 +1,8 b''
1 1 import re
2 2 import urllib.parse
3 3 import httplib2
4 import xml.etree.ElementTree as ET
5
4 6 from django.core.management import BaseCommand
5 7 from boards.models import GlobalId
6 8
@@ -16,7 +18,7 b' class Command(BaseCommand):'
16 18
17 19 def add_arguments(self, parser):
18 20 parser.add_argument('url', type=str)
19 parser.add_argument('global_id', type=str)
21 #parser.add_argument('global_id', type=str) # TODO Implement this
20 22
21 23 def handle(self, *args, **options):
22 24 url = options.get('url')
@@ -43,4 +45,17 b' class Command(BaseCommand):'
43 45 else:
44 46 raise Exception('Invalid global ID')
45 47 else:
46 raise Exception('Full sync is not supported yet.')
48 h = httplib2.Http()
49 response, content = h.request(url, method="POST")
50
51 print(content)
52
53 root = ET.fromstring(content)
54 status = root.findall('status')[0].text
55 if status == 'success':
56 models = root.findall('models')[0]
57 for model in models:
58 model_content = model[0]
59 print(model_content.findall('text')[0].text)
60 else:
61 raise Exception('Invalid response status')
@@ -70,6 +70,10 b" urlpatterns = patterns('',"
70 70 url(r'^api/notifications/(?P<username>\w+)/$', api.api_get_notifications,
71 71 name='api_notifications'),
72 72
73 # Sync protocol API
74 url(r'^api/sync/pull/$', api.sync_pull, name='api_sync_pull'),
75 # TODO 'get' request
76
73 77 # Search
74 78 url(r'^search/$', BoardSearchView.as_view(), name='search'),
75 79
@@ -229,3 +229,18 b' def get_post_data(post_id, format_type=D'
229 229 post = get_object_or_404(Post, id=post_id)
230 230 return post.get_post_data(format_type=format_type, request=request,
231 231 include_last_update=include_last_update)
232
233
234 # TODO Make a separate module for sync API methods
235 def sync_pull(request):
236 """
237 Return 'get' request response for all posts.
238 """
239 request_xml = request.get('xml')
240 if request_xml is None:
241 posts = Post.objects.all()
242 else:
243 pass # TODO Parse the XML and get filters from it
244
245 xml = Post.objects.generate_response_get(posts)
246 return HttpResponse(content=xml)
General Comments 0
You need to be logged in to leave comments. Login now