Save attachment values diff with attached file

remotes/origin/4.0rc
Álex Hermida 2018-09-07 12:47:43 +02:00 committed by Alex Hermida
parent ef788d0946
commit 124e2838fb
2 changed files with 7 additions and 5 deletions

View File

@ -203,6 +203,7 @@ def extract_attachments(obj) -> list:
yield {"id": attach.id, yield {"id": attach.id,
"filename": os.path.basename(attach.attached_file.name), "filename": os.path.basename(attach.attached_file.name),
"url": attach.attached_file.url, "url": attach.attached_file.url,
"attached_file": str(attach.attached_file),
"thumb_url": thumb_url, "thumb_url": thumb_url,
"is_deprecated": attach.is_deprecated, "is_deprecated": attach.is_deprecated,
"description": attach.description, "description": attach.description,

View File

@ -74,10 +74,11 @@ class TimelineSerializer(serializers.LightSerializer):
return obj.data return obj.data
def parse_url(self, item): def parse_url(self, item):
file_path = urlparse(item['url']).path if 'attached_file' in item:
index = file_path.find('/attachments') attached_file = item['attached_file']
attached_file = file_path[index+1:] else:
file_path = urlparse(item['url']).path
index = file_path.find('/attachments')
attached_file = file_path[index+1:]
item['url'] = default_storage.url(attached_file) item['url'] = default_storage.url(attached_file)
return item['url']