Permalink
Browse files

Vulnerability reports & submit data

DataTable bug
import person- blood type and emergency contact
  • Loading branch information...
1 parent a1ee30c commit 4aff4a595a5fa833cba0e2e47ee73ef2f494d432 graeme committed Oct 3, 2012
@@ -166,8 +166,15 @@ def index():
)
s3.report = report
+ user_id = auth.s3_logged_in_person()
+ person = s3db.pr_person[user_id]
+ user_name = "%s %s" % (person.first_name, person.last_name)
+ now = request.utcnow
+ today = now.strftime("%d-%b-%y")
response.view = "vulnerability/map.html"
- return dict(indicators=indicators)
+ return dict(indicators=indicators,
+ user_name = user_name,
+ today = today)
# -----------------------------------------------------------------------------
def init():
@@ -520,6 +527,8 @@ def reportFilter(filter_request):
sgtable = s3db.stats_group
sgtype = s3db.stats_group_type
+ gistable = s3db.gis_location
+ prtable = s3db.pr_person
query = (sgtable.deleted != True) &\
(sgtable.group_type_id == sgtype.id)
try:
@@ -537,31 +546,28 @@ def reportFilter(filter_request):
query &= (sgtable.date >= filter_request["from_date"])
if filter_request["to_date"]:
query &= (sgtable.date <= filter_request["to_date"])
- indicator = None
+ indicator = (sgtype.name == "stats_vca")
if "indicator" in filter_request:
- indicator = (sgtype.name == "vulnerability_indicator")
+ indicator |= (sgtype.name == "vulnerability_indicator")
if "demographics" in filter_request:
- if indicator:
- indicator |= (sgtype.name == "stats_demographic")
- else:
- indicator = (sgtype.name == "stats_demographic")
+ indicator |= (sgtype.name == "stats_demographic")
if "map" in filter_request:
- if indicator:
- indicator |= (sgtype.name == "stats_map")
- else:
- indicator = (sgtype.name == "stats_map")
+ indicator |= (sgtype.name == "stats_map")
if "images" in filter_request:
- if indicator:
- indicator |= (sgtype.name == "stats_image")
- else:
- indicator = (sgtype.name == "stats_image")
+ indicator |= (sgtype.name == "stats_image")
if "reports" in filter_request:
- if indicator:
- indicator |= (sgtype.name == "stats_other")
- else:
- indicator = (sgtype.name == "stats_other")
- if indicator:
- query &= indicator
+ indicator |= (sgtype.name == "stats_other")
+ query &= indicator
+ if "myReports" in filter_request:
+ user = auth.s3_logged_in_person()
+ query &= ((sgtable.approved_by == user) | (sgtable.created_by == user))
+ if "text" in filter_request and filter_request["text"] != "":
+ text = "%%%s%%" % filter_request["text"].lower()
+ query &= (sgtable.location_id == gistable.id)
+ query &= (sgtable.created_by == prtable.id)
+ query &= ((gistable.name.lower().like(text))
+ | (prtable.first_name.lower().like(text))
+ | (prtable.last_name.lower().like(text)))
return query
# End of reportFilter ------------------------------------------------
@@ -663,11 +669,12 @@ def action_repr(id):
sgtable.approved_by.represent = approved_repr
sgtable.id.represent = action_repr
- filter_request = request.post_vars
- filter = reportFilter(filter_request)
# Ensure that we also get the records awaiting for approval
resource = s3db.resource("stats_group", unapproved=True)
- resource.add_filter(filter)
+ filter_request = request.post_vars
+ if filter_request:
+ filter = reportFilter(filter_request)
+ resource.add_filter(filter)
filteredrows = resource.count()
#############################################################
# Note if list_fields is changed here then it also needs
@@ -723,6 +730,7 @@ def action_repr(id):
report = dt.html(filteredrows,
filteredrows,
"report",
+ dt_displayLength = filteredrows,
dt_pagination = "false",
dt_bFilter = "false",
dt_sDom = "t",
@@ -774,6 +782,7 @@ def getReportDetails(id, buttonsRequired):
limitby=(0, 1)).first()
reportType = rows.stats_group_type.name
reportSource_id = rows.stats_group.source_id
+ valid = True
if reportType == "vulnerability_indicator":
# Get the data for this report
vdtable = s3db.vulnerability_data
@@ -863,39 +872,60 @@ def getReportDetails(id, buttonsRequired):
ditable = s3db.doc_image
query = (ditable.source_id == reportSource_id)
record = db(query).select(limitby=(0, 1)).first()
- size = (250, 250)
- image = s3db.pr_image_represent(record.file, size=size)
- size = s3db.pr_image_size(image, size)
- desc = DIV(record.comments, _class="imageDesc")
- filename = record.name
- url_small = URL(c="default", f="download", args=image)
- alt = record.comments if record.comments else filename
- thumb = IMG(_src=url_small,
- _alt=alt,
- _width=size[0],
- _height=size[1]
- )
- url_full = URL(c="default", f="download", args=record.file)
- download = A(T("Download"), _class="download", _href=url_full)
- view = A(T("View full size"),
- _class="download",
- _href=URL(c="vulnerability", f="view_image", args=record.id),
- _target="blank")
- table = TABLE(_class = "imageTable")
- table.append(TR(TD(thumb, _colspan=4)))
- table.append(TR(TD(desc),
- TD(download),
- TD(DIV(" | ", _class="divider")),
- TD(view),
- _class="mapRow"))
+ if record:
+ size = (250, 250)
+ image = s3db.pr_image_represent(record.file, size=size)
+ size = s3db.pr_image_size(image, size)
+ desc = DIV(record.comments, _class="imageDesc")
+ filename = record.name
+ url_small = URL(c="default", f="download", args=image)
+ alt = record.comments if record.comments else filename
+ thumb = IMG(_src=url_small,
+ _alt=alt,
+ _width=size[0],
+ _height=size[1]
+ )
+ url_full = URL(c="default", f="download", args=record.file)
+ download = A(T("Download"), _class="download", _href=url_full)
+ view = A(T("View full size"),
+ _class="download",
+ _href=URL(c="vulnerability", f="view_image", args=record.id),
+ _target="blank")
+ table = TABLE(_class = "imageTable")
+ table.append(TR(TD(thumb, _colspan=4)))
+ table.append(TR(TD(desc),
+ TD(download),
+ TD(DIV(" | ", _class="divider")),
+ TD(view),
+ _class="mapRow"))
+ else:
+ valid = False
+ elif reportType == "stats_other" or reportType == "stats_vca":
+ doctable = s3db.doc_document
+ query = (doctable.source_id == reportSource_id)
+ record = db(query).select(limitby=(0, 1)).first()
+ if record:
+ desc = DIV(record.name, _class="imageDesc")
+ url = URL(c="default", f="download", args=record.file)
+ download = A(T("Download"), _class="download", _href=url)
+ table = TABLE(_class = "imageTable")
+ table.append(TR(TD(desc),
+ TD(download),
+ _class="mapRow"))
+ else:
+ valid = False
else:
- return "No data available"
+ valid = False
# Place the table in a form and attach the buttons (if required)
form = FORM(_id = "form%s" % id)
- form.append(table)
+ if valid:
+ form.append(table)
+ else:
+ form.append(DIV(T("No data available"),_class="mapRow"))
if buttonsRequired:
- form.append(INPUT(_type = "button", _name = "Approve%s" % id,
- _value = "Approve", _class = "approveButton"))
+ if valid:
+ form.append(INPUT(_type = "button", _name = "Approve%s" % id,
+ _value = "Approve", _class = "approveButton"))
form.append(INPUT(_type = "button", _name = "Decline%s" % id,
_value = "Decline", _class = "declineButton"))
return str(form)
@@ -1086,13 +1116,14 @@ def import_vul_part1():
Controller to manage the first phase of the import of vulnerability indicators
"""
+ from gluon.serializers import json
try:
file = request.vars.file.file
except:
- return T("Error File missing")
+ response.headers["Content-Type"] = "application/json"
+ return json({"Error": str(T("Error File missing"))})
from lxml import etree
- from gluon.serializers import json
output = s3_rest_controller("vulnerability", "data",
csv_stylesheet="data.xsl")
@@ -1186,27 +1217,29 @@ def import_image(action):
"""
Controller to import a report
"""
-
- di_table = s3db.doc_image
+ if action == "map" or action == "image":
+ doc_table = s3db.doc_image
+ else:
+ doc_table = s3db.doc_document
sgtable = s3db.stats_group
sgt_table = s3db.stats_group_type
- di_file = di_table.file
+ di_file = doc_table.file
file = request.vars.file
real_filename = file.filename
new_filename = di_file.store(file, real_filename)
date = request.utcnow
creator = auth.s3_logged_in_person()
location_id = request.vars.location
desc = request.vars.desc
- di_id = di_table.insert(file = new_filename,
- name = real_filename,
- date = date,
- comments = desc,
- location_id = location_id,
- created_by = creator
- )
- s3db.update_super(di_table, dict(id=di_id))
- source_id = di_table[di_id].source_id
+ doc_id = doc_table.insert(file = new_filename,
+ name = real_filename,
+ date = date,
+ comments = desc,
+ location_id = location_id,
+ created_by = creator
+ )
+ s3db.update_super(doc_table, dict(id=doc_id))
+ source_id = doc_table[doc_id].source_id
if action == "map":
group = "stats_map"
elif action == "image":
View
@@ -2807,7 +2807,7 @@ def model(self):
}
# http://docs.oasis-open.org/emergency/edxl-have/cs01/xPIL-types.xsd
- pr_blood_type_opts = ("A+", "A-", "B+", "B-", "AB+", "AB-", "0+", "0-")
+ pr_blood_type_opts = ("A+", "A-", "B+", "B-", "AB+", "AB-", "O+", "O-")
pr_eye_color_opts = {
1: T("blue"),
View
@@ -1184,6 +1184,12 @@ def group(self):
if approved is None:
return "Approval pending"
else:
+ sgtype = current.s3db.stats_group_type
+ query = (self.stats_group.group_type_id == sgtype.id)
+ r = current.db(query).select(sgtype.name,
+ limitby = (0, 1)).first()
+ if (r.name == "stats_vca"):
+ return "VCA Report"
# @todo: add conditional branch for VCA report
return "Report"
@@ -1,17 +1,17 @@
-"Sex","First Name","Last Name","Email","Mobile Phone","Organisation","Branch","Office Phone","Office","Job Title","Home Address","Home Country","Home L1","Home L2","Home L3","Home Lat","Home Lon"
-"Mr.","Natalino","Amaral","natalino.amaral@yahoo.com","+(670) 2906-8755","Timor-Leste Red Cross Society",,,,,"Tasqolo","TL","Bobonaro","Bobonaro","Lour",-9.06795,125.35758
-"Ms.","Isabel","Zacarias","isabel.zacarias@hotmail.com","+(670) 6276-9280","Timor-Leste Red Cross Society",,,,,"Couguira","TL","Baucau","Laga","Tequino Mata",-8.49722,126.60278
-"Ms.","Beatriz","Albuquequer","beatriz.albuquequer@gmail.com","+(670) 4639-3551","Timor-Leste Red Cross Society",,,,,"Hedamea","TL","Ermera","Hatolia","Hatolia",-8.82409,125.32266
-"Mr.","Marcelino","Otilia","marcelino.otilia@yahoo.com","+(670) 6004-8196","Timor-Leste Red Cross Society",,,,,"Mautobalau","TL","Aileu","Aileu Vila","Seloi Craic",-8.71296,125.48791
-"Mr.","Marcelo","Polainos","marcelo.polainos@hotmail.com","+(670) 4327-7315","Timor-Leste Red Cross Society",,,,,"Charano","TL","Lautém","Lospalos","Cacavem",-8.59469,126.88854
-"Mr.","Justiano","Macedo","justiano.macedo@gmail.com","+(670) 2611-9149","Timor-Leste Red Cross Society",,,,,"Caunua","TL","Manatuto","Barique/Natarbora","Barique",-8.84709,126.06484
-"Ms.","Soraia","Moises","soraia.moises@yahoo.com","+(670) 5295-1204","Timor-Leste Red Cross Society",,,,,"Sarlala","TL","Aileu","Aileu Vila","Seloi Craic",-8.67454,125.5507
-"Mr.","Lucio","Horta","lucio.horta@hotmail.com","+(670) 8371-2372","Timor-Leste Red Cross Society",,,,,"Vatalara","TL","Lautém","Lospalos","Cacavem",-8.56221,126.89902
-"Ms.","Claudia","Gohan","claudia.gohan@gmail.com","+(670) 7358-3044","Timor-Leste Red Cross Society",,,,,"Raimaten","TL","Bobonaro","Maliana","Lahomea",-8.9884,125.22017
-"Ms.","Adriana","Ramos","adriana.ramos@yahoo.com","+(670) 1818-7216","Timor-Leste Red Cross Society",,,,,"Hatomanuc","TL","Manatuto","Laclubar","Manelima",-8.79088,125.93067
-"Ms.","Elly","de Carvalho","elly.decarvalho@hotmail.com","+(670) 6166-3906","Timor-Leste Red Cross Society",,,,,"Fatucahi","TL","Manufahi","Fatuberliu","Fatucahi",-9.03412,125.98864
-"Mr.","Orlando","Fahik Batak","orlando.fahikbatak@gmail.com","+(670) 4169-1104","Timor-Leste Red Cross Society",,,,,"Betoria","TL","Viqueque","Uatucarbau","Irabin de Baixo",-8.74656,126.69775
-"Mr.","Yakobus","Maia","yakobus.maia@yahoo.com","+(670) 7187-1430","Timor-Leste Red Cross Society",,,,,"Lelalai","TL","Baucau","Quelicai","Lelalai",-8.65705,126.51793
-"Mr.","Abrao","Moio","abrao.moio@hotmail.com","+(670) 7391-9251","Timor-Leste Red Cross Society",,,,,"Banitur","TL","Liquiçá","Liquiçá","Leoteala",-8.68995,125.29288
-"Ms.","Mariana","Sereno","mariana.sereno@gmail.com","+(670) 9459-1197","Timor-Leste Red Cross Society",,,,,"Manufahi","TL","Manatuto","Soibada","Manufahi",-8.83087,125.9218
-"Mr.","Andreia","Gorette","andreia.gorette@yahoo.com","+(670) 3436-2535","Timor-Leste Red Cross Society",,,,,"Aimerulu","TL","Ermera","Hatolia","Hatolia",-8.81285,125.32802
+"Sex","First Name","Last Name","Email","Mobile Phone","Organisation","Branch","Office Phone","Office","Job Title","Home Address","Home Country","Home L1","Home L2","Home L3","Home Lat","Home Lon","Blood Type","Emergency Contact Name","Emergency Contact Relationship","Emergency Contact Phone"
+"Mr.","Natalino","Amaral","natalino.amaral@yahoo.com","+(670) 2906-8755","Timor-Leste Red Cross Society",,,,,"Tasqolo","TL","Bobonaro","Bobonaro","Lour",-9.06795,125.35758,"A+","Elly Ramos","Spouse","+(670) 2906-8703"
+"Ms.","Isabel","Zacarias","isabel.zacarias@hotmail.com","+(670) 6276-9280","Timor-Leste Red Cross Society",,,,,"Couguira","TL","Baucau","Laga","Tequino Mata",-8.49722,126.60278,"O-",,,
+"Ms.","Beatriz","Albuquequer","beatriz.albuquequer@gmail.com","+(670) 4639-3551","Timor-Leste Red Cross Society",,,,,"Hedamea","TL","Ermera","Hatolia","Hatolia",-8.82409,125.32266,"A-",,,
+"Mr.","Marcelino","Otilia","marcelino.otilia@yahoo.com","+(670) 6004-8196","Timor-Leste Red Cross Society",,,,,"Mautobalau","TL","Aileu","Aileu Vila","Seloi Craic",-8.71296,125.48791,"O+",,,
+"Mr.","Marcelo","Polainos","marcelo.polainos@hotmail.com","+(670) 4327-7315","Timor-Leste Red Cross Society",,,,,"Charano","TL","Lautém","Lospalos","Cacavem",-8.59469,126.88854,"O-",,,
+"Mr.","Justiano","Macedo","justiano.macedo@gmail.com","+(670) 2611-9149","Timor-Leste Red Cross Society",,,,,"Caunua","TL","Manatuto","Barique/Natarbora","Barique",-8.84709,126.06484,"O+",,,
+"Ms.","Soraia","Moises","soraia.moises@yahoo.com","+(670) 5295-1204","Timor-Leste Red Cross Society",,,,,"Sarlala","TL","Aileu","Aileu Vila","Seloi Craic",-8.67454,125.5507,"A+",,,
+"Mr.","Lucio","Horta","lucio.horta@hotmail.com","+(670) 8371-2372","Timor-Leste Red Cross Society",,,,,"Vatalara","TL","Lautém","Lospalos","Cacavem",-8.56221,126.89902,"AB+",,,
+"Ms.","Claudia","Gohan","claudia.gohan@gmail.com","+(670) 7358-3044","Timor-Leste Red Cross Society",,,,,"Raimaten","TL","Bobonaro","Maliana","Lahomea",-8.9884,125.22017,"B-",,,
+"Ms.","Adriana","Ramos","adriana.ramos@yahoo.com","+(670) 1818-7216","Timor-Leste Red Cross Society",,,,,"Hatomanuc","TL","Manatuto","Laclubar","Manelima",-8.79088,125.93067,"A+",,,
+"Ms.","Elly","de Carvalho","elly.decarvalho@hotmail.com","+(670) 6166-3906","Timor-Leste Red Cross Society",,,,,"Fatucahi","TL","Manufahi","Fatuberliu","Fatucahi",-9.03412,125.98864,"O-",,,
+"Mr.","Orlando","Fahik Batak","orlando.fahikbatak@gmail.com","+(670) 4169-1104","Timor-Leste Red Cross Society",,,,,"Betoria","TL","Viqueque","Uatucarbau","Irabin de Baixo",-8.74656,126.69775,"A-",,,
+"Mr.","Yakobus","Maia","yakobus.maia@yahoo.com","+(670) 7187-1430","Timor-Leste Red Cross Society",,,,,"Lelalai","TL","Baucau","Quelicai","Lelalai",-8.65705,126.51793,"O+",,,
+"Mr.","Abrao","Moio","abrao.moio@hotmail.com","+(670) 7391-9251","Timor-Leste Red Cross Society",,,,,"Banitur","TL","Liquiçá","Liquiçá","Leoteala",-8.68995,125.29288,"O-",,,
+"Ms.","Mariana","Sereno","mariana.sereno@gmail.com","+(670) 9459-1197","Timor-Leste Red Cross Society",,,,,"Manufahi","TL","Manatuto","Soibada","Manufahi",-8.83087,125.9218,"A+",,,
+"Mr.","Andreia","Gorette","andreia.gorette@yahoo.com","+(670) 3436-2535","Timor-Leste Red Cross Society",,,,,"Aimerulu","TL","Ermera","Hatolia","Hatolia",-8.81285,125.32802,"O+",,,
@@ -40,9 +40,10 @@
</div>
</section>
<![endif]-->
+<div id='lightbox'></div>
<div role='main' id='vulnerability'>
{{include}}
</div>
{{include "scripts.html"}}
</body>
-</html>
+</html>
@@ -1 +1 @@
-"Organisation","Branch","PersonType","Sex","First Name","Middle Name","Last Name","Initials","DOB","Father Name","Mother Name","Religion","National ID","Passport No","Passport Country","Passport Expiry Date","Job Title","Start Date","Email","Mobile Phone","Office Phone","Skype","Callsign","Office","Department","Office Country","Office City","Office Street address","Office Postcode","Office Lat","Office Lon","Exact Coord?","Home Address","Home Postcode","Home Country","Home L1","Home L2","Home L3","Home L4","Home Lat","Home Lon","Teams","Projects","Permanent Address","Permanent Postcode","Permanent Country","Permanent L1","Permanent L2","Permanent L3","Permanent L4","Permanent Lat","Permanent Lon","Education Level","Degree Name","Major","Grade","Year","Institute"
+"Organisation","Branch","PersonType","Sex","First Name","Middle Name","Last Name","Initials","DOB","Father Name","Mother Name","Religion","Blood Type","National ID","Passport No","Passport Country","Passport Expiry Date","Job Title","Start Date","Email","Mobile Phone","Office Phone","Skype","Callsign","Emergency Contact Name","Emergency Contact Relationship","Emergency Contact Phone","Office","Department","Office Country","Office City","Office Street address","Office Postcode","Office Lat","Office Lon","Exact Coord?","Home Address","Home Postcode","Home Country","Home L1","Home L2","Home L3","Home L4","Home Lat","Home Lon","Teams","Projects","Permanent Address","Permanent Postcode","Permanent Country","Permanent L1","Permanent L2","Permanent L3","Permanent L4","Permanent Lat","Permanent Lon","Education Level","Degree Name","Major","Grade","Year","Institute"
Oops, something went wrong.

0 comments on commit 4aff4a5

Please sign in to comment.