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 @@ -5,7 +5,7 @@ import httplib2 from django.core.management import BaseCommand from boards.models import GlobalId -from boards.models.post.sync import SyncManager +from boards.models.post.sync import SyncManager, TAG_ID, TAG_VERSION __author__ = 'neko259' @@ -64,11 +64,16 @@ class Command(BaseCommand): models = root.findall('models')[0] for model in models: + tag_id = model.find(TAG_ID) global_id, exists = GlobalId.from_xml_element(model) - if not exists: - print(global_id) + tag_version = model.find(TAG_VERSION) + if tag_version is not None: + version = int(tag_version.text) or 1 + else: + version = 1 + if not exists or global_id.post.version < version: ids_to_sync.append(global_id) - print() + print('Starting sync...') if len(ids_to_sync) > 0: limit = options.get('split_query', len(ids_to_sync)) diff --git a/boards/models/post/sync.py b/boards/models/post/sync.py --- a/boards/models/post/sync.py +++ b/boards/models/post/sync.py @@ -230,6 +230,7 @@ class SyncManager: title=title, text=text, pub_time=pub_time, opening_post=opening_post, tags=tags, global_id=global_id, files=files, tripcode=tripcode) + print('Parsed post {}'.format(global_id)) else: raise SyncException(EXCEPTION_NODE.format(tag_status.text)) @@ -243,8 +244,11 @@ class SyncManager: models = et.SubElement(response, TAG_MODELS) for post in Post.objects.prefetch_related('global_id').all(): - tag_id = et.SubElement(models, TAG_ID) + tag_model = et.SubElement(models, TAG_MODEL) + tag_id = et.SubElement(tag_model, TAG_ID) post.global_id.to_xml_element(tag_id) + tag_version = et.SubElement(tag_model, TAG_VERSION) + tag_version.text = post.version return et.tostring(response, ENCODING_UNICODE) diff --git a/boards/tests/test_keys.py b/boards/tests/test_keys.py --- a/boards/tests/test_keys.py +++ b/boards/tests/test_keys.py @@ -71,6 +71,7 @@ class KeyTest(TestCase): '[post]%s[/post]' '' '%s' + '%s' '' % ( key.public_key, reply_post.id, @@ -80,6 +81,7 @@ class KeyTest(TestCase): post.id, key.key_type, str(reply_post.get_pub_time_str()), + post.version, ) in response, 'Wrong XML generated for the GET response.') diff --git a/boards/tests/test_sync.py b/boards/tests/test_sync.py --- a/boards/tests/test_sync.py +++ b/boards/tests/test_sync.py @@ -43,6 +43,7 @@ class SyncTest(TestCase): '%s' '%s' '%s' + '%s' '' % ( post.global_id.key, post.global_id.local_id, @@ -51,6 +52,7 @@ class SyncTest(TestCase): post.get_sync_text(), post.get_thread().get_tags().first().name, post.get_pub_time_str(), + post.version, ) in response, 'Wrong response generated for the GET request.') @@ -90,6 +92,7 @@ class SyncTest(TestCase): '%s' '%s' '%s' + '%s' '' % ( post.global_id.key, post.global_id.local_id, @@ -98,5 +101,6 @@ class SyncTest(TestCase): post.get_sync_text(), post.get_thread().get_tags().first().name, post.get_pub_time_str(), + post.version, ) in response, 'Wrong response generated for the GET request.')