Show More
@@ -86,3 +86,6 b' class Attachment(models.Model):' | |||
|
86 | 86 | return get_image_dimensions(preview_path) |
|
87 | 87 | else: |
|
88 | 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 | 50 | ATTR_ID_TYPE = 'id-type' |
|
51 | 51 | |
|
52 | 52 | ID_TYPE_MD5 = 'md5' |
|
53 | ID_TYPE_URL = 'url' | |
|
53 | 54 | |
|
54 | 55 | STATUS_SUCCESS = 'success' |
|
55 | 56 | |
@@ -77,11 +78,17 b' class SyncManager:' | |||
|
77 | 78 | if global_id.content: |
|
78 | 79 | model.append(et.fromstring(global_id.content)) |
|
79 | 80 | if len(attachments) > 0: |
|
80 | attachment_refs = et.SubElement(model, TAG_ATTACHMENT_REFS) | |
|
81 |
for |
|
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
|
81 | internal_attachments = False | |
|
82 | for attachment in attachments: | |
|
83 | if attachment.is_internal(): | |
|
84 | internal_attachments = True | |
|
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 | 92 | else: |
|
86 | 93 | content_tag = et.SubElement(model, TAG_CONTENT) |
|
87 | 94 | |
@@ -114,12 +121,21 b' class SyncManager:' | |||
|
114 | 121 | |
|
115 | 122 | if len(attachments) > 0: |
|
116 | 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 | 136 | for file in attachments: |
|
120 | 137 | SyncManager._attachment_to_xml( |
|
121 |
attachments_tag, attachment_refs, file |
|
|
122 | file.hash, file.file.url) | |
|
138 | attachments_tag, attachment_refs, file) | |
|
123 | 139 | version_tag = et.SubElement(content_tag, TAG_VERSION) |
|
124 | 140 | version_tag.text = str(post.version) |
|
125 | 141 | |
@@ -289,14 +305,19 b' class SyncManager:' | |||
|
289 | 305 | return signatures |
|
290 | 306 | |
|
291 | 307 | @staticmethod |
|
292 |
def _attachment_to_xml(tag_attachments, tag_refs, |
|
|
308 | def _attachment_to_xml(tag_attachments, tag_refs, attachment): | |
|
293 | 309 | if tag_attachments is not None: |
|
294 | mimetype = get_file_mimetype(file) | |
|
295 | attachment = et.SubElement(tag_attachments, TAG_ATTACHMENT) | |
|
296 | attachment.set(ATTR_MIMETYPE, mimetype) | |
|
297 |
attachment.set(ATTR_ |
|
|
298 | attachment.text = hash | |
|
310 | attachment_tag = et.SubElement(tag_attachments, TAG_ATTACHMENT) | |
|
311 | if attachment.is_internal(): | |
|
312 | mimetype = get_file_mimetype(attachment.file.file) | |
|
313 | attachment_tag.set(ATTR_MIMETYPE, mimetype) | |
|
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) | |
|
301 | attachment_ref.set(ATTR_REF, hash) | |
|
302 |
attachment_ref.set(ATTR_ |
|
|
320 | if tag_refs is not None: | |
|
321 | attachment_ref = et.SubElement(tag_refs, TAG_ATTACHMENT_REF) | |
|
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