# HG changeset patch # User neko259 # Date 2015-05-05 17:11:50 # Node ID a82e4e4dac76f277e5bc5f630b9c2e54b9e86c41 # Parent a1834e0504dc897851ca5e9ba0ef7ee022ad5c9b Some progress in the sync diff --git a/boards/management/commands/sync_with_server.py b/boards/management/commands/sync_with_server.py --- a/boards/management/commands/sync_with_server.py +++ b/boards/management/commands/sync_with_server.py @@ -1,6 +1,8 @@ import re import urllib.parse import httplib2 +import xml.etree.ElementTree as ET + from django.core.management import BaseCommand from boards.models import GlobalId @@ -16,7 +18,7 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument('url', type=str) - parser.add_argument('global_id', type=str) + #parser.add_argument('global_id', type=str) # TODO Implement this def handle(self, *args, **options): url = options.get('url') @@ -43,4 +45,17 @@ class Command(BaseCommand): else: raise Exception('Invalid global ID') else: - raise Exception('Full sync is not supported yet.') + h = httplib2.Http() + response, content = h.request(url, method="POST") + + print(content) + + root = ET.fromstring(content) + status = root.findall('status')[0].text + if status == 'success': + models = root.findall('models')[0] + for model in models: + model_content = model[0] + print(model_content.findall('text')[0].text) + else: + raise Exception('Invalid response status') diff --git a/boards/urls.py b/boards/urls.py --- a/boards/urls.py +++ b/boards/urls.py @@ -70,6 +70,10 @@ urlpatterns = patterns('', url(r'^api/notifications/(?P\w+)/$', api.api_get_notifications, name='api_notifications'), + # Sync protocol API + url(r'^api/sync/pull/$', api.sync_pull, name='api_sync_pull'), + # TODO 'get' request + # Search url(r'^search/$', BoardSearchView.as_view(), name='search'), diff --git a/boards/views/api.py b/boards/views/api.py --- a/boards/views/api.py +++ b/boards/views/api.py @@ -229,3 +229,18 @@ def get_post_data(post_id, format_type=D post = get_object_or_404(Post, id=post_id) return post.get_post_data(format_type=format_type, request=request, include_last_update=include_last_update) + + +# TODO Make a separate module for sync API methods +def sync_pull(request): + """ + Return 'get' request response for all posts. + """ + request_xml = request.get('xml') + if request_xml is None: + posts = Post.objects.all() + else: + pass # TODO Parse the XML and get filters from it + + xml = Post.objects.generate_response_get(posts) + return HttpResponse(content=xml)