+
+ {% translate "Area:" %}
+
+
+ {% for area in info.area %}
+ {{ area.areaDesc }}{% if not forloop.last %}, {% endif %}
+ {% endfor %}
+
+
+
+
+ {% endfor %}
+
+
+
+
+ {% endif %}
+
+{% endblock %}
+
+{% block extra_js %}
+ {{ block.super }}
+
+
+
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/capeditor/views.py b/capeditor/views.py
new file mode 100644
index 0000000..7a8450e
--- /dev/null
+++ b/capeditor/views.py
@@ -0,0 +1,51 @@
+from django.shortcuts import render, redirect
+from wagtail import hooks
+
+from capeditor.forms.capimporter import CAPLoadForm, CAPImportForm
+
+
+def load_cap_alert(request):
+ load_template_name = "capeditor/load_cap_alert.html"
+ preview_template_name = "capeditor/preview_cap_alert.html"
+
+ context = {}
+
+ if request.method == "POST":
+ form = CAPLoadForm(request.POST, request.FILES)
+ if form.is_valid():
+ alert_data = form.cleaned_data["alert_data"]
+ form = CAPImportForm(initial={"alert_data": alert_data})
+ context.update({
+ "alert_data": alert_data,
+ "form": form,
+ })
+
+ return render(request, preview_template_name, context)
+
+ else:
+ context.update({"form": form})
+ return render(request, template_name=load_template_name, context=context)
+
+ form = CAPLoadForm()
+ context.update({"form": form})
+
+ return render(request, load_template_name, context)
+
+
+def import_cap_alert(request):
+ if request.method == "POST":
+ form = CAPImportForm(request.POST)
+ if form.is_valid():
+ alert_data = form.cleaned_data["alert_data"]
+
+ # run hook to import alert
+ for fn in hooks.get_hooks("before_import_cap_alert"):
+ result = fn(request, alert_data)
+ if hasattr(result, "status_code"):
+ return result
+
+ return redirect("load_cap_alert")
+ else:
+ return redirect("load_cap_alert")
+
+ return redirect("load_cap_alert")
diff --git a/capeditor/wagtail_hooks.py b/capeditor/wagtail_hooks.py
index f50c487..ad77eb7 100644
--- a/capeditor/wagtail_hooks.py
+++ b/capeditor/wagtail_hooks.py
@@ -1,6 +1,7 @@
from django.shortcuts import redirect
from django.template.response import TemplateResponse
from django.templatetags.static import static
+from django.urls import path
from django.utils.html import format_html
from django.utils.translation import gettext as _
from wagtail import hooks
@@ -10,6 +11,8 @@
from wagtail.admin.utils import get_valid_next_url_from_request
from wagtail.models import Page
+from capeditor.views import load_cap_alert, import_cap_alert
+
@hooks.register("insert_editor_js")
def insert_editor_js():
@@ -26,6 +29,14 @@ def register_icons(icons):
]
+@hooks.register('register_admin_urls')
+def urlconf_stations():
+ return [
+ path('import-cap/', load_cap_alert, name='load_cap_alert'),
+ path('import-cap/import/', import_cap_alert, name='import_cap_alert'),
+ ]
+
+
# @hooks.register("before_copy_page")
def copy_cap_alert_page(request, page):
if page.specific.__class__.__name__ == "CapAlertPage":
diff --git a/sandbox/home/migrations/0020_alter_capalertpage_info.py b/sandbox/home/migrations/0020_alter_capalertpage_info.py
new file mode 100644
index 0000000..021e9ec
--- /dev/null
+++ b/sandbox/home/migrations/0020_alter_capalertpage_info.py
@@ -0,0 +1,23 @@
+# Generated by Django 4.2.11 on 2024-04-05 13:26
+
+import capeditor.blocks
+from django.db import migrations
+import wagtail.blocks
+import wagtail.documents.blocks
+import wagtail.fields
+import wagtailmodelchooser.blocks
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('home', '0019_capalertpage_search_image_alter_capalertpage_info'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='capalertpage',
+ name='info',
+ field=wagtail.fields.StreamField([('alert_info', wagtail.blocks.StructBlock([('event', wagtail.blocks.ChoiceBlock(choices=capeditor.blocks.get_hazard_types, help_text='The text denoting the type of the subject event of the alert message. You can define hazards events monitored by your institution from CAP settings', label='Event')), ('category', wagtail.blocks.MultipleChoiceBlock(choices=[('Geo', 'Geophysical'), ('Met', 'Meteorological'), ('Safety', 'General emergency and public safety'), ('Security', 'Law enforcement, military, homeland and local/private security'), ('Rescue', 'Rescue and recovery'), ('Fire', 'Fire suppression and rescue'), ('Health', 'Medical and public health'), ('Env', 'Pollution and other environmental'), ('Transport', 'Public and private transportation'), ('Infra', 'Utility, telecommunication, other non-transport infrastructure'), ('CBRNE', 'Chemical, Biological, Radiological, Nuclear or High-Yield Explosive threat or attack'), ('Other', 'Other events')], help_text='The code denoting the category of the subject event of the alert message', label='Category')), ('language', wagtail.blocks.ChoiceBlock(choices=[('en', 'English'), ('fr', 'French')], help_text='The code denoting the language of the alert message', label='Language', required=False)), ('urgency', wagtail.blocks.ChoiceBlock(choices=[('Immediate', 'Immediate - Responsive action SHOULD be taken immediately'), ('Expected', 'Expected - Responsive action SHOULD be taken soon (within next hour)'), ('Future', 'Future - Responsive action SHOULD be taken in the near future'), ('Past', 'Past - Responsive action is no longer required'), ('Unknown', 'Unknown - Urgency not known')], help_text='The code denoting the urgency of the subject event of the alert message', label='Urgency')), ('severity', wagtail.blocks.ChoiceBlock(choices=[('Extreme', 'Extreme - Extraordinary threat to life or property'), ('Severe', 'Severe - Significant threat to life or property'), ('Moderate', 'Moderate - Possible threat to life or property'), ('Minor', 'Minor - Minimal to no known threat to life or property'), ('Unknown', 'Unknown - Severity unknown')], help_text='The code denoting the severity of the subject event of the alert message', label='Severity')), ('certainty', wagtail.blocks.ChoiceBlock(choices=[('Observed', 'Observed - Determined to have occurred or to be ongoing'), ('Likely', 'Likely - Likely (percentage > ~50%)'), ('Possible', 'Possible - Possible but not likely (percentage <= ~50%)'), ('Unlikely', 'Unlikely - Not expected to occur (percentage ~ 0)'), ('Unknown', 'Unknown - Certainty unknown')], help_text='The code denoting the certainty of the subject event of the alert message', label='Certainty')), ('headline', wagtail.blocks.CharBlock(help_text='The text headline of the alert message. Make it direct and actionable as possible while remaining short', label='Headline', max_length=160, required=False)), ('description', wagtail.blocks.TextBlock(help_text='The text describing the subject event of the alert message. An extended description of the hazard or event that occasioned this message', label='Description', required=True)), ('instruction', wagtail.blocks.TextBlock(help_text='The text describing the recommended action to be taken by recipients of the alert message', label='Instruction', required=False)), ('effective', wagtail.blocks.DateTimeBlock(help_text='The effective time of the information of the alert message. If not set, the sent date will be used', label='Effective', required=False)), ('onset', wagtail.blocks.DateTimeBlock(help_text='The expected time of the beginning of the subject event of the alert message', label='Onset', required=False)), ('expires', wagtail.blocks.DateTimeBlock(help_text='The expiry time of the information of the alert message. If not set, each recipient is free to set its own policy as to when the message is no longer in effect.', label='Expires', required=True)), ('responseType', wagtail.blocks.ListBlock(wagtail.blocks.StructBlock([('response_type', wagtail.blocks.ChoiceBlock(choices=[('Shelter', 'Shelter - Take shelter in place or per instruction'), ('Evacuate', 'Evacuate - Relocate as instructed in the instruction'), ('Prepare', 'Prepare - Relocate as instructed in the instruction'), ('Execute', 'Execute - Execute a pre-planned activity identified in instruction'), ('Avoid', 'Avoid - Avoid the subject event as per the instruction'), ('Monitor', 'Monitor - Attend to information sources as described in instruction'), ('Assess', 'Assess - Evaluate the information in this message - DONT USE FOR PUBLIC ALERTS'), ('AllClear', 'All Clear - The subject event no longer poses a threat or concern and any follow on action is described in instruction'), ('None', 'No action recommended')], help_text='The code denoting the type of action recommended for the target audience', label='Response type'))], label='Response Type'), default=[], label='Response Types')), ('senderName', wagtail.blocks.CharBlock(help_text='The human-readable name of the agency or authority issuing this alert.', label='Sender name', max_length=255, required=False)), ('contact', wagtail.blocks.CharBlock(help_text='The text describing the contact for follow-up and confirmation of the alert message', label='Contact', max_length=255, required=False)), ('audience', wagtail.blocks.CharBlock(help_text='The text describing the intended audience of the alert message', label='Audience', max_length=255, required=False)), ('area', wagtail.blocks.StreamBlock([('boundary_block', wagtail.blocks.StructBlock([('areaDesc', wagtail.blocks.TextBlock(help_text='The text describing the affected area of the alert message', label='Affected areas / Regions')), ('admin_level', wagtail.blocks.ChoiceBlock(choices=[(0, 'Level 0'), (1, 'Level 1'), (2, 'Level 2'), (3, 'Level 3')], label='Administrative Level')), ('boundary', capeditor.blocks.BoundaryFieldBlock(help_text='The paired values of points defining a polygon that delineates the affected area of the alert message', label='Boundary')), ('altitude', wagtail.blocks.CharBlock(help_text='The specific or minimum altitude of the affected area of the alert message', label='Altitude', max_length=100, required=False)), ('ceiling', wagtail.blocks.CharBlock(help_text='The maximum altitude of the affected area of the alert message.MUST NOT be used except in combination with the altitude element. ', label='Ceiling', max_length=100, required=False))], label='Admin Boundary')), ('polygon_block', wagtail.blocks.StructBlock([('areaDesc', wagtail.blocks.TextBlock(help_text='The text describing the affected area of the alert message', label='Affected areas / Regions')), ('polygon', capeditor.blocks.PolygonOrMultiPolygonFieldBlock(help_text='The paired values of points defining a polygon that delineates the affected area of the alert message', label='Polygon')), ('altitude', wagtail.blocks.CharBlock(help_text='The specific or minimum altitude of the affected area of the alert message', label='Altitude', max_length=100, required=False)), ('ceiling', wagtail.blocks.CharBlock(help_text='The maximum altitude of the affected area of the alert message.MUST NOT be used except in combination with the altitude element. ', label='Ceiling', max_length=100, required=False))], label='Draw Polygon')), ('circle_block', wagtail.blocks.StructBlock([('areaDesc', wagtail.blocks.TextBlock(help_text='The text describing the affected area of the alert message', label='Affected areas / Regions')), ('circle', capeditor.blocks.CircleFieldBlock(help_text='Drag the marker to change position', label='Circle')), ('altitude', wagtail.blocks.CharBlock(help_text='The specific or minimum altitude of the affected area of the alert message', label='Altitude', max_length=100, required=False)), ('ceiling', wagtail.blocks.CharBlock(help_text='The maximum altitude of the affected area of the alert message.MUST NOT be used except in combination with the altitude element. ', label='Ceiling', max_length=100, required=False))], label='Circle')), ('geocode_block', wagtail.blocks.StructBlock([('areaDesc', wagtail.blocks.TextBlock(help_text='The text describing the affected area of the alert message', label='Affected areas / Regions')), ('valueName', wagtail.blocks.TextBlock(label='Name')), ('value', wagtail.blocks.TextBlock(label='Value')), ('altitude', wagtail.blocks.CharBlock(help_text='The specific or minimum altitude of the affected area of the alert message', label='Altitude', max_length=100, required=False)), ('ceiling', wagtail.blocks.CharBlock(help_text='The maximum altitude of the affected area of the alert message.MUST NOT be used except in combination with the altitude element. ', label='Ceiling', max_length=100, required=False))], label='Geocode')), ('predefined_block', wagtail.blocks.StructBlock([('area', wagtailmodelchooser.blocks.ModelChooserBlock(label='Area', target_model='capeditor.predefinedalertarea')), ('altitude', wagtail.blocks.CharBlock(help_text='The specific or minimum altitude of the affected area of the alert message', label='Altitude', max_length=100, required=False)), ('ceiling', wagtail.blocks.CharBlock(help_text='The maximum altitude of the affected area of the alert message.MUST NOT be used except in combination with the altitude element. ', label='Ceiling', max_length=100, required=False))], label='Predefined Area'))], help_text='Admin Boundary, Polygon, Circle or Geocode', label='Alert Area')), ('resource', wagtail.blocks.StreamBlock([('file_resource', wagtail.blocks.StructBlock([('resourceDesc', wagtail.blocks.TextBlock(help_text='The text describing the type and content of the resource file', label='Resource Description')), ('file', wagtail.documents.blocks.DocumentChooserBlock())])), ('external_resource', wagtail.blocks.StructBlock([('resourceDesc', wagtail.blocks.TextBlock(help_text='The text describing the type and content of the resource file', label='Resource Description')), ('external_url', wagtail.blocks.URLBlock(help_text='Link to external resource. This can be for example a link to related websites. ', verbose_name='External Resource Link'))]))], help_text='Additional file with supplemental information related to this alert information', label='Resources', required=False)), ('parameter', wagtail.blocks.ListBlock(wagtail.blocks.StructBlock([('valueName', wagtail.blocks.TextBlock(label='Name')), ('value', wagtail.blocks.TextBlock(label='Value'))], label='Parameter'), default=[], label='Parameters')), ('eventCode', wagtail.blocks.ListBlock(wagtail.blocks.StructBlock([('valueName', wagtail.blocks.TextBlock(help_text='Name for the event code', label='Name')), ('value', wagtail.blocks.TextBlock(help_text='Value of the event code', label='Value'))], label='Event Code'), default=[], label='Event codes'))], label='Alert Information'))], blank=True, null=True, use_json_field=True, verbose_name='Alert Information'),
+ ),
+ ]
diff --git a/sandbox/home/models.py b/sandbox/home/models.py
index 37072f2..b130e92 100644
--- a/sandbox/home/models.py
+++ b/sandbox/home/models.py
@@ -4,7 +4,6 @@
from django.db import models
from django.urls import reverse
from django.utils.functional import cached_property
-from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _, gettext_lazy
from wagtail.admin.panels import MultiFieldPanel, FieldPanel
from wagtail.admin.widgets.slug import SlugInput
@@ -99,24 +98,30 @@ def xml_link(self):
def on_publish_cap_alert(sender, **kwargs):
instance = kwargs['instance']
- # publish to mqtt
- topic = "cap/alerts/all"
- publish_cap_mqtt_message(instance, topic)
-
- # create summary image
- image_content_file = instance.generate_alert_card_image()
- if image_content_file:
-
- # delete old image
- if instance.search_image:
- instance.search_image.delete()
-
- # create new image
- instance.search_image = Image(title=instance.title, file=image_content_file)
- instance.search_image.save()
-
- # save the instance
- instance.save()
+ try:
+ # publish to mqtt
+ topic = "cap/alerts/all"
+ publish_cap_mqtt_message(instance, topic)
+ except Exception as e:
+ pass
+
+ try:
+ # create summary image
+ image_content_file = instance.generate_alert_card_image()
+ if image_content_file:
+
+ # delete old image
+ if instance.search_image:
+ instance.search_image.delete()
+
+ # create new image
+ instance.search_image = Image(title=instance.title, file=image_content_file)
+ instance.search_image.save()
+
+ # save the instance
+ instance.save()
+ except Exception as e:
+ pass
page_published.connect(on_publish_cap_alert, sender=CapAlertPage)
diff --git a/sandbox/home/wagtail_hooks.py b/sandbox/home/wagtail_hooks.py
index 443352e..46495ab 100644
--- a/sandbox/home/wagtail_hooks.py
+++ b/sandbox/home/wagtail_hooks.py
@@ -1,6 +1,286 @@
+import json
+from datetime import datetime
+
+import pytz
from adminboundarymanager.wagtail_hooks import AdminBoundaryManagerAdminGroup
+from django.shortcuts import redirect
+from django.urls import reverse
+from django.utils import timezone
+from django.utils.translation import gettext as _
+from wagtail import hooks
+from wagtail.admin import messages
+from wagtail.admin.menu import Menu, MenuItem
+from wagtail.blocks import StreamValue
+from wagtail_modeladmin.menus import GroupMenuItem
from wagtail_modeladmin.options import (
- modeladmin_register
+ modeladmin_register, ModelAdmin, ModelAdminGroup
)
+from capeditor.cap_settings import CapSetting, get_cap_contact_list, get_cap_audience_list
+from .models import CapAlertPage, HomePage
+
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 CAPMenuGroupAdminMenuItem(GroupMenuItem):
+ def is_shown(self, request):
+ return request.user.has_perm("base.can_view_alerts_menu")
+
+
+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_menu_item(self, order=None):
+ if self.modeladmin_instances:
+ submenu = Menu(items=self.get_submenu_items())
+ return CAPMenuGroupAdminMenuItem(self, self.get_menu_order(), submenu)
+
+ 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:
+
+ # add CAP import menu
+ settings_url = reverse("load_cap_alert")
+ import_cap_menu = MenuItem(label=_("Import CAP Alert"), url=settings_url, icon_name="upload")
+ menu_items.append(import_cap_menu)
+
+ # add settings menu
+ settings_url = reverse(
+ "wagtailsettings:edit",
+ args=[CapSetting._meta.app_label, CapSetting._meta.model_name, ],
+ )
+ gm_settings_menu = MenuItem(label=_("CAP Base Settings"), url=settings_url, icon_name="cog")
+ menu_items.append(gm_settings_menu)
+
+ except Exception:
+ pass
+
+ return menu_items
+
+
+modeladmin_register(CAPMenuGroup)
+
+
+@hooks.register('construct_settings_menu')
+def hide_settings_menu_item(request, menu_items):
+ hidden_settings = ["cap-settings"]
+ menu_items[:] = [item for item in menu_items if item.name not in hidden_settings]
+
+
+@hooks.register("before_import_cap_alert")
+def import_cap_alert(request, alert_data):
+ cap_settings = CapSetting.for_request(request)
+ hazard_event_types = cap_settings.hazard_event_types.all()
+
+ base_data = {}
+
+ # an alert page requires a title
+ # here we use the headline of the first info block
+ title = None
+
+ if "sender" in alert_data:
+ base_data["sender"] = alert_data["sender"]
+ if "sent" in alert_data:
+ sent = alert_data["sent"]
+ # convert dates to local timezone
+ sent = datetime.fromisoformat(sent).astimezone(pytz.utc)
+ sent_local = sent.astimezone(timezone.get_current_timezone())
+ base_data["sent"] = sent_local
+ if "status" in alert_data:
+ base_data["status"] = alert_data["status"]
+ if "msgType" in alert_data:
+ base_data["msgType"] = alert_data["msgType"]
+ if "scope" in alert_data:
+ base_data["scope"] = alert_data["scope"]
+ if "restriction" in alert_data:
+ base_data["restriction"] = alert_data["restriction"]
+ if "note" in alert_data:
+ base_data["note"] = alert_data["note"]
+
+ info_blocks = []
+
+ if "info" in alert_data:
+ for info in alert_data.get("info"):
+ info_base_data = {}
+
+ if "language" in info:
+ info_base_data["language"] = info["language"]
+ if "category" in info:
+ info_base_data["category"] = info["category"]
+ if "event" in info:
+ event = info["event"]
+
+ existing_hazard_event_type = hazard_event_types.filter(event__iexact=event).first()
+ if existing_hazard_event_type:
+ info_base_data["event"] = existing_hazard_event_type.event
+ else:
+ hazard_event_types.create(setting=cap_settings, is_in_wmo_event_types_list=False, event=event,
+ icon="warning")
+ info_base_data["event"] = event
+
+ if "responseType" in info:
+ response_types = info["responseType"]
+ response_type_data = []
+ for response_type in response_types:
+ response_type_data.append({"response_type": response_type})
+ info_base_data["responseType"] = response_type_data
+
+ if "urgency" in info:
+ info_base_data["urgency"] = info["urgency"]
+ if "severity" in info:
+ info_base_data["severity"] = info["severity"]
+ if "certainty" in info:
+ info_base_data["certainty"] = info["certainty"]
+ if "eventCode" in info:
+ event_codes = info["eventCode"]
+ event_code_data = []
+ for event_code in event_codes:
+ event_code_data.append({"valueName": event_code["valueName"], "value": event_code["value"]})
+ info_base_data["eventCode"] = event_code_data
+ if "effective" in info:
+ effective = info["effective"]
+ effective = datetime.fromisoformat(effective).astimezone(pytz.utc)
+ effective_local = effective.astimezone(timezone.get_current_timezone())
+ info_base_data["effective"] = effective_local
+ if "onset" in info:
+ onset = info["onset"]
+ onset = datetime.fromisoformat(onset).astimezone(pytz.utc)
+ onset_local = onset.astimezone(timezone.get_current_timezone())
+ info_base_data["onset"] = onset_local
+ if "expires" in info:
+ expires = info["expires"]
+ expires = datetime.fromisoformat(expires).astimezone(pytz.utc)
+ expires_local = expires.astimezone(timezone.get_current_timezone())
+ info_base_data["expires"] = expires_local
+ if "senderName" in info:
+ info_base_data["senderName"] = info["senderName"]
+ if "headline" in info:
+ info_base_data["headline"] = info["headline"]
+ if not title:
+ title = info["headline"]
+
+ if "description" in info:
+ info_base_data["description"] = info["description"]
+ if "instruction" in info:
+ info_base_data["instruction"] = info["instruction"]
+ if "contact" in info:
+ contact = info["contact"]
+ contact_list = get_cap_contact_list(request)
+ if contact not in contact_list:
+ cap_settings.contacts.append(("contact", {"contact": contact}))
+ cap_settings.save()
+ info_base_data["contact"] = contact
+ if "audience" in info:
+ audience = info["audience"]
+ audience_list = get_cap_audience_list(request)
+ if audience not in audience_list:
+ cap_settings.audience_types.append(("audience_type", {"audience": audience}))
+ cap_settings.save()
+ info_base_data["audience"] = audience
+
+ if "parameter" in info:
+ parameters = info["parameter"]
+ parameter_data = []
+ for parameter in parameters:
+ parameter_data.append({"valueName": parameter["valueName"], "value": parameter["value"]})
+ info_base_data["parameter"] = parameter_data
+ if "resource" in info:
+ resources = info["resource"]
+ resource_data = []
+ for resource in resources:
+ if resource.get("uri") and resource.get("resourceDesc"):
+ resource_data.append({
+ "type": "external_resource",
+ "value": {
+ "external_url": resource["uri"],
+ "resourceDesc": resource["resourceDesc"]
+ }
+ })
+ info_base_data["resource"] = resource_data
+
+ areas_data = []
+ if "area" in info:
+ for area in info.get("area"):
+ area_data = {}
+ areaDesc = area.get("areaDesc")
+
+ if "geocode" in area:
+ area_data["type"] = "geocode_block"
+ geocode = area.get("geocode")
+ geocode_data = {
+ "areaDesc": areaDesc,
+ }
+ if "valueName" in geocode:
+ geocode_data["valueName"] = geocode["valueName"]
+ if "value" in geocode:
+ geocode_data["value"] = geocode["value"]
+
+ area_data["value"] = geocode_data
+
+ if "polygon" in area:
+ area_data["type"] = "polygon_block"
+ polygon_data = {
+ "areaDesc": areaDesc,
+ }
+ geometry = area.get("geometry")
+ polygon_data["polygon"] = json.dumps(geometry)
+
+ area_data["value"] = polygon_data
+
+ if "circle" in area:
+ area_data["type"] = "circle_block"
+ circle_data = {
+ "areaDesc": areaDesc,
+ }
+ circle = area.get("circle")
+ # take the first circle for now
+ # TODO: handle multiple circles ? Investigate use case
+ circle_data["circle"] = circle[0]
+ area_data["value"] = circle_data
+
+ areas_data.append(area_data)
+
+ stream_item = {
+ "type": "alert_info",
+ "value": {
+ **info_base_data,
+ "area": areas_data,
+ },
+ }
+
+ info_blocks.append(stream_item)
+
+ if title:
+ base_data["title"] = title
+ new_cap_alert_page = CapAlertPage(**base_data, live=False)
+ new_cap_alert_page.info = StreamValue(new_cap_alert_page.info.stream_block, info_blocks, is_lazy=True)
+
+ cap_list_page = HomePage.objects.live().first()
+
+ if cap_list_page:
+ cap_list_page.add_child(instance=new_cap_alert_page)
+ cap_list_page.save_revision()
+
+ messages.success(request, _("CAP Alert draft created. You can now edit the alert."))
+
+ return redirect(reverse("wagtailadmin_pages:edit", args=[new_cap_alert_page.id]))
+
+ return None
diff --git a/sandbox/sandbox/settings/base.py b/sandbox/sandbox/settings/base.py
index 1ac722e..ea52830 100644
--- a/sandbox/sandbox/settings/base.py
+++ b/sandbox/sandbox/settings/base.py
@@ -166,7 +166,7 @@
('sw', 'Swahili'),
]
-TIME_ZONE = "UTC"
+TIME_ZONE = "Africa/Nairobi"
USE_I18N = True
@@ -223,3 +223,5 @@
}
CAP_BROKER_URI = env.str("CAP_BROKER_URI", default="")
+
+DATA_UPLOAD_MAX_MEMORY_SIZE = env.int("DATA_UPLOAD_MAX_MEMORY_SIZE", default=26214400) # 25MB
diff --git a/setup.cfg b/setup.cfg
index c0404eb..5af6410 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,6 +1,6 @@
[metadata]
name = capeditor
-version = 0.5.1
+version = 0.5.2
description = Wagtail based CAP composer
long_description = file:README.md
long_description_content_type = text/markdown
@@ -38,5 +38,6 @@ install_requires =
geopandas
matplotlib
cartopy
+ xmltodict