Show More
@@ -5,7 +5,7 b' import httplib2' | |||||
5 | from django.core.management import BaseCommand |
|
5 | from django.core.management import BaseCommand | |
6 |
|
6 | |||
7 | from boards.models import GlobalId |
|
7 | from boards.models import GlobalId | |
8 | from boards.models.post.sync import SyncManager |
|
8 | from boards.models.post.sync import SyncManager, TAG_ID, TAG_VERSION | |
9 |
|
9 | |||
10 | __author__ = 'neko259' |
|
10 | __author__ = 'neko259' | |
11 |
|
11 | |||
@@ -64,11 +64,16 b' class Command(BaseCommand):' | |||||
64 |
|
64 | |||
65 | models = root.findall('models')[0] |
|
65 | models = root.findall('models')[0] | |
66 | for model in models: |
|
66 | for model in models: | |
|
67 | tag_id = model.find(TAG_ID) | |||
67 | global_id, exists = GlobalId.from_xml_element(model) |
|
68 | global_id, exists = GlobalId.from_xml_element(model) | |
68 | if not exists: |
|
69 | tag_version = model.find(TAG_VERSION) | |
69 | print(global_id) |
|
70 | if tag_version is not None: | |
|
71 | version = int(tag_version.text) or 1 | |||
|
72 | else: | |||
|
73 | version = 1 | |||
|
74 | if not exists or global_id.post.version < version: | |||
70 | ids_to_sync.append(global_id) |
|
75 | ids_to_sync.append(global_id) | |
71 | print() |
|
76 | print('Starting sync...') | |
72 |
|
77 | |||
73 | if len(ids_to_sync) > 0: |
|
78 | if len(ids_to_sync) > 0: | |
74 | limit = options.get('split_query', len(ids_to_sync)) |
|
79 | limit = options.get('split_query', len(ids_to_sync)) |
@@ -230,6 +230,7 b' class SyncManager:' | |||||
230 | title=title, text=text, pub_time=pub_time, |
|
230 | title=title, text=text, pub_time=pub_time, | |
231 | opening_post=opening_post, tags=tags, |
|
231 | opening_post=opening_post, tags=tags, | |
232 | global_id=global_id, files=files, tripcode=tripcode) |
|
232 | global_id=global_id, files=files, tripcode=tripcode) | |
|
233 | print('Parsed post {}'.format(global_id)) | |||
233 | else: |
|
234 | else: | |
234 | raise SyncException(EXCEPTION_NODE.format(tag_status.text)) |
|
235 | raise SyncException(EXCEPTION_NODE.format(tag_status.text)) | |
235 |
|
236 | |||
@@ -243,8 +244,11 b' class SyncManager:' | |||||
243 | models = et.SubElement(response, TAG_MODELS) |
|
244 | models = et.SubElement(response, TAG_MODELS) | |
244 |
|
245 | |||
245 | for post in Post.objects.prefetch_related('global_id').all(): |
|
246 | for post in Post.objects.prefetch_related('global_id').all(): | |
246 |
tag_ |
|
247 | tag_model = et.SubElement(models, TAG_MODEL) | |
|
248 | tag_id = et.SubElement(tag_model, TAG_ID) | |||
247 | post.global_id.to_xml_element(tag_id) |
|
249 | post.global_id.to_xml_element(tag_id) | |
|
250 | tag_version = et.SubElement(tag_model, TAG_VERSION) | |||
|
251 | tag_version.text = post.version | |||
248 |
|
252 | |||
249 | return et.tostring(response, ENCODING_UNICODE) |
|
253 | return et.tostring(response, ENCODING_UNICODE) | |
250 |
|
254 |
@@ -71,6 +71,7 b' class KeyTest(TestCase):' | |||||
71 | '<text>[post]%s[/post]</text>' |
|
71 | '<text>[post]%s[/post]</text>' | |
72 | '<thread><id key="%s" local-id="%d" type="%s" /></thread>' |
|
72 | '<thread><id key="%s" local-id="%d" type="%s" /></thread>' | |
73 | '<pub-time>%s</pub-time>' |
|
73 | '<pub-time>%s</pub-time>' | |
|
74 | '<version>%s</version>' | |||
74 | '</content>' % ( |
|
75 | '</content>' % ( | |
75 | key.public_key, |
|
76 | key.public_key, | |
76 | reply_post.id, |
|
77 | reply_post.id, | |
@@ -80,6 +81,7 b' class KeyTest(TestCase):' | |||||
80 | post.id, |
|
81 | post.id, | |
81 | key.key_type, |
|
82 | key.key_type, | |
82 | str(reply_post.get_pub_time_str()), |
|
83 | str(reply_post.get_pub_time_str()), | |
|
84 | post.version, | |||
83 | ) in response, |
|
85 | ) in response, | |
84 | 'Wrong XML generated for the GET response.') |
|
86 | 'Wrong XML generated for the GET response.') | |
85 |
|
87 |
@@ -43,6 +43,7 b' class SyncTest(TestCase):' | |||||
43 | '<text>%s</text>' |
|
43 | '<text>%s</text>' | |
44 | '<tags><tag>%s</tag></tags>' |
|
44 | '<tags><tag>%s</tag></tags>' | |
45 | '<pub-time>%s</pub-time>' |
|
45 | '<pub-time>%s</pub-time>' | |
|
46 | '<version>%s</version>' | |||
46 | '</content>' % ( |
|
47 | '</content>' % ( | |
47 | post.global_id.key, |
|
48 | post.global_id.key, | |
48 | post.global_id.local_id, |
|
49 | post.global_id.local_id, | |
@@ -51,6 +52,7 b' class SyncTest(TestCase):' | |||||
51 | post.get_sync_text(), |
|
52 | post.get_sync_text(), | |
52 | post.get_thread().get_tags().first().name, |
|
53 | post.get_thread().get_tags().first().name, | |
53 | post.get_pub_time_str(), |
|
54 | post.get_pub_time_str(), | |
|
55 | post.version, | |||
54 | ) in response, |
|
56 | ) in response, | |
55 | 'Wrong response generated for the GET request.') |
|
57 | 'Wrong response generated for the GET request.') | |
56 |
|
58 | |||
@@ -90,6 +92,7 b' class SyncTest(TestCase):' | |||||
90 | '<text>%s</text>' |
|
92 | '<text>%s</text>' | |
91 | '<tags><tag>%s</tag></tags>' |
|
93 | '<tags><tag>%s</tag></tags>' | |
92 | '<pub-time>%s</pub-time>' |
|
94 | '<pub-time>%s</pub-time>' | |
|
95 | '<version>%s</version>' | |||
93 | '</content>' % ( |
|
96 | '</content>' % ( | |
94 | post.global_id.key, |
|
97 | post.global_id.key, | |
95 | post.global_id.local_id, |
|
98 | post.global_id.local_id, | |
@@ -98,5 +101,6 b' class SyncTest(TestCase):' | |||||
98 | post.get_sync_text(), |
|
101 | post.get_sync_text(), | |
99 | post.get_thread().get_tags().first().name, |
|
102 | post.get_thread().get_tags().first().name, | |
100 | post.get_pub_time_str(), |
|
103 | post.get_pub_time_str(), | |
|
104 | post.version, | |||
101 | ) in response, |
|
105 | ) in response, | |
102 | 'Wrong response generated for the GET request.') |
|
106 | 'Wrong response generated for the GET request.') |
General Comments 0
You need to be logged in to leave comments.
Login now