From 5d35669d47ebef583c6e696c9b9386d00414855f Mon Sep 17 00:00:00 2001 From: Grace Amondi Date: Thu, 13 Jul 2023 12:20:47 +0300 Subject: [PATCH] fix production display --- pages/cap/models.py | 2 +- .../cap/templates/capeditor/alert_detail.html | 15 +++--- pages/cap/wagtail_hooks.py | 52 ++++++++++++++++++- pages/home/models.py | 10 +++- pages/home/static/js/forecast_map.js | 10 ++-- pages/home/templates/home_page.html | 2 + .../templates/section/forecast_include.html | 8 +-- 7 files changed, 76 insertions(+), 23 deletions(-) diff --git a/pages/cap/models.py b/pages/cap/models.py index a788c648..f97a0369 100644 --- a/pages/cap/models.py +++ b/pages/cap/models.py @@ -9,7 +9,7 @@ class CapAlertPage(AbstractCapAlertPage): template = "capeditor/alert_detail.html" - parent_page_type = ["home.HomePage"] + parent_page_types = ["home.HomePage"] subpage_types = [] content_panels = Page.content_panels + [ diff --git a/pages/cap/templates/capeditor/alert_detail.html b/pages/cap/templates/capeditor/alert_detail.html index ae15127a..07fd72a2 100644 --- a/pages/cap/templates/capeditor/alert_detail.html +++ b/pages/cap/templates/capeditor/alert_detail.html @@ -60,13 +60,7 @@

- {% for item in page.info %} - {% for area in item.value.area %} - - {{area.value.areaDesc}} - - {% endfor %} - {% endfor %} +
@@ -96,6 +90,13 @@

+ {% for item in page.info %} + {% for area in item.value.area %} + + {{area.value.areaDesc}} + + {% endfor %} + {% endfor %} diff --git a/pages/cap/wagtail_hooks.py b/pages/cap/wagtail_hooks.py index 36331ad6..c31dfeb5 100644 --- a/pages/cap/wagtail_hooks.py +++ b/pages/cap/wagtail_hooks.py @@ -1,5 +1,53 @@ from wagtail.contrib.modeladmin.options import modeladmin_register - +from .models import CapAlertPage +from capeditor.models import CapSetting +from wagtail.contrib.modeladmin.options import ( + ModelAdmin, + modeladmin_register, + ModelAdminGroup +) from adminboundarymanager.wagtail_hooks import AdminBoundaryManagerAdminGroup +from django.urls import path, include, reverse +from wagtail.admin.menu import MenuItem +from django.utils.translation import gettext_lazy as _ + +modeladmin_register(AdminBoundaryManagerAdminGroup) + +class CAPAdmin(ModelAdmin): + model = CapAlertPage + menu_label = 'Alerts' + menu_icon = 'list-ul' + menu_order = 200 + add_to_settings_menu = False + exclude_from_explorer = False + + + +class CAPMenuGroup(ModelAdminGroup): + menu_label = 'CAP Alerts' + menu_icon = 'warning' # change as required + menu_order = 200 # will put in 3rd place (000 being 1st, 100 2nd) + items = (CAPAdmin,) + + def get_submenu_items(self): + menu_items = [] + item_order = 1 + + for modeladmin in self.modeladmin_instances: + menu_items.append(modeladmin.get_menu_item(order=item_order)) + item_order += 1 + + try: + settings_url = reverse( + "wagtailsettings:edit", + args=[CapSetting._meta.app_label, CapSetting._meta.model_name, ], + ) + gm_settings_menu = MenuItem(label=_("Settings"), url=settings_url, icon_name="cog") + menu_items.append(gm_settings_menu) + except Exception: + pass + + return menu_items + -modeladmin_register(AdminBoundaryManagerAdminGroup) \ No newline at end of file +modeladmin_register(CAPMenuGroup) \ No newline at end of file diff --git a/pages/home/models.py b/pages/home/models.py index 1c833447..b1a68ed3 100644 --- a/pages/home/models.py +++ b/pages/home/models.py @@ -187,7 +187,7 @@ def get_forecast_by_daterange(request): @cached_property def get_alerts(self): - alerts = CapAlertPage.objects.all().order_by('sent')[:2] + alerts = CapAlertPage.objects.all().order_by('-sent')[:2] active_alerts = [] active_alert_info = None @@ -226,3 +226,11 @@ def get_cities(self): return { 'cities': cities } + + def get_children(self): + children = super().get_children() # Get live and public child pages + + # Exclude CAP Alert pages by their specific criteria (e.g., page type or attribute) + children = children.not_type(CapAlertPage) + + return children diff --git a/pages/home/static/js/forecast_map.js b/pages/home/static/js/forecast_map.js index ff0616d5..4ab06c33 100644 --- a/pages/home/static/js/forecast_map.js +++ b/pages/home/static/js/forecast_map.js @@ -104,8 +104,6 @@ $(document).ready(function () { forecast_map.fitBounds(bbox, { padding: 20 }); } - console.log(geojson) - if(geojson){ forecast_map.addSource("alert-areas", { type: "geojson", @@ -117,7 +115,6 @@ $(document).ready(function () { type: "fill", source: "alert-areas", paint: { - "fill-color": "#088", "fill-color": [ "case", ["==", ["get", "severity"], "Extreme"], @@ -133,6 +130,7 @@ $(document).ready(function () { "black", ], "fill-opacity": 0.7, + "fill-outline-color": "#000", }, }); @@ -195,6 +193,9 @@ $(document).ready(function () { forecast_map.getCanvas().style.cursor = ""; }); + var initDate = document.getElementById("daily_forecast"); + setForecastData(initDate.value) + }) @@ -234,8 +235,7 @@ $(document).ready(function () { } - var initDate = document.getElementById("daily_forecast"); - setForecastData(initDate.value) + diff --git a/pages/home/templates/home_page.html b/pages/home/templates/home_page.html index 788ed450..c3f656c8 100644 --- a/pages/home/templates/home_page.html +++ b/pages/home/templates/home_page.html @@ -33,6 +33,8 @@ const temp_units = "{{settings.forecastmanager.ForecastSetting.get_temp_units_display}}" const forecast_api = "{% url 'forecast-list'%}" const static_path = '{% static "forecastmanager/img/" %}' + const geojson = JSON.parse("{{self.get_alerts.geojson|escapejs}}") + diff --git a/pages/home/templates/section/forecast_include.html b/pages/home/templates/section/forecast_include.html index 4dc7ec86..52f9493e 100644 --- a/pages/home/templates/section/forecast_include.html +++ b/pages/home/templates/section/forecast_include.html @@ -1,5 +1,6 @@ {% load static nmhs_cms_tags %} + {% if self.enable_weather_forecasts == True %} @@ -183,11 +184,4 @@

CAP Alerts

{% endif %} -{% block extra_js %} - - -{% endblock extra_js %}