From 9ca4065a06548bde0cd4725212fbd38a47538e44 Mon Sep 17 00:00:00 2001 From: Jusbrasil Date: Fri, 10 May 2024 17:53:46 -0300 Subject: [PATCH 1/8] feat(ds): add background image to block component --- app/contrib/ds/blocks/cms_plugins.py | 3 ++- app/contrib/ds/blocks/forms.py | 4 +++- app/contrib/ds/blocks/models.py | 7 +++++++ .../ds/blocks/templates/blocks/plugin/change_form.html | 8 +++++++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/contrib/ds/blocks/cms_plugins.py b/app/contrib/ds/blocks/cms_plugins.py index 595e7e62..76705cec 100644 --- a/app/contrib/ds/blocks/cms_plugins.py +++ b/app/contrib/ds/blocks/cms_plugins.py @@ -27,7 +27,7 @@ class BlockPlugin(CMSPluginBase): ), ( _("Estrutura"), - {"fields": (("element", "layout", "is_container"),)}, + {"fields": (("element", "layout", "is_container", "background_image"),)}, ), ( None, @@ -116,6 +116,7 @@ def render(self, context, instance, placeholder): if instance.attributes else None ) + if background_color: css_styles.append(f"background-color:{background_color}") diff --git a/app/contrib/ds/blocks/forms.py b/app/contrib/ds/blocks/forms.py index 84974e8b..752246bb 100644 --- a/app/contrib/ds/blocks/forms.py +++ b/app/contrib/ds/blocks/forms.py @@ -5,6 +5,7 @@ from colorfield.widgets import ColorWidget from django_jsonform.forms.fields import JSONFormField from entangled.forms import EntangledModelFormMixin +from filer.fields.image import FilerImageField from .models import ( Block, @@ -111,6 +112,7 @@ class BlockForm( ContainerFormMixin, forms.ModelForm, ): + template = forms.CharField(widget=forms.HiddenInput(), required=False) class Meta: @@ -137,7 +139,7 @@ class BlockTemplateForm(BlockForm): class Meta: model = Block - untangled_fields = ["template", "element", "layout", "is_container"] + untangled_fields = ["template", "element", "layout", "is_container", "background_image"] entangled_fields = {"attributes": []} def __init__(self, *args, **kwargs): diff --git a/app/contrib/ds/blocks/models.py b/app/contrib/ds/blocks/models.py index bb8122a3..df9849f3 100644 --- a/app/contrib/ds/blocks/models.py +++ b/app/contrib/ds/blocks/models.py @@ -2,6 +2,7 @@ from django.utils.translation import gettext_lazy as _ from cms.models import CMSPlugin +from filer.fields.image import FilerImageField class AlignmentItems(models.TextChoices): @@ -75,6 +76,12 @@ class BlockAbstractModel(models.Model): verbose_name=_("Container"), default=False, ) + background_image = FilerImageField( + verbose_name=("Imagem de fundo"), + blank=True, + null=True, + on_delete=models.SET_NULL, + ) attributes = models.JSONField(null=True, blank=True) class Meta: diff --git a/app/contrib/ds/blocks/templates/blocks/plugin/change_form.html b/app/contrib/ds/blocks/templates/blocks/plugin/change_form.html index 1c042c84..2348b99e 100644 --- a/app/contrib/ds/blocks/templates/blocks/plugin/change_form.html +++ b/app/contrib/ds/blocks/templates/blocks/plugin/change_form.html @@ -121,7 +121,13 @@

Estrutura

{% endwith %} - + {% with field=adminform.form.backgound_image %} +
+ + {{ field.help_text }} + {{field}} +
+ {% endwith %}
{% with field=adminform.form.background_color %}
From 57e74f26c6c26259f80ce360fa34c6dcf33668f8 Mon Sep 17 00:00:00 2001 From: Mario Sergio Date: Fri, 10 May 2024 17:56:56 -0300 Subject: [PATCH 2/8] feat(ds): included image background migration --- .../migrations/0006_block_background_image.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 app/contrib/ds/blocks/migrations/0006_block_background_image.py diff --git a/app/contrib/ds/blocks/migrations/0006_block_background_image.py b/app/contrib/ds/blocks/migrations/0006_block_background_image.py new file mode 100644 index 00000000..39cc99e2 --- /dev/null +++ b/app/contrib/ds/blocks/migrations/0006_block_background_image.py @@ -0,0 +1,22 @@ +# Generated by Django 4.2 on 2024-05-10 20:44 + +from django.conf import settings +from django.db import migrations +import django.db.models.deletion +import filer.fields.image + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.FILER_IMAGE_MODEL), + ('blocks', '0005_alter_block_options_alter_block_element_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='block', + name='background_image', + field=filer.fields.image.FilerImageField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.FILER_IMAGE_MODEL, verbose_name='Imagem de fundo'), + ), + ] From 48153c1190fc4d762ba92f34e67fbae3569385e9 Mon Sep 17 00:00:00 2001 From: Mario Sergio Date: Tue, 14 May 2024 11:56:28 -0300 Subject: [PATCH 3/8] feat(ds): adjusts on background image layout --- app/contrib/ds/blocks/forms.py | 3 +++ .../templates/blocks/plugin/change_form.html | 18 ++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/contrib/ds/blocks/forms.py b/app/contrib/ds/blocks/forms.py index 752246bb..31bab008 100644 --- a/app/contrib/ds/blocks/forms.py +++ b/app/contrib/ds/blocks/forms.py @@ -141,6 +141,9 @@ class Meta: model = Block untangled_fields = ["template", "element", "layout", "is_container", "background_image"] entangled_fields = {"attributes": []} + help_texts = { + 'background_image': 'Selecione uma imagem para o background do bloco.' + } def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/app/contrib/ds/blocks/templates/blocks/plugin/change_form.html b/app/contrib/ds/blocks/templates/blocks/plugin/change_form.html index 2348b99e..256c99f4 100644 --- a/app/contrib/ds/blocks/templates/blocks/plugin/change_form.html +++ b/app/contrib/ds/blocks/templates/blocks/plugin/change_form.html @@ -121,21 +121,13 @@

Estrutura

{% endwith %} - {% with field=adminform.form.backgound_image %} + {% with field=adminform.form.background_image %}
{{ field.help_text }} {{field}}
{% endwith %} -
- {% with field=adminform.form.background_color %} -
- - {{ field.help_text }} - {{field}} -
- {% endwith %} {% comment %} Espaçamento {% endcomment %}
@@ -150,7 +142,13 @@

Estrutura

{{ adminform.form.padding_bottom }}
- + {% with field=adminform.form.background_color %} +
+ + {{ field.help_text }} + {{field}} +
+ {% endwith %}
From bb76b1be5c100bfc6c424ee2d5cee0d073aa7b21 Mon Sep 17 00:00:00 2001 From: Mario Sergio Date: Wed, 15 May 2024 17:07:40 -0300 Subject: [PATCH 4/8] feat(ds): implemented test to background image component --- app/contrib/ds/blocks/cms_plugins.py | 3 +++ .../ds/blocks/tests/test_render_plugins.py | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/app/contrib/ds/blocks/cms_plugins.py b/app/contrib/ds/blocks/cms_plugins.py index 76705cec..f3684e6b 100644 --- a/app/contrib/ds/blocks/cms_plugins.py +++ b/app/contrib/ds/blocks/cms_plugins.py @@ -119,6 +119,9 @@ def render(self, context, instance, placeholder): if background_color: css_styles.append(f"background-color:{background_color}") + + if instance.background_image: + css_styles.append(f"background-image:url('{instance.background_image.url}')") padding_attrs = [("padding_top", "pt"), ("padding_bottom", "pb"), ("padding_left", "pl"), ("padding_right", "pr")] diff --git a/app/contrib/ds/blocks/tests/test_render_plugins.py b/app/contrib/ds/blocks/tests/test_render_plugins.py index e404921e..fcaec3f1 100644 --- a/app/contrib/ds/blocks/tests/test_render_plugins.py +++ b/app/contrib/ds/blocks/tests/test_render_plugins.py @@ -7,6 +7,7 @@ from ..cms_plugins import BlockPlugin from ..forms import BlockForm, BlockTemplateForm from ..models import BlockElement, BlockLayout +from contrib.ds.tests.helpers import get_filer_image # Create your tests here. @@ -21,10 +22,18 @@ def setUp(self): self.placeholder = self.home.placeholders.get(slot="content") self.superuser = self.get_superuser() + self.image = get_filer_image() + def tearDown(self): self.home.delete() self.superuser.delete() + if self.image: + self.image.delete() + del self.image + with self.assertRaises(AttributeError): + print(self.image) + def test_block_plugin(self): plugin = add_plugin( placeholder=self.placeholder, @@ -365,3 +374,19 @@ def test_setup_initial_fields_on_template_block_form(self): self.assertEqual(form.fields["is_container"].initial, True) self.assertEqual(form.fields["padding_top"].initial, "4") self.assertEqual(form.fields["padding_bottom"].initial, "4") + + def test_background_image_block_render_html(self): + model_instance = add_plugin( + placeholder=self.placeholder, + plugin_type="BlockPlugin", + language=self.language, + background_image=self.image, + ) + model_instance.full_clean() + + renderer = ContentRenderer(request=RequestFactory()) + + html = renderer.render_plugin(model_instance, {}) + expected_html = f"""
""" + + self.assertHTMLEqual(html, expected_html) \ No newline at end of file From 6b6e226a6ea9835b88a7755d86d05856c4d05d7e Mon Sep 17 00:00:00 2001 From: Mario Sergio Date: Wed, 15 May 2024 18:30:40 -0300 Subject: [PATCH 5/8] feat(ds) implemented image size component on blocks --- app/contrib/ds/blocks/cms_plugins.py | 3 + app/contrib/ds/blocks/forms.py | 2 +- .../migrations/0007_block_background_size.py | 18 +++ app/contrib/ds/blocks/models.py | 10 ++ .../templates/blocks/plugin/change_form.html | 21 ++- .../ds/blocks/tests/test_render_plugins.py | 3 +- app/contrib/ds/tests/helpers.py | 123 ++++++++++++++++++ 7 files changed, 171 insertions(+), 9 deletions(-) create mode 100644 app/contrib/ds/blocks/migrations/0007_block_background_size.py create mode 100644 app/contrib/ds/tests/helpers.py diff --git a/app/contrib/ds/blocks/cms_plugins.py b/app/contrib/ds/blocks/cms_plugins.py index f3684e6b..f4dbbfe7 100644 --- a/app/contrib/ds/blocks/cms_plugins.py +++ b/app/contrib/ds/blocks/cms_plugins.py @@ -122,6 +122,9 @@ def render(self, context, instance, placeholder): if instance.background_image: css_styles.append(f"background-image:url('{instance.background_image.url}')") + css_styles.append(f"background-size:{instance.background_size}") + css_styles.append("background-repeat:no-repeat") + css_styles.append("background-position:center") padding_attrs = [("padding_top", "pt"), ("padding_bottom", "pb"), ("padding_left", "pl"), ("padding_right", "pr")] diff --git a/app/contrib/ds/blocks/forms.py b/app/contrib/ds/blocks/forms.py index 31bab008..4f7cd6d0 100644 --- a/app/contrib/ds/blocks/forms.py +++ b/app/contrib/ds/blocks/forms.py @@ -139,7 +139,7 @@ class BlockTemplateForm(BlockForm): class Meta: model = Block - untangled_fields = ["template", "element", "layout", "is_container", "background_image"] + untangled_fields = ["template", "element", "layout", "is_container", "background_image", "background_size"] entangled_fields = {"attributes": []} help_texts = { 'background_image': 'Selecione uma imagem para o background do bloco.' diff --git a/app/contrib/ds/blocks/migrations/0007_block_background_size.py b/app/contrib/ds/blocks/migrations/0007_block_background_size.py new file mode 100644 index 00000000..fa3b1c89 --- /dev/null +++ b/app/contrib/ds/blocks/migrations/0007_block_background_size.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2 on 2024-05-15 20:47 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('blocks', '0006_block_background_image'), + ] + + operations = [ + migrations.AddField( + model_name='block', + name='background_size', + field=models.CharField(choices=[('contain', 'Contain'), ('cover', 'Cover'), ('initial', 'Initial')], default='contain', max_length=8), + ), + ] diff --git a/app/contrib/ds/blocks/models.py b/app/contrib/ds/blocks/models.py index df9849f3..9bb06fce 100644 --- a/app/contrib/ds/blocks/models.py +++ b/app/contrib/ds/blocks/models.py @@ -43,6 +43,11 @@ class BlockLayout(models.TextChoices): grid = "grid", _("Em grade") flex = "d-flex", _("Flexível") +class BackgroundSize(models.TextChoices): + contain = "contain" + cover = "cover" + initial = "initial" + class BlockAbstractModel(models.Model): """ @@ -82,6 +87,11 @@ class BlockAbstractModel(models.Model): null=True, on_delete=models.SET_NULL, ) + background_size = models.CharField( + choices=BackgroundSize.choices, + max_length=8, + default=BackgroundSize.contain + ) attributes = models.JSONField(null=True, blank=True) class Meta: diff --git a/app/contrib/ds/blocks/templates/blocks/plugin/change_form.html b/app/contrib/ds/blocks/templates/blocks/plugin/change_form.html index 256c99f4..dda11c7b 100644 --- a/app/contrib/ds/blocks/templates/blocks/plugin/change_form.html +++ b/app/contrib/ds/blocks/templates/blocks/plugin/change_form.html @@ -128,6 +128,20 @@

Estrutura

{{field}} {% endwith %} + {% with field=adminform.form.background_size %} +
+ + {{ field.help_text }} + {{field}} +
+ {% endwith %} + {% with field=adminform.form.background_color %} +
+ + {{ field.help_text }} + {{field}} +
+ {% endwith %} {% comment %} Espaçamento {% endcomment %}
@@ -142,13 +156,6 @@

Estrutura

{{ adminform.form.padding_bottom }}
- {% with field=adminform.form.background_color %} -
- - {{ field.help_text }} - {{field}} -
- {% endwith %}
diff --git a/app/contrib/ds/blocks/tests/test_render_plugins.py b/app/contrib/ds/blocks/tests/test_render_plugins.py index fcaec3f1..91dd9558 100644 --- a/app/contrib/ds/blocks/tests/test_render_plugins.py +++ b/app/contrib/ds/blocks/tests/test_render_plugins.py @@ -23,6 +23,7 @@ def setUp(self): self.superuser = self.get_superuser() self.image = get_filer_image() + self.background_size = "contain" def tearDown(self): self.home.delete() @@ -387,6 +388,6 @@ def test_background_image_block_render_html(self): renderer = ContentRenderer(request=RequestFactory()) html = renderer.render_plugin(model_instance, {}) - expected_html = f"""
""" + expected_html = f"""
""" self.assertHTMLEqual(html, expected_html) \ No newline at end of file diff --git a/app/contrib/ds/tests/helpers.py b/app/contrib/ds/tests/helpers.py new file mode 100644 index 00000000..277e8fd5 --- /dev/null +++ b/app/contrib/ds/tests/helpers.py @@ -0,0 +1,123 @@ +import os +from tempfile import mkdtemp + +from django.core.files import File + +from filer.models.filemodels import File as FilerFile +from filer.models.foldermodels import Folder as FilerFolder +from filer.models.imagemodels import Image as FilerImage +from filer.utils.compatibility import PILImage, PILImageDraw + + +# from https://github.com/divio/django-filer/blob/develop/tests/helpers.py#L46-L52 +def create_image(mode="RGB", size=(800, 600)): + """ + Creates a usable image file using PIL + :returns: PIL Image instance + """ + image = PILImage.new(mode, size) + draw = PILImageDraw.Draw(image) + x_bit, y_bit = size[0] // 10, size[1] // 10 + draw.rectangle((x_bit, y_bit * 2, x_bit * 7, y_bit * 3), "red") + draw.rectangle((x_bit * 2, y_bit, x_bit * 3, y_bit * 8), "red") + + return image + + +def get_image(image_name="test_file.jpg", size=(800, 600)): + """ + Creates and stores an image to the file system using PILImage + + :param image_name: the name for the file (default "test_file.jpg") + :returns: dict {name, image, path} + """ + image = create_image(size=size) + image_path = os.path.join( + mkdtemp(), + image_name, + ) + image.save(image_path, "JPEG") + + return { + "name": image_name, + "image": image, + "path": image_path, + } + + +def get_file(file_name="test_file.pdf"): + """ + Creates and stores an arbitrary file into a temporary dir + + :param file_name: the name for the file (default "test_file.pdf") + :returns: dict {name, image, path} + """ + file_path = os.path.join( + mkdtemp(), + file_name, + ) + data = open(file_path, "a") + + return { + "name": file_name, + "file": data, + "path": file_path, + } + + +def get_filer_image(image_name="test_file.jpg", size=(800, 600)): + """ + Creates and stores an image to filer and returns it + + :param image_name: the name for the file (default "test_file.jpg") + :returns: filer image instance + """ + image = get_image(image_name, size) + filer_file = File( + open(image.get("path"), "rb"), + name=image.get("name"), + ) + filer_object = FilerImage.objects.create( + original_filename=image.get("name"), + file=filer_file, + ) + + return filer_object + + +def get_filer_file(file_name="test_file.pdf", folder=None): + """ + Creates and stores a file to filer and returns it + + :param file_name: the name for the file (default "test_file.pdf") + :param folder: optionally provide a folder instance + :returns: filer file instance + """ + data = get_file(file_name) + filer_file = File( + open(data.get("path"), "rb"), + name=data.get("name"), + ) + filer_object = FilerFile.objects.create( + original_filename=data.get("name"), + file=filer_file, + folder=folder, + ) + + return filer_object + + +def get_filer_folder(folder_name="test_folder", parent=None): + """ + Creates and returns a filer folder + + :param folder_name: the name of the folder to be used (default "test_folder") + :param parent: optionally provide a parent folder + :returns: filer folder instance + """ + filer_object = FilerFolder.objects.create( + parent=parent, + name=folder_name, + ) + + return filer_object \ No newline at end of file From b8c69ce06c1b0d9eeaf3eab44c54913e2dc107a8 Mon Sep 17 00:00:00 2001 From: Igor Santos Date: Thu, 16 May 2024 11:42:55 -0300 Subject: [PATCH 6/8] feat(ds): add custom template style django-filer --- app/adp/settings/base.py | 2 + app/contrib/ds/admin_style/__init__.py | 0 .../admin/filer/widgets/admin_file.html | 83 +++++++++++++++++++ app/contrib/ds/static/ds/css/change_form.scss | 12 ++- app/contrib/ds/static/ds/css/input_file.scss | 32 +++++++ 5 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 app/contrib/ds/admin_style/__init__.py create mode 100644 app/contrib/ds/admin_style/templates/admin/filer/widgets/admin_file.html create mode 100644 app/contrib/ds/static/ds/css/input_file.scss diff --git a/app/adp/settings/base.py b/app/adp/settings/base.py index 4603e43c..88295114 100644 --- a/app/adp/settings/base.py +++ b/app/adp/settings/base.py @@ -21,6 +21,8 @@ INSTALLED_APPS = [ # "admin_styled", # "tailwind", + # Override third apps templates + "contrib.ds.admin_style", "djangocms_admin_style", "django.contrib.admin", "django.contrib.auth", diff --git a/app/contrib/ds/admin_style/__init__.py b/app/contrib/ds/admin_style/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/app/contrib/ds/admin_style/templates/admin/filer/widgets/admin_file.html b/app/contrib/ds/admin_style/templates/admin/filer/widgets/admin_file.html new file mode 100644 index 00000000..e32b6056 --- /dev/null +++ b/app/contrib/ds/admin_style/templates/admin/filer/widgets/admin_file.html @@ -0,0 +1,83 @@ +{% load i18n filer_admin_tags static %} + +{% spaceless %} +
+
+ + + +
+
+
+ {% translate "or drop your file here" %} +
+ + +
+
+ {% if object %} + {% if object.file.exists %} + {% file_icon object size='80x80' %} +
+ {{ object.label }} + {% else %} +
+ {% file_icon object %} + {% translate 'File is missing' %} + {% endif %} + {% else %} + +   + {% endif %} + + + + + {% if object %} +
+ {% endif %} +
+ + +
+ +
+ + + + +
+
+{% endspaceless %} \ No newline at end of file diff --git a/app/contrib/ds/static/ds/css/change_form.scss b/app/contrib/ds/static/ds/css/change_form.scss index ef6db0f8..5af62426 100644 --- a/app/contrib/ds/static/ds/css/change_form.scss +++ b/app/contrib/ds/static/ds/css/change_form.scss @@ -43,10 +43,12 @@ fieldset.module { border: none; margin-bottom: 0; } +} - .field-padding { - grid-column: 2 / span 2; - } +.form-col-flex { + display: flex; + flex-direction: column; + gap: 20px; } .form-radio, .field-custom-radio-widget, .field-padding-widget, .field-radio-inline-widget, .field-gap-widget { @@ -247,4 +249,6 @@ input:checked + .slider:before { display: flex; gap: 10px; align-items: start; -} \ No newline at end of file +} + +@import "./input_file.scss"; \ No newline at end of file diff --git a/app/contrib/ds/static/ds/css/input_file.scss b/app/contrib/ds/static/ds/css/input_file.scss new file mode 100644 index 00000000..71790ad2 --- /dev/null +++ b/app/contrib/ds/static/ds/css/input_file.scss @@ -0,0 +1,32 @@ +.filer-dropzone * { + &.related-lookup:before, .replace-file .fa-search:before { + display: none; + } + + &.related-lookup { + width: auto; + height: 35px; + } +} + +.file-edit-area { + display: flex; + justify-content: space-between; + align-items: center; + + a { + display: flex; + align-items: flex-start; + } +} + +.file-controls { + display: flex; + flex-direction: row; +} + +.file-desc-object { + display: flex; + flex-direction: row; + gap: 10px; +} \ No newline at end of file From 3f28387907532b9780f6a7fad894cdbd8004d640 Mon Sep 17 00:00:00 2001 From: Igor Santos Date: Thu, 16 May 2024 11:44:12 -0300 Subject: [PATCH 7/8] fix(ds): add fields to background image on block forms --- app/contrib/ds/blocks/forms.py | 2 +- .../templates/blocks/plugin/change_form.html | 39 +++++++++++-------- app/contrib/ds/blocks/tests/test_forms.py | 28 +++++++++++++ 3 files changed, 51 insertions(+), 18 deletions(-) create mode 100644 app/contrib/ds/blocks/tests/test_forms.py diff --git a/app/contrib/ds/blocks/forms.py b/app/contrib/ds/blocks/forms.py index 4f7cd6d0..97c343ae 100644 --- a/app/contrib/ds/blocks/forms.py +++ b/app/contrib/ds/blocks/forms.py @@ -117,7 +117,7 @@ class BlockForm( class Meta: model = Block - untangled_fields = ["template", "element", "layout", "is_container"] + untangled_fields = ["template", "element", "layout", "is_container", "background_image", "background_size"] entangled_fields = {"attributes": []} diff --git a/app/contrib/ds/blocks/templates/blocks/plugin/change_form.html b/app/contrib/ds/blocks/templates/blocks/plugin/change_form.html index dda11c7b..c2c85a04 100644 --- a/app/contrib/ds/blocks/templates/blocks/plugin/change_form.html +++ b/app/contrib/ds/blocks/templates/blocks/plugin/change_form.html @@ -121,27 +121,31 @@

Estrutura

{% endwith %} - {% with field=adminform.form.background_image %} -
- - {{ field.help_text }} - {{field}} -
- {% endwith %} - {% with field=adminform.form.background_size %} -
- - {{ field.help_text }} - {{field}} -
- {% endwith %} - {% with field=adminform.form.background_color %} + +
+
+ {% with field=adminform.form.background_image %} +
+ + {{ field.help_text }} + {{field}} +
+ {% endwith %} + {% with field=adminform.form.background_size %}
- + {{ field.help_text }} {{field}}
- {% endwith %} + {% endwith %} + {% with field=adminform.form.background_color %} +
+ + {{ field.help_text }} + {{field}} +
+ {% endwith %} +
{% comment %} Espaçamento {% endcomment %}
@@ -156,6 +160,7 @@

Estrutura

{{ adminform.form.padding_bottom }}
+
diff --git a/app/contrib/ds/blocks/tests/test_forms.py b/app/contrib/ds/blocks/tests/test_forms.py new file mode 100644 index 00000000..86c85c33 --- /dev/null +++ b/app/contrib/ds/blocks/tests/test_forms.py @@ -0,0 +1,28 @@ +import pytest + +from django import forms + +from contrib.ds.blocks.forms import BlockForm, BlockTemplateForm + + +base_fields = [ + "template", + "element", + "layout", + "is_container", + "background_image", + "background_size", +] + + +def test_fields_block_tempalte_form(): + assert base_fields == BlockTemplateForm.Meta.untangled_fields + + +def test_fields_block_form(): + assert base_fields == BlockForm.Meta.untangled_fields + + +def test_template_hidden_on_block_form(): + form = BlockForm() + assert isinstance(form.fields["template"].widget, forms.HiddenInput) From 92e89540035c49d5177e29c642a12f2e02891a2e Mon Sep 17 00:00:00 2001 From: Mario Sergio Date: Thu, 16 May 2024 11:56:24 -0300 Subject: [PATCH 8/8] feat(ds) chanched default background size --- .../0008_alter_block_background_size.py | 18 ++++++++++++++++++ app/contrib/ds/blocks/models.py | 2 +- .../ds/blocks/tests/test_render_plugins.py | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 app/contrib/ds/blocks/migrations/0008_alter_block_background_size.py diff --git a/app/contrib/ds/blocks/migrations/0008_alter_block_background_size.py b/app/contrib/ds/blocks/migrations/0008_alter_block_background_size.py new file mode 100644 index 00000000..e23c8edf --- /dev/null +++ b/app/contrib/ds/blocks/migrations/0008_alter_block_background_size.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2 on 2024-05-16 14:53 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('blocks', '0007_block_background_size'), + ] + + operations = [ + migrations.AlterField( + model_name='block', + name='background_size', + field=models.CharField(choices=[('contain', 'Contain'), ('cover', 'Cover'), ('initial', 'Initial')], default='cover', max_length=8), + ), + ] diff --git a/app/contrib/ds/blocks/models.py b/app/contrib/ds/blocks/models.py index 9bb06fce..883aec7f 100644 --- a/app/contrib/ds/blocks/models.py +++ b/app/contrib/ds/blocks/models.py @@ -90,7 +90,7 @@ class BlockAbstractModel(models.Model): background_size = models.CharField( choices=BackgroundSize.choices, max_length=8, - default=BackgroundSize.contain + default=BackgroundSize.cover ) attributes = models.JSONField(null=True, blank=True) diff --git a/app/contrib/ds/blocks/tests/test_render_plugins.py b/app/contrib/ds/blocks/tests/test_render_plugins.py index 91dd9558..1494c78d 100644 --- a/app/contrib/ds/blocks/tests/test_render_plugins.py +++ b/app/contrib/ds/blocks/tests/test_render_plugins.py @@ -23,7 +23,7 @@ def setUp(self): self.superuser = self.get_superuser() self.image = get_filer_image() - self.background_size = "contain" + self.background_size = "cover" def tearDown(self): self.home.delete()