From 345da6ddccfb5e97915e81df418da80dfafab9e8 Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Wed, 28 Feb 2018 11:59:07 -0300 Subject: [PATCH] add thumbnail generator customizado MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit assim como a os broswer para rendenderizar a tag desconsideram a informação de EXIF.orientation, um thumbnail_generator customizado é necessário para manter a comportamento... para haver reflexo, as imagens secundárias devem ser apagadas de MEDIA_ROOT, não sendo necessário pois, reenviar as imagens primárias. --- sapl/settings.py | 3 +++ sapl/utils.py | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/sapl/settings.py b/sapl/settings.py index 31905aa07..2e6b7c7ff 100644 --- a/sapl/settings.py +++ b/sapl/settings.py @@ -188,6 +188,9 @@ THUMBNAIL_PROCESSORS = ( 'image_cropping.thumbnail_processors.crop_corners', ) + thumbnail_settings.THUMBNAIL_PROCESSORS +THUMBNAIL_SOURCE_GENERATORS = ( + 'sapl.utils.pil_image', +) # troque no caso de reimplementação da classe User conforme # https://docs.djangoproject.com/en/1.9/topics/auth/customizing/#substituting-a-custom-user-model diff --git a/sapl/utils.py b/sapl/utils.py index 01f0f5f2b..3a3cb3fad 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -1,13 +1,11 @@ +from functools import wraps +from operator import itemgetter +from unicodedata import normalize as unicodedata_normalize import hashlib import logging import os import re -from functools import wraps -from operator import itemgetter -from unicodedata import normalize as unicodedata_normalize -import django_filters -import magic from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Button from django import forms @@ -21,14 +19,23 @@ from django.db.models import Q from django.utils import six, timezone from django.utils.translation import ugettext_lazy as _ from django_filters.filterset import STRICTNESS +from easy_thumbnails import source_generators from floppyforms import ClearableFileInput from reversion.admin import VersionAdmin +import django_filters +import magic + from sapl.crispy_layout_mixin import SaplFormLayout, form_actions, to_row from sapl.settings import BASE_DIR + sapl_logger = logging.getLogger(BASE_DIR.name) +def pil_image(source, exif_orientation=False, **options): + return source_generators.pil_image(source, exif_orientation, **options) + + def normalize(txt): return unicodedata_normalize( 'NFKD', txt).encode('ASCII', 'ignore').decode('ASCII')