##// END OF EJS Templates
Added local download links for attachments
neko259 -
r1508:609c3572 decentral
parent child Browse files
Show More
@@ -23,6 +23,8 b" TAG_ATTACHMENTS = 'attachments'"
23 23 TAG_ATTACHMENT = 'attachment'
24 24 TAG_TAGS = 'tags'
25 25 TAG_TAG = 'tag'
26 TAG_ATTACHMENT_REFS = 'attachment-refs'
27 TAG_ATTACHMENT_REF = 'attachment-ref'
26 28
27 29 TYPE_GET = 'get'
28 30
@@ -32,6 +34,8 b" ATTR_NAME = 'name'"
32 34 ATTR_VALUE = 'value'
33 35 ATTR_MIMETYPE = 'mimetype'
34 36 ATTR_KEY = 'key'
37 ATTR_REF = 'ref'
38 ATTR_URL = 'url'
35 39
36 40 STATUS_SUCCESS = 'success'
37 41
@@ -79,16 +83,16 b' class SyncManager:'
79 83 attachments = post.attachments.all()
80 84 if len(images) > 0 or len(attachments) > 0:
81 85 attachments_tag = et.SubElement(content_tag, TAG_ATTACHMENTS)
86 attachment_refs = et.SubElement(model, TAG_ATTACHMENT_REFS)
87
82 88 for image in images:
83 mimetype = get_file_mimetype(image.image.file)
84 attachment = et.SubElement(attachments_tag, TAG_ATTACHMENT)
85 attachment.set(ATTR_MIMETYPE, mimetype)
86 attachment.text = image.hash
89 SyncManager._attachment_to_xml(
90 attachments_tag, attachment_refs, image.image.file,
91 image.hash, image.image.url)
87 92 for file in attachments:
88 mimetype = get_file_mimetype(file.file.file)
89 attachment = et.SubElement(attachments_tag, TAG_ATTACHMENT)
90 attachment.set(ATTR_MIMETYPE, mimetype)
91 attachment.text = file.hash
93 SyncManager._attachment_to_xml(
94 attachments_tag, attachment_refs, file.file.file,
95 file.hash, file.file.url)
92 96
93 97 signatures_tag = et.SubElement(model, TAG_SIGNATURES)
94 98 post_signatures = post.global_id.signature_set.all()
@@ -216,3 +220,14 b' class SyncManager:'
216 220 signatures.append(signature)
217 221
218 222 return signatures
223
224 @staticmethod
225 def _attachment_to_xml(tag_attachments, tag_refs, file, hash, url):
226 mimetype = get_file_mimetype(file)
227 attachment = et.SubElement(tag_attachments, TAG_ATTACHMENT)
228 attachment.set(ATTR_MIMETYPE, mimetype)
229 attachment.text = hash
230
231 attachment_ref = et.SubElement(tag_refs, TAG_ATTACHMENT_REF)
232 attachment_ref.set(ATTR_REF, hash)
233 attachment_ref.set(ATTR_URL, url)
General Comments 0
You need to be logged in to leave comments. Login now