Skip to content

Commit d5fc5c6

Browse files
committed
DBC22-6524: removed debugging console logs and warnings as possible
DBC22-6524: fixed null geo saving for advisory DBC22-6524: reverted to pre version DBC22-6524: validate geo field before post request
1 parent ffe9c7e commit d5fc5c6

3 files changed

Lines changed: 45 additions & 13 deletions

File tree

src/backend/apps/cms/models.py

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
from django.contrib.gis.forms import MultiPolygonField
1818
from django.contrib.gis.geos import MultiPolygon, Polygon, GEOSGeometry
1919
from wagtail.admin.forms import WagtailAdminPageForm
20+
from wagtail.admin.panels import Panel
21+
from django.core.exceptions import ValidationError
22+
2023

2124
TABLE_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

172193
class 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+
245275
class 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 = []

src/backend/apps/cms/static/js/map-widget.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
setupKeyboardShortcuts();
2929
setupSaveHook();
3030
enterDrawMode(); // default mode on load
31-
32-
console.log('map-widget initialized');
3331
}
3432

3533
// Styles
@@ -418,8 +416,6 @@ function enterSelectedMode() {
418416
if (form) {
419417
// Force our correct geometry value into the field before FormData reads it
420418
updateHiddenField();
421-
console.log('FormData intercepted, geometry:',
422-
document.getElementById('id_geometry')?.value?.substring(0, 80));
423419
}
424420
return new originalFormData(form);
425421
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div class="w-field">
2+
<div class="w-field__wrapper">
3+
<input type="text" value="{{ value }}" readonly
4+
style="width:100%; padding: 0.5rem 0.75rem; border: 1px solid #e0e0e0 !important; border-radius: 4px; background: #f6f6f8; color: #333; font-size: 0.95rem; outline: none !important; box-shadow: none !important; cursor: default;" />
5+
</div>
6+
</div>

0 commit comments

Comments
 (0)