Skip to content

Commit

Permalink
Merge pull request #22 from wmo-raf/dev
Browse files Browse the repository at this point in the history
Updates and Bug Fixes
  • Loading branch information
erick-otenyo authored Apr 29, 2024
2 parents 3c5d425 + 0756c97 commit 9008fe9
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 479 deletions.
4 changes: 2 additions & 2 deletions capeditor/cap_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

@register_setting
class CapSetting(BaseSiteSetting, ClusterableModel):
sender = models.CharField(max_length=255, blank=True, null=True, verbose_name=_("CAP Sender Identifier"),
help_text=_("Can be the website link or email of the sending institution"))
sender = models.CharField(max_length=255, blank=True, null=True, verbose_name=_("CAP Sender Email"),
help_text=_("Email of the sending institution"))
sender_name = models.CharField(max_length=255, blank=True, null=True, verbose_name=_("CAP Sender Name"),
help_text=_("Name of the sending institution"))
logo = models.ForeignKey("wagtailimages.Image", null=True, blank=True, on_delete=models.SET_NULL, related_name="+",
Expand Down
18 changes: 18 additions & 0 deletions capeditor/migrations/0005_alter_capsetting_sender.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.11 on 2024-04-29 07:19

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('capeditor', '0004_predefinedalertarea'),
]

operations = [
migrations.AlterField(
model_name='capsetting',
name='sender',
field=models.CharField(blank=True, help_text='Email of the sending institution', max_length=255, null=True, verbose_name='CAP Sender Email'),
),
]
58 changes: 3 additions & 55 deletions capeditor/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import os
import uuid

from adminboundarymanager.models import AdminBoundarySettings
from django.conf import settings
from django.utils import timezone
from django.utils.functional import cached_property
from django.utils.translation import gettext_lazy as _
Expand All @@ -22,7 +19,6 @@
AlertIncident
)
from capeditor.constants import SEVERITY_MAPPING, URGENCY_MAPPING, CERTAINTY_MAPPING
from capeditor.shareable.png import cap_geojson_to_image, CapAlertCardImage
from .cap_settings import *


Expand Down Expand Up @@ -156,15 +152,12 @@ class AbstractCapAlertPage(Page):
"<status> 'Exercise' and <msgType> 'Error'"), verbose_name=_("Note"))
info = StreamField([
("alert_info", AlertInfo(label=_("Alert Information")))
], block_counts={
'alert_info': {'min_num': 1},
}, use_json_field=True, blank=True,
null=True, verbose_name=_("Alert Information"), )
], use_json_field=True, min_num=1, max_num=1, block_counts={'alert_info': {'max_num': 1, "min_num": 1}, },
verbose_name=_("Alert Information"), )

addresses = StreamField([
("recipient", AlertAddress(label=_("Recipient")))
], use_json_field=True, blank=True,
null=True, verbose_name=_("Addresses"),
], use_json_field=True, blank=True, null=True, verbose_name=_("Addresses"),
help_text=_("The group listing of intended recipients of the alert message, if scope is Private"))

references = StreamField([
Expand Down Expand Up @@ -317,48 +310,3 @@ def get_geojson_features(self, request=None):
features.append(feature)

return features

def generate_alert_card_image(self):

site = Site.objects.get(is_default_site=True)

abm_settings = AdminBoundarySettings.for_site(site)
cap_settings = CapSetting.for_site(site)
abm_extents = abm_settings.combined_countries_bounds

info = self.infos[0]

features = self.get_geojson_features()
if features:
feature_coll = {
"type": "FeatureCollection",
"features": features,
}

if abm_extents:
# format to what matplotlib expects
abm_extents = [abm_extents[0], abm_extents[2], abm_extents[1], abm_extents[3]]

cap_detail = {
"title": self.title,
"event": info.get("event"),
"sent_on": self.sent,
"org_name": cap_settings.sender_name,
"severity": info.get("severity"),
"properties": info.get("properties"),
}

org_logo = cap_settings.logo
if org_logo:
cap_detail.update({
"org_logo_file": os.path.join(settings.MEDIA_ROOT, org_logo.file.path)
})

map_img_buffer = cap_geojson_to_image(feature_coll, abm_extents)

image_content_file = CapAlertCardImage(map_img_buffer, cap_detail,
f"{self.identifier}.png").render()

return image_content_file

return None
Empty file removed capeditor/shareable/__init__.py
Empty file.
Loading

0 comments on commit 9008fe9

Please sign in to comment.