Merge pull request #380 from taigaio/issue/2884/crop-images-for-timeline

Issue#2884: Crop images for the timeline
remotes/origin/enhancement/email-actions
David Barragán Merino 2015-06-29 18:02:36 +02:00
commit a3f0b5eba5
3 changed files with 16 additions and 3 deletions

View File

@ -409,11 +409,13 @@ SOUTH_MIGRATION_MODULES = {
DEFAULT_AVATAR_SIZE = 80 # 80x80 pixels
DEFAULT_BIG_AVATAR_SIZE = 300 # 300x300 pixels
DEFAULT_TIMELINE_IMAGE_SIZE = 640 # 640x??? pixels
THUMBNAIL_ALIASES = {
'': {
'avatar': {'size': (DEFAULT_AVATAR_SIZE, DEFAULT_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},
},
}

View File

@ -21,6 +21,10 @@ from django.apps import apps
from django.contrib.contenttypes.models import ContentType
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_dict
from taiga.mdrender.service import render as mdrender
@ -179,10 +183,16 @@ def _generic_extract(obj:object, fields:list, default=None) -> dict:
@as_tuple
def extract_attachments(obj) -> list:
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,
"filename": os.path.basename(attach.attached_file.name),
"url": attach.attached_file.url,
"description": attach.description,
"thumb_url": thumb_url,
"is_deprecated": attach.is_deprecated,
"description": attach.description,
"order": attach.order}

View File

@ -182,12 +182,13 @@ class HistoryEntry(models.Model):
for aid in set(tuple(oldattachs.keys()) + tuple(newattachs.keys())):
if aid in oldattachs and aid in newattachs:
changes = make_diff_from_dicts(oldattachs[aid], newattachs[aid],
excluded_keys=("filename", "url"))
excluded_keys=("filename", "url", "thumb_url"))
if changes:
change = {
"filename": newattachs.get(aid, {}).get("filename", ""),
"url": newattachs.get(aid, {}).get("url", ""),
"thumb_url": newattachs.get(aid, {}).get("thumb_url", ""),
"changes": changes
}
attachments["changed"].append(change)