diff --git a/app/contrib/frontend/landpage/cms_plugins.py b/app/contrib/frontend/landpage/cms_plugins.py index 5548d4af..af64512e 100644 --- a/app/contrib/frontend/landpage/cms_plugins.py +++ b/app/contrib/frontend/landpage/cms_plugins.py @@ -1,12 +1,14 @@ from django import forms from django.db.models import Q +from django.contrib import admin + from cms.plugin_base import CMSPluginBase from cms.plugin_pool import plugin_pool from contrib.bonde.models import Community -from .models import Navbar, Footer +from .models import Navbar, CarouselBlock, CarouselItem, Footer from .forms import LayoutBlockForm, LayoutBlockPressureForm # from .layouts import Layout @@ -82,6 +84,32 @@ def render(self, context, instance, placeholder): return context +class CarouselItemInline(admin.StackedInline): + model = CarouselItem + fk_name = 'block' + + +@plugin_pool.register_plugin +class CarouselBlockPlugin(CMSPluginBase): + model = CarouselBlock + name = "Bloco de Carousel" + inlines = [CarouselItemInline] + render_template = "frontend/landpage/plugins/carousel.html" + + def render(self, context, instance, placeholder): + ctx = super().render(context, instance, placeholder) + items = instance.carousel_items.all() + + print("Items in render:", items) + + ctx.update({ + "title": instance.title, + "description": instance.description, + 'items': items, + }) + return ctx + + @plugin_pool.register_plugin class FooterPlugin(CMSPluginBase): name = "Rodapé (Padrão)" diff --git a/app/contrib/frontend/landpage/migrations/0008_auto_20231019_2300.py b/app/contrib/frontend/landpage/migrations/0008_auto_20231019_2300.py new file mode 100644 index 00000000..259b34d3 --- /dev/null +++ b/app/contrib/frontend/landpage/migrations/0008_auto_20231019_2300.py @@ -0,0 +1,69 @@ +# Generated by Django 3.2 on 2023-10-19 23:00 + +import colorfield.fields +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import filer.fields.image + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.FILER_IMAGE_MODEL), + ('cms', '0022_auto_20180620_1551'), + ('landpage', '0007_merge_0006_auto_20230821_2039_0006_auto_20230822_1436'), + ] + + operations = [ + migrations.CreateModel( + name='CarouselBlock', + fields=[ + ('cmsplugin_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='landpage_carouselblock', serialize=False, to='cms.cmsplugin')), + ('title', models.CharField(max_length=120, verbose_name='Título')), + ('description', models.CharField(blank=True, max_length=120, null=True, verbose_name='Descrição')), + ], + options={ + 'abstract': False, + }, + bases=('cms.cmsplugin',), + ), + migrations.AlterField( + model_name='block', + name='background_color', + field=colorfield.fields.ColorField(blank=True, default=None, image_field=None, max_length=25, null=True, samples=[('#FFFFFF', 'white'), ('#000000', 'black')]), + ), + migrations.AlterField( + model_name='footer', + name='background_color', + field=colorfield.fields.ColorField(blank=True, default=None, image_field=None, max_length=25, null=True, samples=[('#FFFFFF', 'white'), ('#000000', 'black')], verbose_name='Cor de fundo'), + ), + migrations.AlterField( + model_name='footer', + name='color', + field=colorfield.fields.ColorField(blank=True, default=None, image_field=None, max_length=25, null=True, samples=[('#FFFFFF', 'white'), ('#000000', 'black')], verbose_name='Cor da fonte'), + ), + migrations.AlterField( + model_name='navbar', + name='background_color', + field=colorfield.fields.ColorField(blank=True, default=None, image_field=None, max_length=25, null=True, samples=[('#FFFFFF', 'white'), ('#000000', 'black')], verbose_name='Cor de fundo'), + ), + migrations.AlterField( + model_name='navbar', + name='color', + field=colorfield.fields.ColorField(blank=True, default=None, image_field=None, max_length=25, null=True, samples=[('#FFFFFF', 'white'), ('#000000', 'black')], verbose_name='Cor da fonte'), + ), + migrations.CreateModel( + name='CarouselItem', + fields=[ + ('cmsplugin_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='landpage_carouselitem', serialize=False, to='cms.cmsplugin')), + ('text', models.TextField(verbose_name='Texto do item')), + ('block', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='carousel_items', to='landpage.carouselblock')), + ('image', filer.fields.image.FilerImageField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.FILER_IMAGE_MODEL, verbose_name='Imagem do item')), + ], + options={ + 'abstract': False, + }, + bases=('cms.cmsplugin',), + ), + ] diff --git a/app/contrib/frontend/landpage/models.py b/app/contrib/frontend/landpage/models.py index ad72200d..aafaf11f 100644 --- a/app/contrib/frontend/landpage/models.py +++ b/app/contrib/frontend/landpage/models.py @@ -118,8 +118,25 @@ class Meta: abstract = False +class CarouselBlock(CMSPlugin): + title = models.CharField("Título", max_length=120) + description = models.CharField("Descrição", max_length=120, null=True, blank=True) + + def copy_relations(self, oldinstance): + self.carousel_items.all().delete() + + for carousel_item in oldinstance.carousel_items.all(): + carousel_item.pk = None + carousel_item.block = self + carousel_item.save() + + +class CarouselItem(CMSPlugin): + block = models.ForeignKey(CarouselBlock, related_name='carousel_items', on_delete=models.CASCADE) + image = FilerImageField(verbose_name="Imagem do item", null=True, blank=True, on_delete=models.SET_NULL) + text = models.TextField("Texto do item") + + class Footer(BlockElementStyled, CMSPlugin): class Meta: abstract = False - - diff --git a/app/contrib/frontend/landpage/templates/frontend/landpage/plugins/carousel.html b/app/contrib/frontend/landpage/templates/frontend/landpage/plugins/carousel.html new file mode 100644 index 00000000..aaf32531 --- /dev/null +++ b/app/contrib/frontend/landpage/templates/frontend/landpage/plugins/carousel.html @@ -0,0 +1,67 @@ +{% load cms_tags sekizai_tags static %} + +{% addtoblock "css" %} + +{% endaddtoblock %} + + + + {% if title or description %} + + {% if title %} + {{ title }} + {% endif %} + {% if description %} + {{ description }} + {% endif %} + + {% endif %} + + + + + {% for item in items %} + + + {{ item.text }} + + {% endfor %} + + + + + + + + +{% addtoblock "js" %} + + +{% endaddtoblock %} diff --git a/app/project/settings/cms.py b/app/project/settings/cms.py index ab3ad2ec..fddc16e1 100644 --- a/app/project/settings/cms.py +++ b/app/project/settings/cms.py @@ -12,7 +12,7 @@ CMS_PLACEHOLDER_CONF = { "content": { "name": "Blocos", - "plugins": ["BlockPlugin", "BlockPressurePlugin", "EleicaoCandidateListPlugin", "EleicaoCarouselPlugin", "EleicaoVoterFormPlugin"], + "plugins": ["BlockPlugin", "BlockPressurePlugin", "CarouselBlockPlugin", "EleicaoCandidateListPlugin", "EleicaoCarouselPlugin", "EleicaoVoterFormPlugin"], }, "navigation": { "name": "Navegação",
{{ description }}
{{ item.text }}