From 58c41c6007e62e6dca8a4979b88cc798f3026bdb Mon Sep 17 00:00:00 2001 From: AASG2003 Date: Wed, 4 Sep 2024 22:48:29 -0400 Subject: [PATCH] feat: :sparkles: add color picker panel adding color picker panel to color fields in the models --- home/models.py | 48 +++++++++++++++++++++------------------- requirements.txt | 3 ++- website/settings/base.py | 3 ++- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/home/models.py b/home/models.py index 18ce9c4..3ed20eb 100644 --- a/home/models.py +++ b/home/models.py @@ -4,7 +4,8 @@ from wagtail.admin.panels import FieldPanel from wagtail import blocks from wagtail.images.blocks import ImageChooserBlock - +from wagtail_color_panel.fields import ColorField +from wagtail_color_panel.edit_handlers import NativeColorPanel class HomePage(Page): event = RichTextField(blank=True) @@ -77,15 +78,15 @@ class HomePage(Page): blank=True, use_json_field=True, ) - color_gradient_1 = models.CharField(max_length=250, blank=True, default="#FF4D79") - color_gradient_2 = models.CharField(max_length=250, blank=True, default="#FF809F") - color_primary = models.CharField(max_length=250, blank=True, default="#ff4a67") - color_text_hero = models.CharField(max_length=250, blank=True, default="#FFFFFF") + color_gradient_1 = ColorField(max_length=250, blank=True, default="#FF4D79") + color_gradient_2 = ColorField(max_length=250, blank=True, default="#FF809F") + color_primary = ColorField(max_length=250, blank=True, default="#ff4a67") + color_text_hero = ColorField(max_length=250, blank=True, default="#FFFFFF") show_time = models.BooleanField(default=True) - background_section = models.CharField(max_length=250, blank=True, default="#FFFFFF") - color_text_section = models.CharField(max_length=250, blank=True, default="white") - navbar_background = models.CharField(max_length=250, default="transparent") - navbar_links_color = models.CharField(max_length=250,default="white") + background_section = ColorField(max_length=250, blank=True, default="#FFFFFF") + color_text_section = ColorField(max_length=250, blank=True, default="#FFFFFF") + navbar_background = ColorField(max_length=250, blank=True, default="transparent") + navbar_links_color = ColorField(max_length=250, blank=True, default="#FFFFFF") message_show_time = models.CharField(max_length=250, blank=True, default="Próximamente...") menu_links = StreamField( [ @@ -129,8 +130,8 @@ class HomePage(Page): content_panels = Page.content_panels + [ FieldPanel("event"), FieldPanel("favicon"), - FieldPanel("navbar_background"), - FieldPanel("navbar_links_color"), + NativeColorPanel("navbar_background"), + NativeColorPanel("navbar_links_color"), FieldPanel("position_event"), FieldPanel("about"), FieldPanel("location"), @@ -142,22 +143,23 @@ class HomePage(Page): FieldPanel("logo_image_big"), FieldPanel("hero_image"), FieldPanel("hero_image_overlay_opacity"), - FieldPanel("color_text_hero"), + NativeColorPanel("color_text_hero"), FieldPanel("hero_padding_left"), FieldPanel("hero_padding_right"), - FieldPanel("color_gradient_1"), - FieldPanel("color_gradient_2"), - FieldPanel("color_primary"), + NativeColorPanel("color_gradient_1"), + NativeColorPanel("color_gradient_2"), + NativeColorPanel("color_primary"), FieldPanel("show_time"), - FieldPanel("background_section"), - FieldPanel("color_text_section"), + NativeColorPanel("background_section"), + NativeColorPanel("color_text_section"), FieldPanel("message_show_time"), FieldPanel("menu_links"), FieldPanel("footer_title"), FieldPanel("footer_site_info"), FieldPanel("footer_networks"), - FieldPanel("footer_background"), - FieldPanel("footer_color_text"), + NativeColorPanel("color_gradient_1"), + NativeColorPanel("footer_background"), + NativeColorPanel("footer_color_text"), FieldPanel("externalRaws"), ] @@ -217,8 +219,8 @@ class ScheduleBlock(blocks.StructBlock): class SegmentPage(Page): order = models.IntegerField(default=0) - background_section = models.CharField(max_length=250, blank=True, default="#FFFFFF") - color_text_section = models.CharField(max_length=250, blank=True, default="black") + background_section = ColorField(max_length=250, blank=True, default="#FFFFFF") + color_text_section = ColorField(max_length=250, blank=True, default="black") segments = StreamField( [ # detail segment @@ -363,7 +365,7 @@ class SegmentPage(Page): content_panels = Page.content_panels + [ FieldPanel("order"), - FieldPanel("background_section"), - FieldPanel("color_text_section"), + NativeColorPanel("color_text_section"), FieldPanel("segments"), + NativeColorPanel("background_section") ] diff --git a/requirements.txt b/requirements.txt index 22f11c0..8124482 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ Django>=4.2,<5.1 wagtail>=6.2,<6.3 django-mathfilters==1.0.0 whitenoise==6.2.0 -mysqlclient==2.2.1 \ No newline at end of file +mysqlclient==2.2.1 +wagtail-color-panel==1.5.0 \ No newline at end of file diff --git a/website/settings/base.py b/website/settings/base.py index e98ca72..7c52a08 100644 --- a/website/settings/base.py +++ b/website/settings/base.py @@ -52,7 +52,8 @@ "django.contrib.messages", "django.contrib.staticfiles", "mathfilters", - 'wagtail.contrib.search_promotions' + 'wagtail.contrib.search_promotions', + 'wagtail_color_panel' ] MIDDLEWARE = [