Browse Source

fix: corrige image cropping widget

bump_django
LeandroJatai 5 months ago
parent
commit
fba93f5fe7
  1. 17
      sapl/compilacao/forms.py
  2. 16
      sapl/parlamentares/forms.py
  3. 11
      sapl/utils.py

17
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: <a href="%(initial_url)s">%(initial)s</a> '
'%(clear_template)s<br />%(input_text)s: %(input)s'
)
from sapl.utils import YES_NO_CHOICES, FileFieldCheckMixin,\
CustomImageCropWidget
error_messages = {

16
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: <a href="%(initial_url)s">%(initial)s</a> '
'%(clear_template)s<br />%(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

11
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'

Loading…
Cancel
Save