From 83b8243d395ff73c0ddfd9491d7e25e59479fcb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Mon, 29 Jun 2015 16:05:42 +0200 Subject: [PATCH] Issue#2884: Crop images for the timeline --- settings/common.py | 2 ++ taiga/projects/history/freeze_impl.py | 14 ++++++++++++-- taiga/projects/history/models.py | 3 ++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/settings/common.py b/settings/common.py index a8c88c41..1a441e92 100644 --- a/settings/common.py +++ b/settings/common.py @@ -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}, }, } diff --git a/taiga/projects/history/freeze_impl.py b/taiga/projects/history/freeze_impl.py index 1e1038cb..a591c666 100644 --- a/taiga/projects/history/freeze_impl.py +++ b/taiga/projects/history/freeze_impl.py @@ -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 @@ -100,7 +104,7 @@ def project_values(diff): values = _common_users_values(diff) return values - + def milestone_values(diff): values = _common_users_values(diff) return values @@ -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} diff --git a/taiga/projects/history/models.py b/taiga/projects/history/models.py index 48b890fb..82d1667d 100644 --- a/taiga/projects/history/models.py +++ b/taiga/projects/history/models.py @@ -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)