Refactor thumb_url in timeline serializer
parent
c40cb86dbd
commit
ef8f44e434
|
@ -18,10 +18,12 @@
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from django.core.files.storage import default_storage
|
from django.core.files.storage import default_storage
|
||||||
|
from django.conf import settings
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
from taiga.base.api import serializers
|
from taiga.base.api import serializers
|
||||||
from taiga.base.fields import Field, MethodField
|
from taiga.base.fields import Field, MethodField
|
||||||
|
from taiga.base.utils.thumbnails import get_thumbnail_url
|
||||||
from taiga.users.services import get_user_photo_url, get_user_big_photo_url
|
from taiga.users.services import get_user_photo_url, get_user_big_photo_url
|
||||||
from taiga.users.gravatar import get_user_gravatar_id
|
from taiga.users.gravatar import get_user_gravatar_id
|
||||||
|
|
||||||
|
@ -77,8 +79,13 @@ class TimelineSerializer(serializers.LightSerializer):
|
||||||
if 'attached_file' in item:
|
if 'attached_file' in item:
|
||||||
attached_file = item['attached_file']
|
attached_file = item['attached_file']
|
||||||
else:
|
else:
|
||||||
|
# This is the case for old timeline entries
|
||||||
file_path = urlparse(item['url']).path
|
file_path = urlparse(item['url']).path
|
||||||
index = file_path.find('/attachments')
|
index = file_path.find('/attachments')
|
||||||
attached_file = file_path[index+1:]
|
attached_file = file_path[index+1:]
|
||||||
|
|
||||||
item['url'] = default_storage.url(attached_file)
|
item['url'] = default_storage.url(attached_file)
|
||||||
|
thumb_url = get_thumbnail_url(attached_file,
|
||||||
|
settings.THN_ATTACHMENT_TIMELINE)
|
||||||
|
|
||||||
|
item['thumb_url'] = thumb_url
|
||||||
|
|
Loading…
Reference in New Issue