Show More
@@ -86,3 +86,6 b' class Attachment(models.Model):' | |||||
86 | return get_image_dimensions(preview_path) |
|
86 | return get_image_dimensions(preview_path) | |
87 | else: |
|
87 | else: | |
88 | return 200, 150 |
|
88 | return 200, 150 | |
|
89 | ||||
|
90 | def is_internal(self): | |||
|
91 | return self.url is None or len(self.url) == 0 |
@@ -50,6 +50,7 b" ATTR_URL = 'url'" | |||||
50 | ATTR_ID_TYPE = 'id-type' |
|
50 | ATTR_ID_TYPE = 'id-type' | |
51 |
|
51 | |||
52 | ID_TYPE_MD5 = 'md5' |
|
52 | ID_TYPE_MD5 = 'md5' | |
|
53 | ID_TYPE_URL = 'url' | |||
53 |
|
54 | |||
54 | STATUS_SUCCESS = 'success' |
|
55 | STATUS_SUCCESS = 'success' | |
55 |
|
56 | |||
@@ -77,11 +78,17 b' class SyncManager:' | |||||
77 | if global_id.content: |
|
78 | if global_id.content: | |
78 | model.append(et.fromstring(global_id.content)) |
|
79 | model.append(et.fromstring(global_id.content)) | |
79 | if len(attachments) > 0: |
|
80 | if len(attachments) > 0: | |
80 | attachment_refs = et.SubElement(model, TAG_ATTACHMENT_REFS) |
|
81 | internal_attachments = False | |
81 |
for |
|
82 | for attachment in attachments: | |
82 |
|
|
83 | if attachment.is_internal(): | |
83 |
|
|
84 | internal_attachments = True | |
84 |
|
|
85 | break | |
|
86 | ||||
|
87 | if internal_attachments: | |||
|
88 | attachment_refs = et.SubElement(model, TAG_ATTACHMENT_REFS) | |||
|
89 | for file in attachments: | |||
|
90 | SyncManager._attachment_to_xml( | |||
|
91 | None, attachment_refs, file) | |||
85 | else: |
|
92 | else: | |
86 | content_tag = et.SubElement(model, TAG_CONTENT) |
|
93 | content_tag = et.SubElement(model, TAG_CONTENT) | |
87 |
|
94 | |||
@@ -114,12 +121,21 b' class SyncManager:' | |||||
114 |
|
121 | |||
115 | if len(attachments) > 0: |
|
122 | if len(attachments) > 0: | |
116 | attachments_tag = et.SubElement(content_tag, TAG_ATTACHMENTS) |
|
123 | attachments_tag = et.SubElement(content_tag, TAG_ATTACHMENTS) | |
117 | attachment_refs = et.SubElement(model, TAG_ATTACHMENT_REFS) |
|
124 | ||
|
125 | internal_attachments = False | |||
|
126 | for attachment in attachments: | |||
|
127 | if attachment.is_internal(): | |||
|
128 | internal_attachments = True | |||
|
129 | break | |||
|
130 | ||||
|
131 | if internal_attachments: | |||
|
132 | attachment_refs = et.SubElement(model, TAG_ATTACHMENT_REFS) | |||
|
133 | else: | |||
|
134 | attachment_refs = None | |||
118 |
|
135 | |||
119 | for file in attachments: |
|
136 | for file in attachments: | |
120 | SyncManager._attachment_to_xml( |
|
137 | SyncManager._attachment_to_xml( | |
121 |
attachments_tag, attachment_refs, file |
|
138 | attachments_tag, attachment_refs, file) | |
122 | file.hash, file.file.url) |
|
|||
123 | version_tag = et.SubElement(content_tag, TAG_VERSION) |
|
139 | version_tag = et.SubElement(content_tag, TAG_VERSION) | |
124 | version_tag.text = str(post.version) |
|
140 | version_tag.text = str(post.version) | |
125 |
|
141 | |||
@@ -289,14 +305,19 b' class SyncManager:' | |||||
289 | return signatures |
|
305 | return signatures | |
290 |
|
306 | |||
291 | @staticmethod |
|
307 | @staticmethod | |
292 |
def _attachment_to_xml(tag_attachments, tag_refs, |
|
308 | def _attachment_to_xml(tag_attachments, tag_refs, attachment): | |
293 | if tag_attachments is not None: |
|
309 | if tag_attachments is not None: | |
294 | mimetype = get_file_mimetype(file) |
|
310 | attachment_tag = et.SubElement(tag_attachments, TAG_ATTACHMENT) | |
295 | attachment = et.SubElement(tag_attachments, TAG_ATTACHMENT) |
|
311 | if attachment.is_internal(): | |
296 | attachment.set(ATTR_MIMETYPE, mimetype) |
|
312 | mimetype = get_file_mimetype(attachment.file.file) | |
297 |
attachment.set(ATTR_ |
|
313 | attachment_tag.set(ATTR_MIMETYPE, mimetype) | |
298 | attachment.text = hash |
|
314 | attachment_tag.set(ATTR_ID_TYPE, ID_TYPE_MD5) | |
|
315 | attachment_tag.text = attachment.hash | |||
|
316 | else: | |||
|
317 | attachment_tag.set(ATTR_ID_TYPE, ID_TYPE_URL) | |||
|
318 | attachment_tag.text = attachment.url | |||
299 |
|
319 | |||
300 | attachment_ref = et.SubElement(tag_refs, TAG_ATTACHMENT_REF) |
|
320 | if tag_refs is not None: | |
301 | attachment_ref.set(ATTR_REF, hash) |
|
321 | attachment_ref = et.SubElement(tag_refs, TAG_ATTACHMENT_REF) | |
302 |
attachment_ref.set(ATTR_ |
|
322 | attachment_ref.set(ATTR_REF, attachment.hash) | |
|
323 | attachment_ref.set(ATTR_URL, attachment.url) |
General Comments 0
You need to be logged in to leave comments.
Login now