From 4447e4b523eccb09afe58d4cbbf8fed81cbd6f05 Mon Sep 17 00:00:00 2001 From: miguelzinh3 Date: Thu, 11 Jan 2024 19:42:31 -0300 Subject: [PATCH] feat: add bootstrap grid plugin with choices --- .../migrations/0002_auto_20240111_2048.py | 23 +++++ app/nossas/plugins/cms_plugins/grid.py | 22 ++++- app/nossas/plugins/migrations/0002_grid.py | 27 +++++ .../migrations/0003_auto_20240111_2218.py | 40 ++++++++ .../migrations/0004_auto_20240111_2221.py | 33 +++++++ app/nossas/plugins/models/gridmodel.py | 99 +++++++++++++++++++ .../templates/nossas/plugins/column.html | 7 ++ .../templates/nossas/plugins/grid.html | 10 +- 8 files changed, 256 insertions(+), 5 deletions(-) create mode 100644 app/nossas/apps/institutional/migrations/0002_auto_20240111_2048.py create mode 100644 app/nossas/plugins/migrations/0002_grid.py create mode 100644 app/nossas/plugins/migrations/0003_auto_20240111_2218.py create mode 100644 app/nossas/plugins/migrations/0004_auto_20240111_2221.py create mode 100644 app/nossas/plugins/models/gridmodel.py create mode 100644 app/nossas/plugins/templates/nossas/plugins/column.html diff --git a/app/nossas/apps/institutional/migrations/0002_auto_20240111_2048.py b/app/nossas/apps/institutional/migrations/0002_auto_20240111_2048.py new file mode 100644 index 000000000..ed9014432 --- /dev/null +++ b/app/nossas/apps/institutional/migrations/0002_auto_20240111_2048.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2 on 2024-01-11 20:48 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('institutional', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='institutionalinformation', + name='contact_phone', + field=models.CharField(max_length=16, verbose_name='Telefone de contato'), + ), + migrations.AlterField( + model_name='institutionalinformation', + name='zipcode', + field=models.CharField(max_length=9, verbose_name='CEP'), + ), + ] diff --git a/app/nossas/plugins/cms_plugins/grid.py b/app/nossas/plugins/cms_plugins/grid.py index 2e8c49b28..00fbaa3c8 100644 --- a/app/nossas/plugins/cms_plugins/grid.py +++ b/app/nossas/plugins/cms_plugins/grid.py @@ -1,9 +1,29 @@ from cms.plugin_base import CMSPluginBase from cms.plugin_pool import plugin_pool +from nossas.plugins.models.gridmodel import Grid, Column @plugin_pool.register_plugin class BootstrapGridPlugin(CMSPluginBase): name = "Grid" module = "NOSSAS" - render_template = "nossas/plugins/grid.html" \ No newline at end of file + model = Grid + render_template = "nossas/plugins/grid.html" + allow_children = True + child_classes = [ + "BootstrapColumnPlugin" + ] + + +@plugin_pool.register_plugin +class BootstrapColumnPlugin(CMSPluginBase): + name = "Coluna" + module = "NOSSAS" + model = Column + render_template = "nossas/plugins/column.html" + allow_children = True + + def render(self, context, instance, placeholder): + parent_instance = instance.parent.get_plugin_instance()[0] + context['parent_instance'] = parent_instance + return super().render(context, instance, placeholder) \ No newline at end of file diff --git a/app/nossas/plugins/migrations/0002_grid.py b/app/nossas/plugins/migrations/0002_grid.py new file mode 100644 index 000000000..a35bdc07c --- /dev/null +++ b/app/nossas/plugins/migrations/0002_grid.py @@ -0,0 +1,27 @@ +# Generated by Django 3.2 on 2024-01-11 20:48 + +from django.db import migrations, models +import django.db.models.deletion +import nossas.design.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cms', '0022_auto_20180620_1551'), + ('plugins', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Grid', + fields=[ + ('cmsplugin_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='plugins_grid', serialize=False, to='cms.cmsplugin')), + ('attributes', models.JSONField(blank=True, null=True)), + ], + options={ + 'abstract': False, + }, + bases=(nossas.design.models.UIBackgroundMixin, 'cms.cmsplugin'), + ), + ] diff --git a/app/nossas/plugins/migrations/0003_auto_20240111_2218.py b/app/nossas/plugins/migrations/0003_auto_20240111_2218.py new file mode 100644 index 000000000..2976e881c --- /dev/null +++ b/app/nossas/plugins/migrations/0003_auto_20240111_2218.py @@ -0,0 +1,40 @@ +# Generated by Django 3.2 on 2024-01-11 22:18 + +from django.db import migrations, models +import django.db.models.deletion +import nossas.design.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cms', '0022_auto_20180620_1551'), + ('plugins', '0002_grid'), + ] + + operations = [ + migrations.CreateModel( + name='Column', + fields=[ + ('cmsplugin_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='plugins_column', serialize=False, to='cms.cmsplugin')), + ('attributes', models.JSONField(blank=True, null=True)), + ('col', models.CharField(choices=[('', 'Auto'), ('g-col-1', 'Col 1'), ('g-col-2', 'Col 2'), ('g-col-3', 'Col 3'), ('g-col-4', 'Col 4'), ('g-col-5', 'Col 5'), ('g-col-6', 'Col 6'), ('g-col-7', 'Col 7'), ('g-col-8', 'Col 8'), ('g-col-9', 'Col 9'), ('g-col-10', 'Col 10'), ('g-col-11', 'Col 11'), ('g-col-12', 'Col 12')], default='', help_text='Defina manualmente o número de colunas que esta coluna ocupará.', max_length=15, verbose_name='Coluna')), + ('rows', models.CharField(choices=[('', 'Auto'), ('grid-row: 2', 'Linha 2'), ('grid-row: 3', 'Linha 3'), ('grid-row: 4', 'Linha 4')], default='', help_text='Escolha manualmente o número da linha que esta coluna ocupará.', max_length=15, verbose_name='Linhas')), + ('col_start_at', models.CharField(choices=[('', 'Auto'), ('g-start-1', 'Start at Col 1'), ('g-start-2', 'Start at Col 2'), ('g-start-3', 'Start at Col 3'), ('g-start-4', 'Start at Col 4'), ('g-start-5', 'Start at Col 5'), ('g-start-6', 'Start at Col 6'), ('g-start-7', 'Start at Col 7'), ('g-start-8', 'Start at Col 8'), ('g-start-9', 'Start at Col 9'), ('g-start-10', 'Start at Col 10'), ('g-start-11', 'Start at Col 11'), ('g-start-12', 'Start at Col 12')], default='', help_text='Defina em qual coluna o elemento deve iniciar.', max_length=30, verbose_name='Alinhamento horizontal da coluna')), + ], + options={ + 'abstract': False, + }, + bases=(nossas.design.models.UIBackgroundMixin, 'cms.cmsplugin'), + ), + migrations.AddField( + model_name='grid', + name='grid_gap', + field=models.CharField(choices=[('row-gap: 0;', 'Sem espaçamento'), ('row-gap: 4;', 'Pequeno'), ('row-gap: 8;', 'Grande')], default='row-gap: 0;', help_text='Selecione o espaço entre colunas do Grid.', max_length=15, verbose_name='Espaçamento do Grid'), + ), + migrations.AddField( + model_name='grid', + name='grid_layout', + field=models.CharField(choices=[('', 'Auto'), ('g-col-12', '1 Coluna'), ('g-col-12 g-col-md-6', '2 Colunas'), ('g-col-12 g-col-md-4', '3 Colunas'), ('g-col-12 g-col-sm-2 g-col-4', '4 Colunas'), ('g-col-12 g-col-sm-2 g-col-2', '6 Colunas'), ('g-col-12 g-col-sm-2 g-col-1', '12 Colunas')], default='', help_text="Escolha 'Auto' para um layout responsivo automático ou para selecionar o número de colunas manualmente.", max_length=80, verbose_name='Layout do Grid'), + ), + ] diff --git a/app/nossas/plugins/migrations/0004_auto_20240111_2221.py b/app/nossas/plugins/migrations/0004_auto_20240111_2221.py new file mode 100644 index 000000000..1ebbd1d35 --- /dev/null +++ b/app/nossas/plugins/migrations/0004_auto_20240111_2221.py @@ -0,0 +1,33 @@ +# Generated by Django 3.2 on 2024-01-11 22:21 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('plugins', '0003_auto_20240111_2218'), + ] + + operations = [ + migrations.AlterField( + model_name='column', + name='col', + field=models.CharField(choices=[(' ', 'Auto'), ('g-col-1', 'Col 1'), ('g-col-2', 'Col 2'), ('g-col-3', 'Col 3'), ('g-col-4', 'Col 4'), ('g-col-5', 'Col 5'), ('g-col-6', 'Col 6'), ('g-col-7', 'Col 7'), ('g-col-8', 'Col 8'), ('g-col-9', 'Col 9'), ('g-col-10', 'Col 10'), ('g-col-11', 'Col 11'), ('g-col-12', 'Col 12')], default=' ', help_text='Defina manualmente o número de colunas que esta coluna ocupará.', max_length=15, verbose_name='Coluna'), + ), + migrations.AlterField( + model_name='column', + name='col_start_at', + field=models.CharField(choices=[(' ', 'Auto'), ('g-start-1', 'Start at Col 1'), ('g-start-2', 'Start at Col 2'), ('g-start-3', 'Start at Col 3'), ('g-start-4', 'Start at Col 4'), ('g-start-5', 'Start at Col 5'), ('g-start-6', 'Start at Col 6'), ('g-start-7', 'Start at Col 7'), ('g-start-8', 'Start at Col 8'), ('g-start-9', 'Start at Col 9'), ('g-start-10', 'Start at Col 10'), ('g-start-11', 'Start at Col 11'), ('g-start-12', 'Start at Col 12')], default=' ', help_text='Defina em qual coluna o elemento deve iniciar.', max_length=30, verbose_name='Alinhamento horizontal da coluna'), + ), + migrations.AlterField( + model_name='column', + name='rows', + field=models.CharField(choices=[(' ', 'Auto'), ('grid-row: 2', 'Linha 2'), ('grid-row: 3', 'Linha 3'), ('grid-row: 4', 'Linha 4')], default=' ', help_text='Escolha manualmente o número da linha que esta coluna ocupará.', max_length=15, verbose_name='Linhas'), + ), + migrations.AlterField( + model_name='grid', + name='grid_layout', + field=models.CharField(choices=[(' ', 'Auto'), ('g-col-12', '1 Coluna'), ('g-col-12 g-col-md-6', '2 Colunas'), ('g-col-12 g-col-md-4', '3 Colunas'), ('g-col-12 g-col-sm-2 g-col-4', '4 Colunas'), ('g-col-12 g-col-sm-2 g-col-2', '6 Colunas'), ('g-col-12 g-col-sm-2 g-col-1', '12 Colunas')], default=' ', help_text="Escolha 'Auto' para um layout responsivo automático ou para selecionar o número de colunas manualmente.", max_length=80, verbose_name='Layout do Grid'), + ), + ] diff --git a/app/nossas/plugins/models/gridmodel.py b/app/nossas/plugins/models/gridmodel.py new file mode 100644 index 000000000..853e7bdb9 --- /dev/null +++ b/app/nossas/plugins/models/gridmodel.py @@ -0,0 +1,99 @@ +from django.db import models +from nossas.design.models import UICMSPlugin, UIBackgroundMixin + + +class GridLayoutChoices(models.TextChoices): + grid_auto = " ", "Auto" + grid_1 = "g-col-12", "1 Coluna" + grid_2 = "g-col-12 g-col-md-6", "2 Colunas" + grid_3 = "g-col-12 g-col-md-4", "3 Colunas" + grid_4 = "g-col-12 g-col-sm-2 g-col-4", "4 Colunas" + grid_6 = "g-col-12 g-col-sm-2 g-col-2", "6 Colunas" + grid_12 = "g-col-12 g-col-sm-2 g-col-1", "12 Colunas" + + +class GridSpacingChoices(models.TextChoices): + gap_0 = "row-gap: 0;", "Sem espaçamento" + gap_4 = "row-gap: 4;", "Pequeno" + gap_8 = "row-gap: 8;", "Grande" + + +class Grid(UIBackgroundMixin, UICMSPlugin): + grid_layout = models.CharField( + "Layout do Grid", + max_length=80, + default=GridLayoutChoices.grid_auto, + choices=GridLayoutChoices.choices, + help_text="Escolha 'Auto' para um layout responsivo automático ou para selecionar o número de colunas manualmente.", + ) + grid_gap = models.CharField( + "Espaçamento do Grid", + default=GridSpacingChoices.gap_0, + choices=GridSpacingChoices.choices, + max_length=15, + help_text="Selecione o espaço entre colunas do Grid.", + ) + + +class ColumnChoices(models.TextChoices): + auto = " ", "Auto" + col_1 = "g-col-1", "Col 1" + col_2 = "g-col-2", "Col 2" + col_3 = "g-col-3", "Col 3" + col_4 = "g-col-4", "Col 4" + col_5 = "g-col-5", "Col 5" + col_6 = "g-col-6", "Col 6" + col_7 = "g-col-7", "Col 7" + col_8 = "g-col-8", "Col 8" + col_9 = "g-col-9", "Col 9" + col_10 = "g-col-10", "Col 10" + col_11 = "g-col-11", "Col 11" + col_12 = "g-col-12", "Col 12" + + +class RowChoices(models.TextChoices): + auto = " ", "Auto" + row_1 = "grid-row: 2", "Linha 2" + row_2 = "grid-row: 3", "Linha 3" + row_3 = "grid-row: 4", "Linha 4" + + +class ColumnStartAtChoices(models.TextChoices): + auto = " ", "Auto" + g_start_1 = "g-start-1", "Start at Col 1" + g_start_2 = "g-start-2", "Start at Col 2" + g_start_3 = "g-start-3", "Start at Col 3" + g_start_4 = "g-start-4", "Start at Col 4" + g_start_5 = "g-start-5", "Start at Col 5" + g_start_6 = "g-start-6", "Start at Col 6" + g_start_7 = "g-start-7", "Start at Col 7" + g_start_8 = "g-start-8", "Start at Col 8" + g_start_9 = "g-start-9", "Start at Col 9" + g_start_10 = "g-start-10", "Start at Col 10" + g_start_11 = "g-start-11", "Start at Col 11" + g_start_12 = "g-start-12", "Start at Col 12" + + +class Column(UIBackgroundMixin, UICMSPlugin): + col = models.CharField( + "Coluna", + choices=ColumnChoices.choices, + default=ColumnChoices.auto, + max_length=15, + help_text="Defina manualmente o número de colunas que esta coluna ocupará.", + ) + rows = models.CharField( + "Linhas", + choices=RowChoices.choices, + default=RowChoices.auto, + max_length=15, + help_text="Escolha manualmente o número da linha que esta coluna ocupará.", + ) + col_start_at = models.CharField( + "Alinhamento horizontal da coluna", + choices=ColumnStartAtChoices.choices, + default=ColumnStartAtChoices.auto, + max_length=30, + help_text="Defina em qual coluna o elemento deve iniciar.", + + ) diff --git a/app/nossas/plugins/templates/nossas/plugins/column.html b/app/nossas/plugins/templates/nossas/plugins/column.html new file mode 100644 index 000000000..5a2cb4c98 --- /dev/null +++ b/app/nossas/plugins/templates/nossas/plugins/column.html @@ -0,0 +1,7 @@ +{% load cms_tags %} + +
+ {% for plugin in instance.child_plugin_instances %} + {% render_plugin plugin %} + {% endfor %} +
diff --git a/app/nossas/plugins/templates/nossas/plugins/grid.html b/app/nossas/plugins/templates/nossas/plugins/grid.html index 50f57503c..2b1530d20 100644 --- a/app/nossas/plugins/templates/nossas/plugins/grid.html +++ b/app/nossas/plugins/templates/nossas/plugins/grid.html @@ -1,5 +1,7 @@ -
-
.g-col-4
-
.g-col-4
-
.g-col-4
+{% load cms_tags %} + +
+{% for plugin in instance.child_plugin_instances %} + {% render_plugin plugin %} +{% endfor %}