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