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,
"filename": os.path.basename(attach.attached_file.name),
"url": attach.attached_file.url,
"attached_file": str(attach.attached_file),
"thumb_url": thumb_url,
"is_deprecated": attach.is_deprecated,
"description": attach.description,

View File

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