diff --git a/sapl/compilacao/forms.py b/sapl/compilacao/forms.py index 3423cc7e8..be45bade7 100644 --- a/sapl/compilacao/forms.py +++ b/sapl/compilacao/forms.py @@ -13,7 +13,7 @@ from django.forms.forms import Form from django.forms.models import ModelForm from django.template import defaultfilters from django.utils.translation import gettext_lazy as _ -from image_cropping.widgets import CropWidget, ImageCropWidget +from image_cropping.widgets import CropWidget from model_utils.choices import Choices from sapl import utils @@ -26,19 +26,8 @@ from sapl.compilacao.models import (NOTAS_PUBLICIDADE_CHOICES, from sapl.compilacao.utils import DISPOSITIVO_SELECT_RELATED from sapl.crispy_layout_mixin import SaplFormHelper from sapl.crispy_layout_mixin import SaplFormLayout, to_column, to_row -from sapl.utils import YES_NO_CHOICES, FileFieldCheckMixin - - -class CustomImageCropWidget(ImageCropWidget): - """ - Custom ImageCropWidget that doesn't show the initial value of the field. - We use this trick, and place it right under the CropWidget so that - it looks like the user is seeing the image and clearing the image. - """ - template_with_initial = ( - # '%(initial_text)s: %(initial)s ' - '%(clear_template)s
%(input_text)s: %(input)s' - ) +from sapl.utils import YES_NO_CHOICES, FileFieldCheckMixin,\ + CustomImageCropWidget error_messages = { diff --git a/sapl/parlamentares/forms.py b/sapl/parlamentares/forms.py index 0aa0479b3..42188d93e 100755 --- a/sapl/parlamentares/forms.py +++ b/sapl/parlamentares/forms.py @@ -13,30 +13,18 @@ from django.forms import ModelForm from django.utils import timezone from django.utils.translation import gettext_lazy as _ import django_filters -from image_cropping.widgets import CropWidget, ImageCropWidget +from image_cropping.widgets import CropWidget, ImageCropWidget, get_attrs from sapl.base.models import Autor, TipoAutor from sapl.crispy_layout_mixin import SaplFormHelper from sapl.crispy_layout_mixin import form_actions, to_row from sapl.rules import SAPL_GROUP_VOTANTE -from sapl.utils import FileFieldCheckMixin +from sapl.utils import FileFieldCheckMixin, CustomImageCropWidget from .models import (Coligacao, ComposicaoColigacao, Filiacao, Frente, Legislatura, Mandato, Parlamentar, Partido, Votante, Bloco, FrenteParlamentar, BlocoMembro) -class CustomImageCropWidget(ImageCropWidget): - """ - Custom ImageCropWidget that doesn't show the initial value of the field. - We use this trick, and place it right under the CropWidget so that - it looks like the user is seeing the image and clearing the image. - """ - template_with_initial = ( - # '%(initial_text)s: %(initial)s ' - '%(clear_template)s
%(input_text)s: %(input)s' - ) - - def validar_datas_legislatura(eleicao, inicio, fim, pk=None): logger = logging.getLogger(__name__) # Verifica se data de eleição < inicio < fim diff --git a/sapl/utils.py b/sapl/utils.py index e4b3c6c1b..50d912888 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -38,6 +38,7 @@ from django.utils.safestring import mark_safe from django.utils.translation import gettext_lazy as _ import django_filters from easy_thumbnails import source_generators +from image_cropping.widgets import ImageCropWidget, get_attrs import magic import requests import six @@ -309,6 +310,16 @@ class SaplGenericRelation(GenericRelation): super().__init__(to, **kwargs) +class CustomImageCropWidget(ImageCropWidget): + def subwidgets(self, name, value, attrs=None): + if not attrs: + attrs = {} + if value: + attrs.update(get_attrs(value, name)) + + return super().subwidgets(name, value, attrs=attrs) + + class ImageThumbnailFileInput(ClearableFileInput): template_name = 'widgets/image_thumbnail.html'