Issue#2884: Crop images for the timeline
parent
00901a3c93
commit
83b8243d39
|
@ -409,11 +409,13 @@ SOUTH_MIGRATION_MODULES = {
|
||||||
|
|
||||||
DEFAULT_AVATAR_SIZE = 80 # 80x80 pixels
|
DEFAULT_AVATAR_SIZE = 80 # 80x80 pixels
|
||||||
DEFAULT_BIG_AVATAR_SIZE = 300 # 300x300 pixels
|
DEFAULT_BIG_AVATAR_SIZE = 300 # 300x300 pixels
|
||||||
|
DEFAULT_TIMELINE_IMAGE_SIZE = 640 # 640x??? pixels
|
||||||
|
|
||||||
THUMBNAIL_ALIASES = {
|
THUMBNAIL_ALIASES = {
|
||||||
'': {
|
'': {
|
||||||
'avatar': {'size': (DEFAULT_AVATAR_SIZE, DEFAULT_AVATAR_SIZE), 'crop': True},
|
'avatar': {'size': (DEFAULT_AVATAR_SIZE, DEFAULT_AVATAR_SIZE), 'crop': True},
|
||||||
'big-avatar': {'size': (DEFAULT_BIG_AVATAR_SIZE, DEFAULT_BIG_AVATAR_SIZE), 'crop': True},
|
'big-avatar': {'size': (DEFAULT_BIG_AVATAR_SIZE, DEFAULT_BIG_AVATAR_SIZE), 'crop': True},
|
||||||
|
'timeline-image': {'size': (DEFAULT_TIMELINE_IMAGE_SIZE, 0), 'crop': True},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,10 @@ from django.apps import apps
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
|
|
||||||
|
from easy_thumbnails.files import get_thumbnailer
|
||||||
|
from easy_thumbnails.exceptions import InvalidImageFormatError
|
||||||
|
|
||||||
|
from taiga.base.utils.urls import get_absolute_url
|
||||||
from taiga.base.utils.iterators import as_tuple
|
from taiga.base.utils.iterators import as_tuple
|
||||||
from taiga.base.utils.iterators import as_dict
|
from taiga.base.utils.iterators import as_dict
|
||||||
from taiga.mdrender.service import render as mdrender
|
from taiga.mdrender.service import render as mdrender
|
||||||
|
@ -179,10 +183,16 @@ def _generic_extract(obj:object, fields:list, default=None) -> dict:
|
||||||
@as_tuple
|
@as_tuple
|
||||||
def extract_attachments(obj) -> list:
|
def extract_attachments(obj) -> list:
|
||||||
for attach in obj.attachments.all():
|
for attach in obj.attachments.all():
|
||||||
|
try:
|
||||||
|
thumb_url = get_thumbnailer(attach.attached_file)['timeline-image'].url
|
||||||
|
thumb_url = get_absolute_url(thumb_url)
|
||||||
|
except InvalidImageFormatError as e:
|
||||||
|
thumb_url = None
|
||||||
|
|
||||||
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,
|
||||||
"description": attach.description,
|
"thumb_url": thumb_url,
|
||||||
"is_deprecated": attach.is_deprecated,
|
"is_deprecated": attach.is_deprecated,
|
||||||
"description": attach.description,
|
"description": attach.description,
|
||||||
"order": attach.order}
|
"order": attach.order}
|
||||||
|
|
|
@ -182,12 +182,13 @@ class HistoryEntry(models.Model):
|
||||||
for aid in set(tuple(oldattachs.keys()) + tuple(newattachs.keys())):
|
for aid in set(tuple(oldattachs.keys()) + tuple(newattachs.keys())):
|
||||||
if aid in oldattachs and aid in newattachs:
|
if aid in oldattachs and aid in newattachs:
|
||||||
changes = make_diff_from_dicts(oldattachs[aid], newattachs[aid],
|
changes = make_diff_from_dicts(oldattachs[aid], newattachs[aid],
|
||||||
excluded_keys=("filename", "url"))
|
excluded_keys=("filename", "url", "thumb_url"))
|
||||||
|
|
||||||
if changes:
|
if changes:
|
||||||
change = {
|
change = {
|
||||||
"filename": newattachs.get(aid, {}).get("filename", ""),
|
"filename": newattachs.get(aid, {}).get("filename", ""),
|
||||||
"url": newattachs.get(aid, {}).get("url", ""),
|
"url": newattachs.get(aid, {}).get("url", ""),
|
||||||
|
"thumb_url": newattachs.get(aid, {}).get("thumb_url", ""),
|
||||||
"changes": changes
|
"changes": changes
|
||||||
}
|
}
|
||||||
attachments["changed"].append(change)
|
attachments["changed"].append(change)
|
||||||
|
|
Loading…
Reference in New Issue