Skip to content

Commit

Permalink
CAP: link area and resource only to alert; info_id kept for importing…
Browse files Browse the repository at this point in the history
… alert

SAMBRO: clean and minor tweaks

SAMBRO: more rss feed demo channels

CAP: Show submit for approval button if there is at least one area segment in alert

Add cap_resource to doc entities
  • Loading branch information
biplovbhandari committed Feb 23, 2016
1 parent da6ea57 commit c875bf3
Show file tree
Hide file tree
Showing 11 changed files with 370 additions and 263 deletions.
83 changes: 11 additions & 72 deletions controllers/cap.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,13 +614,6 @@ def custom_widget_fn_3(r, **attr):

elif r.component_name == "area":
atable = r.component.table
# Limit to those for this Alert
atable.info_id.requires = IS_EMPTY_OR(
IS_ONE_OF(db, "cap_info.id",
s3db.cap_info_represent,
filterby="alert_id",
filter_opts=(r.id,),
))
for f in ("event_type_id", "priority"):
# Do not show for the actual area
field = atable[f]
Expand All @@ -636,14 +629,6 @@ def custom_widget_fn_3(r, **attr):
cap_area_options = cap_AreaRowOptionsBuilder(r.id)
atable.name.represent = S3Represent(options=cap_area_options)

# Auto assign the info_id to area if only one info segment
itable = s3db.cap_info
rows = db(itable.alert_id == r.record.id).select(itable.id)
if len(rows) == 1:
field = atable.info_id
field.default = rows.first().id
field.writable = field.readable = False

if r.record.approved_by is not None:
# Once approved, don't allow area segment to edit
# Don't allow to delete
Expand All @@ -655,21 +640,6 @@ def custom_widget_fn_3(r, **attr):

elif r.component_name == "resource":
atable = r.component.table
# Limit to those for this Alert
atable.info_id.requires = IS_EMPTY_OR(
IS_ONE_OF(db, "cap_info.id",
s3db.cap_info_represent,
filterby="alert_id",
filter_opts=(r.id,),
))

# Auto assign the info_id to area if only one info segment
itable = s3db.cap_info
rows = db(itable.alert_id == r.record.id).select(itable.id)
if len(rows) == 1:
field = atable.info_id
field.default = rows.first().id
field.writable = field.readable = False

if r.record.approved_by is not None:
# Once approved, don't allow resource segment to edit
Expand Down Expand Up @@ -760,11 +730,6 @@ def postp(r, output):
del row_clone["id"]
row_clone["alert_id"] = lastid
row_clone["is_template"] = False
# Use the info_id here
if len(rows) == 1:
row_clone["info_id"] = rows.first().id
else:
del row_clone["info_id"]
rtable.insert(**row_clone)

rows = db(itable.alert_id == lastid).select(itable.id)
Expand Down Expand Up @@ -917,25 +882,10 @@ def prep(r):

elif r.component_name == "resource":
rtable = r.component.table
# Limit to those for this Alert
rtable.info_id.requires = IS_EMPTY_OR(
IS_ONE_OF(db, "cap_info.id",
s3db.cap_info_represent,
filterby="alert_id",
filter_opts=(r.id,),
))

# Set is_template to true as only accessed by template
rtable.is_template.default = True

# Auto assign the info_id to area if only one info segment
itable = s3db.cap_info
rows = db(itable.alert_id == r.record.id).select(itable.id)
if len(rows) == 1:
field = rtable.info_id
field.default = rows.first().id
field.writable = field.readable = False

s3.crud_strings[tablename] = Storage(
label_create = T("Create Template"),
title_display = T("Template"),
Expand Down Expand Up @@ -1013,30 +963,15 @@ def area():

def prep(r):
artable = s3db.cap_area
for f in ("alert_id", "info_id"):
field = artable[f]
field.writable = False
field.readable = False
artable.alert_id.readable = False
artable.alert_id.writable = False

# Area create from this controller is template
artable.is_template.default = True

return True
s3.prep = prep

def postp(r, output):
if r.interactive and r.component and r.component_name == "area_location":
# Modify action button to open cap/area_location directly.
#read_url = URL(c="cap", f="area_location", args=["[id]"])
update_url = URL(c="cap", f="area_location", args=["[id]", "update"])
delete_url = URL(c="cap", f="area_location", args=["[id]", "delete"])
s3_action_buttons(r,
update_url=update_url,
delete_url=delete_url,
)
return output
s3.postp = postp

output = s3_rest_controller("cap", "area",
rheader = s3db.cap_rheader)
return output
Expand Down Expand Up @@ -1066,7 +1001,10 @@ def compose():
URL(c="cap", f="alert", args=[alert_id, "review"]))
message = "You are requested to take action on this alert:\n\n%s" % url
msg.send_by_pe_id(pe_ids, subject, message)
msg.send_by_pe_id(pe_ids, subject, message, contact_method = "SMS")
try:
msg.send_by_pe_id(pe_ids, subject, message, contact_method = "SMS")
except ValueError:
current.log.error("No SMS Handler defined!")
session.confirmation = T("Alert Approval Notified")

redirect(URL(c="cap", f="alert"))
Expand All @@ -1086,8 +1024,8 @@ def set_priority_js():
)

from gluon.serializers import json as jsons
from s3 import s3_unicode
p_settings = [(s3_unicode(T(r.name)), r.urgency, r.severity, r.certainty, r.color_code)\
from s3 import s3_str
p_settings = [(s3_str(T(r.name)), r.urgency, r.severity, r.certainty, r.color_code)\
for r in rows]

priority_conf = '''S3.cap_priorities=%s''' % jsons(p_settings)
Expand Down Expand Up @@ -1123,6 +1061,7 @@ def cap_AreaRowOptionsBuilder(alert_id, caller=None):
values = [row.id for row in rows]
count = len(values)
if count:
from s3 import s3_str
if count == 1:
query_ = (atable.id == values[0])
else:
Expand All @@ -1148,8 +1087,8 @@ def cap_AreaRowOptionsBuilder(alert_id, caller=None):
cap_area_options = {}
for row_ in rows_:
cap_area_options[row_["cap_area.name"]] = \
s3_unicode(row_["cap_area_name.name_l10n"] or \
row_["cap_area.name"])
s3_str(row_["cap_area_name.name_l10n"] or \
row_["cap_area.name"])

return cap_area_options

Expand Down
Loading

0 comments on commit c875bf3

Please sign in to comment.