Skip to content

Commit

Permalink
Merge pull request #242 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 Jul 17, 2024
2 parents 7b18f4b + 0eacaad commit 33b1b18
Show file tree
Hide file tree
Showing 33 changed files with 822 additions and 549 deletions.
11 changes: 0 additions & 11 deletions base/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,6 @@ class Meta:
template = "streams/table_block.html"


class WhatWeDoBlock(blocks.StructBlock):
icon = IconChooserBlock(required=False, label=_("Icon"))
title = blocks.CharBlock(max_length=60, required=False)
description = blocks.RichTextBlock(features=SUMMARY_RICHTEXT_FEATURES)

class Meta:
template = 'streams/what_we_do_block.html'
icon = 'placeholder'
label = _("What we do")


class SocialMediaBlock(blocks.StructBlock):
name = blocks.CharBlock(max_length=60, )
icon = IconChooserBlock(required=False, label=_("Icon"))
Expand Down
44 changes: 24 additions & 20 deletions base/templates/streams/feature_block.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
{% load wagtailcore_tags wagtailimages_tags %}

{% if value.figure_type == "image" and value.image %}
<div class="container">
<div class="columns alternate-container">
{% if is_even %}
<div class="column is-half-desktop is-full-mobile">
{% include 'streams/feature_block_detail_include.html' with value=value %}
</div>
<div class="column is-half-desktop is-full-mobile">
{% include 'streams/feature_block_figure_include.html' with value=value %}
</div>

<div class="container">
<div class="columns alternate-container">
{% if is_even %}
<div class="column is-half-desktop is-full-mobile">
{% include 'streams/feature_block_detail_include.html' with value=value %}
</div>
<div class="column is-half-desktop is-full-mobile">
{% include 'streams/feature_block_figure_include.html' with value=value %}
</div>

{% else %}

<div class="column is-half-desktop is-full-mobile">
{% include 'streams/feature_block_figure_include.html' with value=value %}
</div>
<div class="column is-half-desktop is-full-mobile">
{% include 'streams/feature_block_detail_include.html' with value=value %}
</div>
{% endif %}
{% else %}

<div class="column is-half-desktop is-full-mobile">
{% include 'streams/feature_block_figure_include.html' with value=value %}
</div>
<div class="column is-half-desktop is-full-mobile">
{% include 'streams/feature_block_detail_include.html' with value=value %}
</div>
{% endif %}
</div>
</div>
</div>
{% endif %}






90 changes: 0 additions & 90 deletions base/templates/streams/what_we_do_block.html

This file was deleted.

2 changes: 1 addition & 1 deletion nmhs_cms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# major.minor.patch.release.number
# release must be one of alpha, beta, rc, or final
VERSION = (0, 9, 0, "final", 0)
VERSION = (0, 9, 1, "beta", 1)

__version__ = get_version(VERSION)

Expand Down
25 changes: 1 addition & 24 deletions nmhs_cms/static/css/nmhs_cms.css
Original file line number Diff line number Diff line change
Expand Up @@ -118,29 +118,6 @@ select#city-option {
color: #ffffff !important; /* Change the text color of the selected option */
}

select#city-option option{
select#city-option option {
color: black !important;
}

/* Width and height of the scrollbar */
::-webkit-scrollbar {
width: 1px; /* Width of the vertical scrollbar */
height: 1px; /* Height of the horizontal scrollbar */
}

/* Track */
::-webkit-scrollbar-track {
background: #f1f1f110;
border-radius: 10px;
}

/* Handle */
::-webkit-scrollbar-thumb {
background: #ffffff;
border-radius: 10px;
}

/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
background: var(--primary-color);
}
35 changes: 0 additions & 35 deletions nmhs_cms/templates/what_we_do_section.html

This file was deleted.

35 changes: 30 additions & 5 deletions pages/cap/sign.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from xml.etree import ElementTree as ET

from django.conf import settings
from lxml import etree
from signxml import XMLSigner, SignatureMethod
from lxml import etree as lxml_ET
from signxml import XMLSigner, SignatureMethod, XMLVerifier

cap_cert_path = getattr(settings, "CAP_CERT_PATH", "")
cap_private_key_path = getattr(settings, "CAP_PRIVATE_KEY_PATH", "")
cap_signature_method = getattr(settings, "CAP_SIGNATURE_METHOD", SignatureMethod.RSA_SHA256)


def sign_xml(xml_string):
def sign_cap_xml(xml_bytes):
if not cap_cert_path or not cap_private_key_path:
return None

Expand All @@ -17,6 +19,29 @@ def sign_xml(xml_string):
with open(cap_cert_path, "rb") as cert_file:
cert = cert_file.read()

root = etree.fromstring(xml_string)
# register cap namespace¬
ET.register_namespace("cap", "urn:oasis:names:tc:emergency:cap:1.2")
root = ET.fromstring(xml_bytes)

# specify location for enveloped signature
# https://technotes.shemyak.com/posts/xml-signatures-with-python-elementtree/
# https://xml-security.github.io/signxml/#signxml.XMLSigner
ET.register_namespace("ds", "http://www.w3.org/2000/09/xmldsig#")
ET.SubElement(root, "ds:Signature", {"xmlns:ds": "http://www.w3.org/2000/09/xmldsig#", "Id": "placeholder"})

signed_root = XMLSigner(signature_algorithm=cap_signature_method).sign(root, key=key, cert=cert)
return etree.tostring(signed_root)

return lxml_ET.tostring(signed_root)


def verify_cap_xml(xml_bytes):
if not cap_cert_path:
return False

root = lxml_ET.fromstring(xml_bytes)

try:
verified_data = XMLVerifier().verify(root).signed_xml
return True
except Exception as e:
return False
4 changes: 2 additions & 2 deletions pages/cap/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from base.models import ImportantPages
from base.weasyprint_utils import django_url_fetcher
from pages.cap.constants import DEFAULT_STYLE, CAP_LAYERS
from .sign import sign_xml
from .sign import sign_cap_xml


def create_cap_geomanager_dataset(cap_geomanager_settings, has_live_alerts, request=None):
Expand Down Expand Up @@ -264,7 +264,7 @@ def serialize_and_sign_cap_alert(alert, request=None):
signed = False

try:
signed_xml = sign_xml(xml_bytes)
signed_xml = sign_cap_xml(xml_bytes)
if signed_xml:
xml = signed_xml
signed = True
Expand Down
37 changes: 37 additions & 0 deletions pages/cap/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,42 @@ def add_root_elements(self, handler):
except Exception as e:
pass

def add_item_elements(self, handler, item):
handler.addQuickElement("title", item["title"])
handler.addQuickElement("link", item["link"], attrs={"type": "application/cap+xml"})
if item["description"] is not None:
handler.addQuickElement("description", item["description"])

# Author information.
if item["author_name"] and item["author_email"]:
handler.addQuickElement(
"author", "%s (%s)" % (item["author_email"], item["author_name"])
)
elif item["author_email"]:
handler.addQuickElement("author", item["author_email"])
elif item["author_name"]:
handler.addQuickElement(
"dc:creator",
item["author_name"],
{"xmlns:dc": "http://purl.org/dc/elements/1.1/"},
)

if item["pubdate"] is not None:
handler.addQuickElement("pubDate", rfc2822_date(item["pubdate"]))
if item["comments"] is not None:
handler.addQuickElement("comments", item["comments"])
if item["unique_id"] is not None:
guid_attrs = {}
if isinstance(item.get("unique_id_is_permalink"), bool):
guid_attrs["isPermaLink"] = str(item["unique_id_is_permalink"]).lower()
handler.addQuickElement("guid", item["unique_id"], guid_attrs)
if item["ttl"] is not None:
handler.addQuickElement("ttl", item["ttl"])

# Categories.
for cat in item["categories"]:
handler.addQuickElement("category", cat)


class AlertListFeed(Feed):
feed_copyright = "public domain"
Expand Down Expand Up @@ -177,6 +213,7 @@ def get_cap_xml(request, guid):

if not xml:
xml, signed = serialize_and_sign_cap_alert(alert, request)
xml = xml.decode("utf-8")

if signed:
# cache signed alerts for 5 days
Expand Down
25 changes: 19 additions & 6 deletions pages/glossary/templates/glossary/glossary_index_page.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'base.html' %}
{% load static wagtailiconchooser_tags i18n %}
{% load static wagtailiconchooser_tags i18n wagtailcore_tags %}

{% block extra_css %}
{% endblock %}
Expand All @@ -8,11 +8,24 @@

{% block content %}
<main class="is-index">
<section class="nmhs-work is-desktop">
<div class="work container">
{% include 'service_introduction.html' with page=page what_we_do=False %}
</div>
</section>
{% if page.introduction_image %}
<section class="nmhs-work">
<div class="work container">
{% include 'service_introduction.html' with page=page %}
</div>
</section>
{% else %}
<section class="nmhs-work intro-section">
<div class="work container">
<h2 class="section-subheader">
{{ page.introduction_title }}
</h2>
<div class="intro-description format-text">
{{ page.introduction_text|richtext }}
</div>
</div>
</section>
{% endif %}
<section id="glossary-items" class="listing-section">
<h2 id="results" class="section-title center">
{% translate "Browse Terms" %}
Expand Down
Loading

0 comments on commit 33b1b18

Please sign in to comment.