From 711d884138365d74e7b209ab4c06818422fb149e Mon Sep 17 00:00:00 2001 From: Roberta Takenaka Date: Thu, 1 Sep 2022 16:14:04 -0300 Subject: [PATCH] =?UTF-8?q?Adiciona=20configura=C3=A7=C3=A3o=20do=20site?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core_settings/migrations/0001_initial.py | 13 ++++++-- core_settings/models.py | 38 ++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/core_settings/migrations/0001_initial.py b/core_settings/migrations/0001_initial.py index a8253d7..58ce3c0 100644 --- a/core_settings/migrations/0001_initial.py +++ b/core_settings/migrations/0001_initial.py @@ -1,7 +1,8 @@ -# Generated by Django 3.2.12 on 2022-07-18 11:12 +# Generated by Django 3.2.12 on 2022-08-29 09:10 from django.db import migrations, models import django.db.models.deletion +import wagtail.core.fields class Migration(migrations.Migration): @@ -9,8 +10,8 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ('wagtailcore', '0066_collection_management_permissions'), ('wagtailimages', '0023_add_choose_permissions'), + ('wagtailcore', '0066_collection_management_permissions'), ] operations = [ @@ -18,12 +19,18 @@ class Migration(migrations.Migration): name='CustomSettings', fields=[ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(blank=True, max_length=100, null=True)), + ('email', models.EmailField(blank=True, max_length=100, null=True)), + ('phone', models.CharField(blank=True, max_length=100, null=True)), + ('footer_text', wagtail.core.fields.RichTextField(blank=True, null=True)), ('admin_logo', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.image')), ('favicon', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.image')), ('site', models.OneToOneField(editable=False, on_delete=django.db.models.deletion.CASCADE, to='wagtailcore.site')), + ('site_logo', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.image')), ], options={ - 'abstract': False, + 'verbose_name': 'Configuração do site', + 'verbose_name_plural': 'Configuração do site', }, ), ] diff --git a/core_settings/models.py b/core_settings/models.py index f78a72d..7bc2704 100644 --- a/core_settings/models.py +++ b/core_settings/models.py @@ -1,7 +1,9 @@ from django.db import models +from django.utils.translation import gettext as _ +from wagtail.core.fields import RichTextField +from wagtail.admin.edit_handlers import FieldPanel, TabbedInterface, ObjectList from wagtail.images.edit_handlers import ImageChooserPanel - from wagtail.contrib.settings.models import BaseSetting, register_setting @@ -13,6 +15,16 @@ class CustomSettings(BaseSetting): More about look: https://docs.wagtail.org/en/stable/reference/contrib/settings.html """ + class Meta: + verbose_name = _('Configuração do site') + verbose_name_plural = _('Configuração do site') + + name = models.CharField(max_length=100, null=True, blank=True) + email = models.EmailField(max_length=100, null=True, blank=True) + phone = models.CharField(max_length=100, null=True, blank=True) + + footer_text = RichTextField(null=True, blank=True) + favicon = models.ForeignKey( 'wagtailimages.Image', null=True, @@ -29,7 +41,29 @@ class CustomSettings(BaseSetting): related_name='+' ) - panels = [ + site_logo = models.ForeignKey( + 'wagtailimages.Image', + null=True, + blank=True, + on_delete=models.SET_NULL, + related_name='+' + ) + + site_panels = [ + FieldPanel('name'), + FieldPanel('email'), + FieldPanel('phone'), + FieldPanel('footer_text', classname="full"), ImageChooserPanel('favicon'), + ImageChooserPanel('site_logo'), + ] + + admin_panels = [ ImageChooserPanel('admin_logo'), ] + + edit_handler = TabbedInterface([ + ObjectList(site_panels, heading=_('Site settings')), + ObjectList(admin_panels, heading=_('Admin settings')), + ]) +