Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bulletin Form for OCD PH #1470

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions modules/s3cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2683,6 +2683,27 @@ def get_cap_area_default(self):

return self.cap.get("area_default", ["geocode", "polygon"])

def get_cap_bulletin_method(self):
"""
Name of the method that is used to generate the bulletin for this deployment
"""

return self.cap.get("bulletin_method")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems odd to have this be configurable via settings like this?
What I would propose would be an S3Method for cap/alert/[id]/bulletin
This would still allow the template to define a custom function in config.py


def get_cap_bulletin_officer(self):
"""
Name of the officer who is responsible to issue the bulletin
"""

return self.cap.get("bulletin_officer", "Name of Officer")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stuff seems too dynamic to want to put into settings...although that is about to become more accessible via WebSetup.
Until then it would be better as a DB table? (Even with WebSetup, a DB table provides better UX)


def get_cap_bulltin_officer_designation(self):
"""
Designation of the officer who is responsible to issue the bulletin
"""

return self.cap.get("bulletin_officer_designation", "Designation")

# -------------------------------------------------------------------------
# CMS: Content Management System
#
Expand Down
54 changes: 42 additions & 12 deletions modules/s3db/cap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3358,6 +3358,7 @@ def cap_rheader(r):
db = current.db
s3db = current.s3db
tablename = r.tablename
settings = current.deployment_settings
if tablename == "cap_alert":
alert_id = record.id
itable = s3db.cap_info
Expand Down Expand Up @@ -3411,6 +3412,7 @@ def cap_rheader(r):
else:
action_btn = None
msg_type_buttons = None
bulletin_btns = []
if not row:
error = DIV(T("You need to create at least one alert information item in order to be able to broadcast this alert!"),
_class="error")
Expand All @@ -3424,26 +3426,50 @@ def cap_rheader(r):

has_permission = current.auth.s3_has_permission
# Display 'Submit for Approval', 'Publish Alert' or
# 'Review Alert' based on permission and deployment settings
# 'Review Alert' and Bulletin Form print button based
# on permission and deployment settings
if not current.request.get_vars.get("_next") and \
current.deployment_settings.get_cap_authorisation() and \
settings.get_cap_authorisation() and \
record.approved_by is None:
# Show these buttons only if there is atleast one area segment
area_table = s3db.cap_area
area_row = db(area_table.alert_id == alert_id).\
select(area_table.id,
limitby=(0, 1)).first()
if area_row and has_permission("update", "cap_alert",
if area_row:
# Show these buttons only if there is at least one area segment
cap_bulletin_method = settings.get_cap_bulletin_method()
if cap_bulletin_method:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If using the S3Method & DB configuration, the cap_bulletin table could be queried & if there is an undeleted row then proceed to add the buttons

irows = db(itable.alert_id == alert_id).select(\
itable.language)
for irow in irows:
language = irow.language
btn = A(T("%s Form" % (itable.language.represent(language))),
_href = URL(c = "default",
f = "index",
args = [cap_bulletin_method],
vars = {"lan": language,
"alert_id": alert_id,
}
),
_class = "action-btn button tiny",
_target = "_blank",
)
bulletin_btns.append(btn)

# Display 'Submit for Approval', 'Publish Alert' or
# 'Review Alert' based on permission and deployment settings
if has_permission("update", "cap_alert",
record_id=alert_id):
action_btn = A(T("Submit for Approval"),
_href = URL(f = "notify_approver",
vars = {"cap_alert.id": alert_id,
},
),
_class = "action-btn confirm-btn button tiny"
)
current.response.s3.jquery_ready.append(
'''S3.confirmClick('.confirm-btn','%s')''' % T("Do you want to submit the alert for approval?"))
action_btn = A(T("Submit for Approval"),
_href = URL(f = "notify_approver",
vars = {"cap_alert.id": alert_id,
},
),
_class = "action-btn confirm-btn button tiny"
)
current.response.s3.jquery_ready.append(
'''S3.confirmClick('.confirm-btn','%s')''' % T("Do you want to submit the alert for approval?"))

# For Alert Approver
if has_permission("approve", "cap_alert"):
Expand Down Expand Up @@ -3555,6 +3581,10 @@ def cap_rheader(r):
if msg_type_buttons is not None:
rheader.insert(1, msg_type_buttons)

if len(bulletin_btns):
for bulletin_btn in bulletin_btns:
rheader.insert(1, bulletin_btn)

elif tablename == "cap_area":
# Used only for Area Templates
tabs = [(T("Area"), None),
Expand Down
1 change: 0 additions & 1 deletion modules/templates/SAMBRO/Demo/organisation.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Organisation,KV:cap_oid,Acronym,Type,Country,Website,Twitter,Comments
Abteilung Wasserhaushal,2.49.0.0.40.1,Acronym,Type,Country,Website,Twitter,Comments
Department of Hydrology and Meteorology,2.49.0.0.524.0,DHM,Government,NP,www.dhm.gov.np,,
Department of Meteorology and Hydrology,2.49.0.0.428.0,DMH,Government,MM,www.dmh.gov.mm,,
National Disaster Management Center,2.49.0.0.462.1,NDMC,Government,MV,ndmc.gov.mv,,
Expand Down
4 changes: 4 additions & 0 deletions modules/templates/SAMBRO/PH/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ def config(settings):
args = ["SAMBRO", "PH", "img", "pagasa.png"],
)

# Name of Method used to create bulletin
# This may vary according to organization implementing it
settings.cap.bulletin_method = "bulletin_ocd"

# END =========================================================================
77 changes: 77 additions & 0 deletions modules/templates/SAMBRO/PH/controllers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,86 @@
# -*- coding: utf-8 -*-

from gluon import current
from gluon.html import *

from s3 import S3CustomController, s3_str

from templates.SAMBRO.controllers import index, subscriptions, user_info, alert_hub_cop

# -----------------------------------------------------------------------------
class alert_map(index):
pass

# -----------------------------------------------------------------------------
class index(alert_hub_cop):
pass

# -----------------------------------------------------------------------------
class bulletin_ocd(S3CustomController):
""" Generate the Bulletin for OCD """

def __call__(self):
""" Main entry point, configuration """

r = current.request

alert_id = r.vars.get("alert_id")
if not alert_id:
return "alert id is required to generate report"

language = r.vars.get("lan", "en-US")
current.response.view = "../modules/templates/SAMBRO/PH/views/bulletin_ocd.html"
s3db = current.s3db
table = s3db.cap_alert
itable = s3db.cap_info
atable = s3db.cap_area
ptable = s3db.cap_info_parameter
query = (table.id == alert_id) & \
(table.deleted != True) & \
(itable.alert_id == table.id) & \
(itable.deleted != True) & \
(itable.language == language) & \
(atable.alert_id == table.id) & \
(atable.deleted != True) & \
(ptable.info_id == itable.id) & \
(ptable.deleted != True)

arows = current.db(query).select(table.status,
table.source,
itable.description,
itable.instruction,
itable.headline,
itable.contact,
ptable.name,
ptable.value)
parameter_table = TABLE(_style="width: 90%; margin:0 auto")
if len(arows):
settings = current.deployment_settings
parameters = {}
row_info = arows.first().cap_info
row_alert = arows.first().cap_alert
for arow in arows:
name = arow.cap_info_parameter.name
if "sahana:bulletin" in name:
parameter_table_row = TR(TD(B(name.split("sahana:bulletin:", 1)[1]),
_style="border: 1px solid grey",
),
TD(arow.cap_info_parameter.value,
_style="border: 1px solid grey",
))
parameter_table.append(parameter_table_row)

output = dict(instruction=s3_str(row_info.instruction),
description=s3_str(row_info.description),
headline=s3_str(row_info.headline),
status=s3_str(row_alert.status),
time=s3_str(r.utcnow.strftime("%d %B %Y, %I:%M %p")),
source=s3_str(row_alert.source),
parameter_table=parameter_table,
contact=s3_str(row_info.contact),
releasing_officer=settings.get_cap_bulletin_officer(),
releasing_officer_designation=settings.get_cap_bulltin_officer_designation(),
)

return output
return "No parameter with sahana:bulletin:"
89 changes: 89 additions & 0 deletions modules/templates/SAMBRO/PH/views/bulletin_ocd.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="{{=T.accepted_language or "en"}}">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>Office of Civil Defense Bulletin</title>
<meta name="application-name" content="{{=appname}}" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<link rel="shortcut icon" href="/{{=appname}}/static/favicon.ico" type="image/x-icon" />
</head>
<body>
<div id='ocd-wrapper' style='font-family: sans-serif'>
<div id='ocd-header'>
<div id='ocd-header-top' style='clear:both'>
<div id='ocd-header-logo'>
<img src='/{{=appname}}/static/img/ndrrmc_logo.jpg' style='height: 6em; float: left' />
</div>
<div id='ocd-header-heading' style='display: block;
text-transform: uppercase;
text-align: center;
margin-left: 7em;
word-spacing: 0;
letter-spacing: 0;
margin-top: 1em;'>
<div id='ocd-header-heading-1' style='line-height:0'>
<b>Republic of the Philippines</b>
</div>
<div id='ocd-header-heading-2' style='line-height:0'>
<h4><b>National Disaster Risk Reduction and Management Council</b></h4>
</div>
<hr style='border: 1px solid blue' />
<div id='ocd-header-heading-3' style='text-transform:none; line-height: 0'>
<h6>National Disaster Risk Reduction and Management Center, Camp Aguinaldo, Quezon City, Philippines</h6>
</div>
</div>
</div>
<div id='ocd-header-bottom'>
<div id='ocd-header-subject' style='text-transform: uppercase;
text-decoration: underline;
text-align: center;
margin-bottom: 1em;'>
<h2><b>NDRRMC {{=XML(status)}}</b></h2>
</div>
<div id='ocd-header-subject-description' style='text-align: center'>
{{=XML(headline)}}
</div>
<div id='ocd-header-signature' style='margin-left: 60%;
margin-top: 2em;
text-align: center;'>
Releasing Officer: <br /><br /><br />
<b>{{=XML(releasing_officer)}}</b> <br />{{=XML(releasing_officer_designation)}}
</div>
</div>
</div>
<div id='ocd-body'>
<div id='ocd-body-top'>
<div id='ocd-body-top-date' style='line-height: 0'>
DATE: {{=XML(time)}}
</div>
<hr />
<div id='ocd-body-top-source' style='line-height: 0; margin-bottom: 2em'>
Source: {{=XML(source)}}
</div>
</div>
<div id='ocd-body-main'>
<div id='ocd-situational-overview'>
<b style='text-transform: uppercase'>I. Situational Overview</b> <br /><br />
<div id='ocd-parameter-body'>
{{=XML(parameter_table)}}
<div id='ocd-body-description' style='margin-top: 1em'>
<b>Description: </b>{{=XML(description)}}
</div>
</div>
</div>
<div id='ocd-instruction' style='margin-top: 1em;'>
<b style='text-transform: uppercase'>II. Action/s Taken</b>
<div id='ocd-body-description'>
{{=XML(instruction)}}
</div>
</div>
</div>
</div>
<div id='ocd-footer' style='margin-top: 10em; text-align: center;'>
<hr style='border: 2px solid blue'>{{=XML(contact)}}
</div>
</div>
<script>window.print();</script>
</body>
</html>
Binary file added static/img/ndrrmc_logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.