Package: capeditor
CAP ComposerAWagtailbased Common Alerting Protocol (CAP) Warning Composer. This is a web-based tool for
creating and managing CAP alerts. It is designed to be used by meteorological and hydrological services, disaster
management agencies, and other organizations that need to create and disseminate CAP alerts.TheCommon Alerting Protocol (CAP)provides an open, non-proprietary digital message format for all types of alerts
and notifications. It does not address any particular application or telecommunications method. The CAP format is
compatible with emerging techniques, such as Web services, as well as existing formats including the Specific Area
Message Encoding (SAME) used for the United States' National Oceanic and Atmospheric Administration (NOAA) Weather Radio
and the Emergency Alert System (EAS)The CAP xml response follows the structure of the schema provided athttp://docs.oasis-open.org/emergency/cap/v1.2/CAP-v1.2-os.htmlContentsCAP ComposerFeaturesQuick startUsageCreating a CAP AlertSections in the Alert Page and corresponding XMLA. Alert IdentificationB. Alert InfoC. Alert AreaD. Alert ResourceIntegrations🌟 FeaturesModern user-friendly composer that followsCAP 1.2standard. Built on top of the awesomeWagtail CMSPreview a CAP alert as you edit. Save drafts for sharing with colleagues and collaboratingInbuilt CAP validation. The page will not save if you have not input the required data according to CAP standardUser-friendly alert area map tool that allows multiple ways of constructing alert geographic areas, while keeping the
interface simpleSelect country official administrative boundaries for different levels (Admin 1, Admin 2, Admin 3), with in-built
simplification of complex boundariesDraw a polygonDraw a circleUse Geocode key valuesInbuilt publishing workflow using Wagtail's powerful page model, with automated emails to composers and approversCollaborate with team members using inbuilt comments (similar to how you could do in Word) with automated
notifications. Request for changes and approvalsPublish realtime notifications/messages to third party integrations using MQTT messaging protocolPredefine a list of hazards types monitored by your institution, with intuitive icons
fromOCHA humanitarian iconsExtendable to add your custom logic and functionality. The package provides anabstractdjango model that can be
inherited for customizations. It is all python code.Quick start1. Install in virtualenvironment using pippipinstallcapeditor2. Configure settingsIn yoursettings.pyorsettings/base.py, within the installed apps, include therest_framework, rest_framework_xmlandcapeditoras below:INSTALLED_APPS=[# ...'rest_framework','rest_framework_xml','capeditor']Set up restframeworkxml renderersREST_FRAMEWORK={'DEFAULT_RENDERER_CLASSES':('rest_framework.renderers.JSONRenderer','rest_framework_xml.renderers.XMLRenderer',# add XMLRenderer),'DEFAULT_PARSER_CLASSES':('rest_framework_xml.parsers.XMLParser',),}3. Run model migrationspythonmanage.pymigrateUsageCreating a CAP AlertWith CAP composer successfully installed, both the Alert Listing page and Alert Detail page will be available on wagtail
admin interface.- AlertList
   |_ Alert 1
   |_ Alert 2Create anAlert Listing Pageby adding it as a child page and specifying the title of the page. This page will host a
list of all alerts created.Create one or moreAlert Pageby adding it as a child to theAlert Listing PageSections in the Alert Page and corresponding XMLThe overall Document Object Model of an alert is as below:Alert IdentificationIt contains the following entities required for a valid CAP message:Sender ID(sender),Sent Dat/Time (sent),Message Status (status),Message Type (msgType),Scope(scope),Restriction (restriction),Addresses (addresses),Note (note),Reference IDs (references) andIncident ids (incidents).The alert identifier is generated automatically and is not editable.NOTE:Some fields are visible based on selection of different parameters.Alert InfoCorresponds to the<info>element in the CAP message. The  entity specifies the alert's details. At least
one  block is required for an alert. If you support multiple languages, it is recommended that you use one 
block for each language for the same  entity.:A CAP message expects at least one<info>element to be present. Multiple<info>blocks should all have the
same<category>and<event>element values.EachInformationblock contains the following elements:Language (Language)Event Category/Categories (category)Event Type (event)Response Type/Types (responseType)Urgency (urgency)Severity (severity)Certainty (certainty)Audience (audience)Event Code/Codes (eventCode)Effective Date/Time (effective)Onset Date/Time (onset)Expiration Date/Time (expires)Sender Name (senderName)Headline(headline)Event description (description)Instructions (instruction)Information URL (web),Contact Info (contact) andParameter/Parameters(parameter)C. Alert AreaInformation Entity that defines the geographic area to be notified. Multiple areas can be defined in the alert. Each
area contains the following elements:Area Description (areaDesc),Area Polygon/Polygons (polygon),Area Circle/Circles (circle),Area Geocode/Geocodes (geocode),Altitude (altitude),Ceiling (ceiling)The Alert area input has 4 selector options:Admin Boundary (area is picked from predefined boundaries). To use this option, ensure that admin boundaries are
initially loaded. Refer toSetting up boundariessection.Polygon (drawing a polygon)Circle (drawing a circle which specifies the latitude, longitude and radius)Geocode (specifying area geocode name and value). Using this option presumes knowledge of the coding systemAlert ResourceEntity that defines supplemental information related to an  object Multiple instances of this section are allowed.
It contains:Description (resourceDesc), MIME Type (mimeType), File Size (size), URI (uri), Dereferenced URI (derefUri) and
Digest (digest)**The Alert resource input has 2 selector options:File resource (takes in a file and description)External resourceIntegrationsTo integrate the alerts to another wagtail page and include in templates, for example in the home page refer to sandbox
folder for sample standalone.MQTT IntegrationYou can publish a mqtt message immediately after a CAP alert has been published. This allows connected clients to
receive the CAP message using the MQTT protocol.You will need to setup a MQTT broker. We have included the docker configuration to setup a local broker instance
usingEclipse MosquittoYou need to add aCAP_BROKER_URIsetting to yoursettings.pywhich should be the URI to a MQTT broker with
permissions to publish messages.Then usingWagtail page_published signalorWagtail after_publish_page hook, you
can attach a function to publish the MQTT message.Below is a sample snippet to achieve this in yourmodels.py# models.pyfromwagtail.signalsimportpage_publishedfromcapeditor.modelsimportAbstractCapAlertPagefromcapeditor.pubsub.publishimportpublish_cap_mqtt_messageclassCapAlertPage(AbstractCapAlertPage):....defon_publish_cap_alert(sender,**kwargs):instance=kwargs['instance']topic="cap/alerts/all"publish_cap_mqtt_message(instance,topic)page_published.connect(on_publish_cap_alert,sender=CapAlertPage)Using the sample above, once a CAP Alert Page has published, a correspondingmqtt messagewill also be published
immediately.You will need to decide how to structure your MQTT alert topics.You can have a complete look at the code undersandbox/home/models.py