Save thumbnail file path in timeline and use it in serializer
parent
d55ee21e8e
commit
34c5bd40d3
|
@ -15,12 +15,13 @@
|
|||
|
||||
from django.conf import settings
|
||||
|
||||
from taiga.base.utils.thumbnails import get_thumbnail_url
|
||||
from taiga.base.utils.thumbnails import get_thumbnail_url, get_thumbnail
|
||||
|
||||
|
||||
def get_timeline_image_thumbnail_url(attachment):
|
||||
def get_timeline_image_thumbnail_name(attachment):
|
||||
if attachment.attached_file:
|
||||
return get_thumbnail_url(attachment.attached_file, settings.THN_ATTACHMENT_TIMELINE)
|
||||
thumbnail = get_thumbnail(attachment.attached_file, settings.THN_ATTACHMENT_TIMELINE)
|
||||
return thumbnail.name if thumbnail else None
|
||||
return None
|
||||
|
||||
|
||||
|
@ -29,6 +30,7 @@ def get_card_image_thumbnail_url(attachment):
|
|||
return get_thumbnail_url(attachment.attached_file, settings.THN_ATTACHMENT_CARD)
|
||||
return None
|
||||
|
||||
|
||||
def get_attachment_image_preview_url(attachment):
|
||||
if attachment.attached_file:
|
||||
return get_thumbnail_url(attachment.attached_file, settings.THN_ATTACHMENT_PREVIEW)
|
||||
|
|
|
@ -28,7 +28,7 @@ from taiga.base.utils.iterators import as_tuple
|
|||
from taiga.base.utils.iterators import as_dict
|
||||
from taiga.mdrender.service import render as mdrender
|
||||
|
||||
from taiga.projects.attachments.services import get_timeline_image_thumbnail_url
|
||||
from taiga.projects.attachments.services import get_timeline_image_thumbnail_name
|
||||
|
||||
import os
|
||||
|
||||
|
@ -199,12 +199,13 @@ def _generic_extract(obj:object, fields:list, default=None) -> dict:
|
|||
def extract_attachments(obj) -> list:
|
||||
for attach in obj.attachments.all():
|
||||
# Force the creation of a thumbnail for the timeline
|
||||
get_timeline_image_thumbnail_url(attach)
|
||||
thumbnail_file = get_timeline_image_thumbnail_name(attach)
|
||||
|
||||
yield {"id": attach.id,
|
||||
"filename": os.path.basename(attach.attached_file.name),
|
||||
"url": attach.attached_file.url,
|
||||
"attached_file": str(attach.attached_file),
|
||||
"thumbnail_file": thumbnail_file,
|
||||
"is_deprecated": attach.is_deprecated,
|
||||
"description": attach.description,
|
||||
"order": attach.order}
|
||||
|
|
|
@ -85,7 +85,12 @@ class TimelineSerializer(serializers.LightSerializer):
|
|||
attached_file = file_path[index+1:]
|
||||
|
||||
item['url'] = default_storage.url(attached_file)
|
||||
thumb_url = get_thumbnail_url(attached_file,
|
||||
settings.THN_ATTACHMENT_TIMELINE)
|
||||
|
||||
if 'thumbnail_file' in item:
|
||||
thumb_file = item['thumbnail_file']
|
||||
thumb_url = default_storage.url(thumb_file) if thumb_file else None
|
||||
else:
|
||||
thumb_url = get_thumbnail_url(attached_file,
|
||||
settings.THN_ATTACHMENT_TIMELINE)
|
||||
|
||||
item['thumb_url'] = thumb_url
|
||||
|
|
Loading…
Reference in New Issue