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
7- from wagtail_color_panel . fields import ColorField
6+ from wagtail . models import Page
87from wagtail_color_panel .edit_handlers import NativeColorPanel
8+ from wagtail_color_panel .fields import ColorField
9+
910
1011class HomePage (Page ):
1112 event = RichTextField (blank = True )
@@ -48,7 +49,9 @@ class HomePage(Page):
4849 on_delete = models .SET_NULL ,
4950 related_name = "+" ,
5051 )
51- 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+ )
5255 hero_padding_left = models .CharField (max_length = 250 , default = "20px" )
5356 hero_padding_right = models .CharField (max_length = 250 , default = "20px" )
5457 footer_title = models .CharField (max_length = 250 , blank = True )
@@ -80,45 +83,52 @@ class HomePage(Page):
8083 )
8184
8285 primaryFontURL = models .URLField (max_length = 250 , blank = True )
83- primaryFontFamily = models .CharField (max_length = 250 , default = "sans-serif" )
86+ primaryFontFamily = models .CharField (max_length = 250 , default = "sans-serif" )
8487 secondaryFontURL = models .URLField (max_length = 250 , blank = True )
8588 secondaryFontFamily = models .CharField (max_length = 250 , default = "sans-serif" )
8689 color_gradient_1 = ColorField (max_length = 250 , blank = True , default = "#FF4D79" )
8790 color_gradient_2 = ColorField (max_length = 250 , blank = True , default = "#FF809F" )
8891 color_primary = ColorField (max_length = 250 , blank = True , default = "#ff4a67" )
89- color_text_hero = ColorField (max_length = 250 , blank = True , default = "#FFFFFF" )
92+ color_text_hero = ColorField (max_length = 250 , blank = True , default = "#FFFFFF" )
9093
9194 show_time = models .BooleanField (default = True )
9295 background_section = ColorField (max_length = 250 , blank = True , default = "#FFFFFF" )
93- color_text_section = ColorField (max_length = 250 , blank = True , default = "#FFFFFF" )
94- navbar_background = ColorField (max_length = 250 , blank = True , default = "#000000" )
95- navbar_links_color = ColorField (max_length = 250 , blank = True , default = "#FFFFFF" )
96- message_show_time = models .CharField (max_length = 250 , blank = True , default = "Próximamente..." )
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+ )
97102 menu_links = StreamField (
98- [
99- (
100- "menu_links" ,
101- blocks .StructBlock (
102- [
103- ("text" , blocks .CharBlock (max_length = 250 , required = True )),
104- ("url" ,blocks .CharBlock (max_length = 250 , required = True , default = "#" )),
105- ]
106- ),
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+ ]
107116 ),
108- ],
109- blank = True ,
110- use_json_field = True ,
111- )
117+ ),
118+ ],
119+ blank = True ,
120+ use_json_field = True ,
121+ )
112122 favicon = models .ForeignKey (
113123 "wagtailimages.Image" ,
114124 null = True ,
115125 blank = True ,
116126 on_delete = models .SET_NULL ,
117127 related_name = "+" ,
118- help_text = "max size 256x256 png format"
128+ help_text = "max size 256x256 png format" ,
119129 )
120130 footer_background = models .CharField (max_length = 250 , blank = True , default = "#161E26" )
121- 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" )
122132 externalRaws = StreamField (
123133 [
124134 (
@@ -152,16 +162,13 @@ class HomePage(Page):
152162 NativeColorPanel ("color_text_hero" ),
153163 FieldPanel ("hero_padding_left" ),
154164 FieldPanel ("hero_padding_right" ),
155-
156165 FieldPanel ("primaryFontURL" ),
157166 FieldPanel ("primaryFontFamily" ),
158167 FieldPanel ("secondaryFontURL" ),
159168 FieldPanel ("secondaryFontFamily" ),
160-
161169 NativeColorPanel ("color_gradient_1" ),
162170 NativeColorPanel ("color_gradient_2" ),
163171 NativeColorPanel ("color_primary" ),
164-
165172 FieldPanel ("show_time" ),
166173 NativeColorPanel ("background_section" ),
167174 NativeColorPanel ("color_text_section" ),
@@ -175,12 +182,17 @@ class HomePage(Page):
175182 NativeColorPanel ("footer_color_text" ),
176183 FieldPanel ("externalRaws" ),
177184 ]
178-
185+
179186 def get_context (self , request ):
180187 # Update context to include only published posts, ordered by reverse-chron
181188 context = super ().get_context (request )
182189 segments = SegmentPage .objects .child_of (self ).live ().order_by ("order" )
183190 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+ ]
184196 return context
185197
186198
@@ -203,6 +215,7 @@ class SponsorBlock(blocks.StructBlock):
203215 )
204216 url = blocks .URLBlock (required = False )
205217
218+
206219class TiersBlock (blocks .StructBlock ):
207220 classname = blocks .CharBlock (required = False )
208221 name = blocks .CharBlock ()
@@ -215,6 +228,7 @@ class TiersBlock(blocks.StructBlock):
215228 url_text = blocks .CharBlock (required = False , default = "Buy now" )
216229 bg_color = blocks .CharBlock (required = False , default = "#fff" )
217230
231+
218232class ScheduleDetailBlock (blocks .StructBlock ):
219233 menu_title = blocks .CharBlock ()
220234 menu_subtitle = blocks .CharBlock (default = "Workshop" )
@@ -225,15 +239,17 @@ class ScheduleDetailBlock(blocks.StructBlock):
225239 location = blocks .CharBlock (required = False )
226240 image = ImageChooserBlock (required = False )
227241
242+
228243class ScheduleBlock (blocks .StructBlock ):
229244 name = blocks .CharBlock ()
230245 detail = blocks .CharBlock ()
231246 schedule_details = blocks .ListBlock (ScheduleDetailBlock (required = False ))
232247
248+
233249class SegmentPage (Page ):
234250 order = models .IntegerField (default = 0 )
235251 background_section = ColorField (max_length = 250 , blank = True , default = "#FFFFFF" )
236- color_text_section = ColorField (max_length = 250 , blank = True , default = "#000000" )
252+ color_text_section = ColorField (max_length = 250 , blank = True , default = "#000000" )
237253 segments = StreamField (
238254 [
239255 # detail segment
@@ -268,7 +284,8 @@ class SegmentPage(Page):
268284 ),
269285 ),
270286 (
271- "list_style" ,blocks .BooleanBlock (required = False , default = False ),
287+ "list_style" ,
288+ blocks .BooleanBlock (required = False , default = False ),
272289 ),
273290 ]
274291 ),
@@ -380,9 +397,10 @@ class SegmentPage(Page):
380397 FieldPanel ("order" ),
381398 NativeColorPanel ("color_text_section" ),
382399 FieldPanel ("segments" ),
383- NativeColorPanel ("background_section" )
400+ NativeColorPanel ("background_section" ),
384401 ]
402+
385403 def get_context (self , request ):
386404 context = super ().get_context (request )
387- context [' parent' ] = self .get_parent ().specific
405+ context [" parent" ] = self .get_parent ().specific
388406 return context
0 commit comments