##// 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 import re
1 import re
2 import urllib.parse
2 import urllib.parse
3 import httplib2
3 import httplib2
4 import xml.etree.ElementTree as ET
5
4 from django.core.management import BaseCommand
6 from django.core.management import BaseCommand
5 from boards.models import GlobalId
7 from boards.models import GlobalId
6
8
@@ -16,7 +18,7 b' class Command(BaseCommand):'
16
18
17 def add_arguments(self, parser):
19 def add_arguments(self, parser):
18 parser.add_argument('url', type=str)
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 def handle(self, *args, **options):
23 def handle(self, *args, **options):
22 url = options.get('url')
24 url = options.get('url')
@@ -43,4 +45,17 b' class Command(BaseCommand):'
43 else:
45 else:
44 raise Exception('Invalid global ID')
46 raise Exception('Invalid global ID')
45 else:
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 url(r'^api/notifications/(?P<username>\w+)/$', api.api_get_notifications,
70 url(r'^api/notifications/(?P<username>\w+)/$', api.api_get_notifications,
71 name='api_notifications'),
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 # Search
77 # Search
74 url(r'^search/$', BoardSearchView.as_view(), name='search'),
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 post = get_object_or_404(Post, id=post_id)
229 post = get_object_or_404(Post, id=post_id)
230 return post.get_post_data(format_type=format_type, request=request,
230 return post.get_post_data(format_type=format_type, request=request,
231 include_last_update=include_last_update)
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