Skip to content

Commit

Permalink
refactor: add carousel plugin to landpage
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelzinh3 committed Oct 19, 2023
1 parent 0f3ec25 commit 9cebc0d
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 4 deletions.
30 changes: 29 additions & 1 deletion app/contrib/frontend/landpage/cms_plugins.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)"
Expand Down
Original file line number Diff line number Diff line change
@@ -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',),
),
]
21 changes: 19 additions & 2 deletions app/contrib/frontend/landpage/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{% load cms_tags sekizai_tags static %}

{% addtoblock "css" %}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@10/swiper-bundle.min.css" />
{% endaddtoblock %}

<section class="bg-[#024C2B] relative">
<div class="container px-5 py-28 mx-auto md:px-4">
{% if title or description %}
<div class="mb-6">
{% if title %}
<h2 class="text-4xl text-white text-center max-w-[620px] mx-auto mb-4">{{ title }}</h2>
{% endif %}
{% if description %}
<p class="text-white text-center max-w-[815px] mx-auto">{{ description }}</p>
{% endif %}
</div>
{% endif %}

<div class="swiper mySwiper md:min-h-[300px]">
<div class="swiper-wrapper">
<!-- Slides -->
{% for item in items %}
<div class="swiper-slide">
<img src="{{ item.image.url }}" alt="{{ item.text }}">
<p>{{ item.text }}</p>
</div>
{% endfor %}
</div>
</div>
<div class="swiper-pagination"></div>
<div class="swiper-button-prev mt-14 md:mx-5 md:mt-10"></div>
<div class="swiper-button-next mt-14 md:mx-5 md:mt-10"></div>
</div>
</section>

{% addtoblock "js" %}
<script src="https://cdn.jsdelivr.net/npm/swiper@10/swiper-bundle.min.js"></script>
<script>
var swiper = new Swiper(".mySwiper", {
slidesPerView: 1,
spaceBetween: 10,
pagination: {
el: ".swiper-pagination",
clickable: true,
},
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev",
},
breakpoints: {
640: {
slidesPerView: 2,
spaceBetween: 20,
},
768: {
slidesPerView: 4,
spaceBetween: 40,
},
1024: {
slidesPerView: 5,
spaceBetween: 50,
},
},
});
</script>
{% endaddtoblock %}
2 changes: 1 addition & 1 deletion app/project/settings/cms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 9cebc0d

Please sign in to comment.