1717from django .contrib .gis .forms import MultiPolygonField
1818from django .contrib .gis .geos import MultiPolygon , Polygon , GEOSGeometry
1919from wagtail .admin .forms import WagtailAdminPageForm
20+ from wagtail .admin .panels import Panel
21+ from django .core .exceptions import ValidationError
22+
2023
2124TABLE_OPTIONS = {'rowHeaders' : True ,
2225 'colHeaders' : True , }
@@ -168,6 +171,24 @@ class RichContent(blocks.StreamBlock):
168171 callout = blocks .RichTextBlock (help_text = CALLOUT_HELP_TEXT ,
169172 template = 'cms/callout.html' )
170173
174+ class ReadOnlyPanel (Panel ):
175+ def __init__ (self , field_name , ** kwargs ):
176+ self .field_name = field_name
177+ super ().__init__ (** kwargs )
178+
179+ def clone (self ):
180+ return self .__class__ (
181+ field_name = self .field_name ,
182+ heading = self .heading ,
183+ )
184+
185+ class BoundPanel (Panel .BoundPanel ):
186+ template_name = 'cms/read_only_panel.html'
187+
188+ def get_context_data (self , parent_context = None ):
189+ ctx = super ().get_context_data (parent_context )
190+ ctx ['value' ] = getattr (self .instance , self .panel .field_name , '' )
191+ return ctx
171192
172193class AdvisoryIndexPage (Page ):
173194 parent_page_types = ["wagtailcore.Page" ]
@@ -198,6 +219,14 @@ def rendered_body(self):
198219
199220 last_notified_at = models .DateTimeField (null = True , blank = True )
200221
222+ def clean (self ):
223+ super ().clean ()
224+
225+ if self .geometry is None or self .geometry .empty :
226+ raise ValidationError ({
227+ "geometry" : "Please draw at least one polygon."
228+ })
229+
201230 # Editor panels configuration
202231 content_panels = [
203232 FieldPanel ("title" , help_text = HelpText .GENERIC_TITLE ),
@@ -209,9 +238,9 @@ def rendered_body(self):
209238 heading = "Area" ,
210239 ),
211240 FieldPanel ("body" , help_text = HelpText .GENERIC_BODY ),
212- FieldPanel ('created_at' , read_only = True , heading = "Created" ),
213- FieldPanel ('first_published_at' , read_only = True , heading = "Published" ),
214- FieldPanel ( 'last_notified_at' , read_only = True , heading = "Updated" ),
241+ ReadOnlyPanel ('created_at' , heading = "Created" ),
242+ ReadOnlyPanel ('first_published_at' , heading = "Published" ),
243+ ReadOnlyPanel ( 'last_published_at' , heading = "Updated" ),
215244 ]
216245 promote_panels = []
217246
@@ -242,6 +271,7 @@ def save(self, *args, **kwargs):
242271 super ().save (log_action = None , * args , ** kwargs )
243272 cache .delete (CacheKey .ADVISORY_LIST )
244273
274+
245275class BulletinIndexPage (Page ):
246276 parent_page_types = ["wagtailcore.Page" ]
247277 subpage_types = ["cms.Bulletin" ]
@@ -281,9 +311,9 @@ def save(self, *args, **kwargs):
281311 heading = "Newsfeed Image" ),
282312 FieldPanel ("image_alt_text" , help_text = HelpText .BULLETIN_IMAGE_ALT_TEXT ),
283313 FieldPanel ("body" , help_text = HelpText .GENERIC_BODY ),
284- FieldPanel ('created_at' , read_only = True , heading = "Created" ),
285- FieldPanel ('first_published_at' , read_only = True , heading = "Published" ),
286- FieldPanel ( 'last_notified_at' , read_only = True , heading = "Updated" ),
314+ ReadOnlyPanel ('created_at' , heading = "Created" ),
315+ ReadOnlyPanel ('first_published_at' , heading = "Published" ),
316+ ReadOnlyPanel ( 'last_published_at' , heading = "Updated" ),
287317 ]
288318 promote_panels = []
289319
@@ -447,9 +477,9 @@ def save(self, *args, **kwargs):
447477 content_panels = [
448478 FieldPanel ("title" , help_text = HelpText .GENERIC_TITLE ),
449479 FieldPanel ("body" , help_text = HelpText .GENERIC_BODY ),
450- FieldPanel ('created_at' , read_only = True , heading = "Created" ),
451- FieldPanel ('first_published_at' , read_only = True , heading = "Published" ),
452- FieldPanel ('last_published_at' , read_only = True , heading = "Updated" ),
480+ ReadOnlyPanel ('created_at' , heading = "Created" ),
481+ ReadOnlyPanel ('first_published_at' , heading = "Published" ),
482+ ReadOnlyPanel ('last_published_at' , heading = "Updated" ),
453483 ]
454484
455485 promote_panels = []
0 commit comments