11from django .db import models
2- from wagtail .fields import RichTextField , StreamField
3- from wagtail .models import Page
4- from wagtail .admin .panels import FieldPanel
52from wagtail import blocks
3+ from wagtail .admin .panels import FieldPanel
4+ from wagtail .fields import RichTextField , StreamField
65from wagtail .images .blocks import ImageChooserBlock
6+ from wagtail .models import Page
7+ from wagtail_color_panel .edit_handlers import NativeColorPanel
8+ from wagtail_color_panel .fields import ColorField
79
810
911class HomePage (Page ):
@@ -47,7 +49,9 @@ class HomePage(Page):
4749 on_delete = models .SET_NULL ,
4850 related_name = "+" ,
4951 )
50- hero_image_overlay_opacity = models .DecimalField (default = 0.70 , decimal_places = 2 , max_digits = 3 )
52+ hero_image_overlay_opacity = models .DecimalField (
53+ default = 0.70 , decimal_places = 2 , max_digits = 3
54+ )
5155 hero_padding_left = models .CharField (max_length = 250 , default = "20px" )
5256 hero_padding_right = models .CharField (max_length = 250 , default = "20px" )
5357 footer_title = models .CharField (max_length = 250 , blank = True )
@@ -77,41 +81,54 @@ class HomePage(Page):
7781 blank = True ,
7882 use_json_field = True ,
7983 )
80- color_gradient_1 = models .CharField (max_length = 250 , blank = True , default = "#FF4D79" )
81- color_gradient_2 = models .CharField (max_length = 250 , blank = True , default = "#FF809F" )
82- color_primary = models .CharField (max_length = 250 , blank = True , default = "#ff4a67" )
83- color_text_hero = models .CharField (max_length = 250 , blank = True , default = "#FFFFFF" )
84+
85+ primaryFontURL = models .URLField (max_length = 250 , blank = True )
86+ primaryFontFamily = models .CharField (max_length = 250 , default = "sans-serif" )
87+ secondaryFontURL = models .URLField (max_length = 250 , blank = True )
88+ secondaryFontFamily = models .CharField (max_length = 250 , default = "sans-serif" )
89+ color_gradient_1 = ColorField (max_length = 250 , blank = True , default = "#FF4D79" )
90+ color_gradient_2 = ColorField (max_length = 250 , blank = True , default = "#FF809F" )
91+ color_primary = ColorField (max_length = 250 , blank = True , default = "#ff4a67" )
92+ color_text_hero = ColorField (max_length = 250 , blank = True , default = "#FFFFFF" )
93+
8494 show_time = models .BooleanField (default = True )
85- background_section = models .CharField (max_length = 250 , blank = True , default = "#FFFFFF" )
86- color_text_section = models .CharField (max_length = 250 , blank = True , default = "white" )
87- navbar_background = models .CharField (max_length = 250 , default = "transparent" )
88- navbar_links_color = models .CharField (max_length = 250 ,default = "white" )
89- message_show_time = models .CharField (max_length = 250 , blank = True , default = "Próximamente..." )
95+ background_section = ColorField (max_length = 250 , blank = True , default = "#FFFFFF" )
96+ color_text_section = ColorField (max_length = 250 , blank = True , default = "#FFFFFF" )
97+ navbar_background = ColorField (max_length = 250 , blank = True , default = "#000000" )
98+ navbar_links_color = ColorField (max_length = 250 , blank = True , default = "#FFFFFF" )
99+ message_show_time = models .CharField (
100+ max_length = 250 , blank = True , default = "Próximamente..."
101+ )
90102 menu_links = StreamField (
91- [
92- (
93- "menu_links" ,
94- blocks .StructBlock (
95- [
96- ("text" , blocks .CharBlock (max_length = 250 , required = True )),
97- ("url" ,blocks .CharBlock (max_length = 250 , required = True , default = "#" )),
98- ]
99- ),
103+ [
104+ (
105+ "menu_links" ,
106+ blocks .StructBlock (
107+ [
108+ ("text" , blocks .CharBlock (max_length = 250 , required = True )),
109+ (
110+ "url" ,
111+ blocks .CharBlock (
112+ max_length = 250 , required = True , default = "#"
113+ ),
114+ ),
115+ ]
100116 ),
101- ],
102- blank = True ,
103- use_json_field = True ,
104- )
117+ ),
118+ ],
119+ blank = True ,
120+ use_json_field = True ,
121+ )
105122 favicon = models .ForeignKey (
106123 "wagtailimages.Image" ,
107124 null = True ,
108125 blank = True ,
109126 on_delete = models .SET_NULL ,
110127 related_name = "+" ,
111- help_text = "max size 256x256 png format"
128+ help_text = "max size 256x256 png format" ,
112129 )
113130 footer_background = models .CharField (max_length = 250 , blank = True , default = "#161E26" )
114- footer_color_text = models .CharField (max_length = 250 , blank = True , default = "#9e9e9e" )
131+ footer_color_text = models .CharField (max_length = 250 , blank = True , default = "#9e9e9e" )
115132 externalRaws = StreamField (
116133 [
117134 (
@@ -129,8 +146,8 @@ class HomePage(Page):
129146 content_panels = Page .content_panels + [
130147 FieldPanel ("event" ),
131148 FieldPanel ("favicon" ),
132- FieldPanel ("navbar_background" ),
133- FieldPanel ("navbar_links_color" ),
149+ NativeColorPanel ("navbar_background" ),
150+ NativeColorPanel ("navbar_links_color" ),
134151 FieldPanel ("position_event" ),
135152 FieldPanel ("about" ),
136153 FieldPanel ("location" ),
@@ -142,30 +159,40 @@ class HomePage(Page):
142159 FieldPanel ("logo_image_big" ),
143160 FieldPanel ("hero_image" ),
144161 FieldPanel ("hero_image_overlay_opacity" ),
145- FieldPanel ("color_text_hero" ),
162+ NativeColorPanel ("color_text_hero" ),
146163 FieldPanel ("hero_padding_left" ),
147164 FieldPanel ("hero_padding_right" ),
148- FieldPanel ("color_gradient_1" ),
149- FieldPanel ("color_gradient_2" ),
150- FieldPanel ("color_primary" ),
165+ FieldPanel ("primaryFontURL" ),
166+ FieldPanel ("primaryFontFamily" ),
167+ FieldPanel ("secondaryFontURL" ),
168+ FieldPanel ("secondaryFontFamily" ),
169+ NativeColorPanel ("color_gradient_1" ),
170+ NativeColorPanel ("color_gradient_2" ),
171+ NativeColorPanel ("color_primary" ),
151172 FieldPanel ("show_time" ),
152- FieldPanel ("background_section" ),
153- FieldPanel ("color_text_section" ),
173+ NativeColorPanel ("background_section" ),
174+ NativeColorPanel ("color_text_section" ),
154175 FieldPanel ("message_show_time" ),
155176 FieldPanel ("menu_links" ),
156177 FieldPanel ("footer_title" ),
157178 FieldPanel ("footer_site_info" ),
158179 FieldPanel ("footer_networks" ),
159- FieldPanel ("footer_background" ),
160- FieldPanel ("footer_color_text" ),
180+ NativeColorPanel ("color_gradient_1" ),
181+ NativeColorPanel ("footer_background" ),
182+ NativeColorPanel ("footer_color_text" ),
161183 FieldPanel ("externalRaws" ),
162184 ]
163-
185+
164186 def get_context (self , request ):
165187 # Update context to include only published posts, ordered by reverse-chron
166188 context = super ().get_context (request )
167189 segments = SegmentPage .objects .child_of (self ).live ().order_by ("order" )
168190 context ["segments" ] = segments # sorted (segments, key=lambda x: x.order)
191+ context ["exist_descendants" ] = [
192+ descendant
193+ for descendant in self .get_descendants ()
194+ if descendant .live and descendant .content_type == self .content_type
195+ ]
169196 return context
170197
171198
@@ -188,6 +215,7 @@ class SponsorBlock(blocks.StructBlock):
188215 )
189216 url = blocks .URLBlock (required = False )
190217
218+
191219class TiersBlock (blocks .StructBlock ):
192220 classname = blocks .CharBlock (required = False )
193221 name = blocks .CharBlock ()
@@ -200,6 +228,7 @@ class TiersBlock(blocks.StructBlock):
200228 url_text = blocks .CharBlock (required = False , default = "Buy now" )
201229 bg_color = blocks .CharBlock (required = False , default = "#fff" )
202230
231+
203232class ScheduleDetailBlock (blocks .StructBlock ):
204233 menu_title = blocks .CharBlock ()
205234 menu_subtitle = blocks .CharBlock (default = "Workshop" )
@@ -210,15 +239,17 @@ class ScheduleDetailBlock(blocks.StructBlock):
210239 location = blocks .CharBlock (required = False )
211240 image = ImageChooserBlock (required = False )
212241
242+
213243class ScheduleBlock (blocks .StructBlock ):
214244 name = blocks .CharBlock ()
215245 detail = blocks .CharBlock ()
216246 schedule_details = blocks .ListBlock (ScheduleDetailBlock (required = False ))
217247
248+
218249class SegmentPage (Page ):
219250 order = models .IntegerField (default = 0 )
220- background_section = models . CharField (max_length = 250 , blank = True , default = "#FFFFFF" )
221- color_text_section = models . CharField (max_length = 250 , blank = True , default = "black " )
251+ background_section = ColorField (max_length = 250 , blank = True , default = "#FFFFFF" )
252+ color_text_section = ColorField (max_length = 250 , blank = True , default = "#000000 " )
222253 segments = StreamField (
223254 [
224255 # detail segment
@@ -253,7 +284,8 @@ class SegmentPage(Page):
253284 ),
254285 ),
255286 (
256- "list_style" ,blocks .BooleanBlock (required = False , default = False ),
287+ "list_style" ,
288+ blocks .BooleanBlock (required = False , default = False ),
257289 ),
258290 ]
259291 ),
@@ -363,7 +395,12 @@ class SegmentPage(Page):
363395
364396 content_panels = Page .content_panels + [
365397 FieldPanel ("order" ),
366- FieldPanel ("background_section" ),
367- FieldPanel ("color_text_section" ),
398+ NativeColorPanel ("color_text_section" ),
368399 FieldPanel ("segments" ),
400+ NativeColorPanel ("background_section" ),
369401 ]
402+
403+ def get_context (self , request ):
404+ context = super ().get_context (request )
405+ context ["parent" ] = self .get_parent ().specific
406+ return context
0 commit comments