Navigation Menu

Skip to content

Commit

Permalink
S3GroupedItems: use bulk representation for group labels, whitespace …
Browse files Browse the repository at this point in the history
…cleanups
  • Loading branch information
nursix committed Sep 30, 2015
1 parent dd96e92 commit f4029f0
Show file tree
Hide file tree
Showing 13 changed files with 181 additions and 174 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
4bcacee (2015-09-30 13:34:55)
nursix-1.1.0-devel-2841-gdd96e92 (2015-09-30 15:09:43)
64 changes: 32 additions & 32 deletions controllers/cap.py
Expand Up @@ -105,7 +105,7 @@ def alert():
tablename = "cap_alert"

def prep(r):

if r.representation == "dl":
# DataList: match list_layout
list_fields = ["info.headline",
Expand All @@ -129,8 +129,8 @@ def prep(r):
"scope",
"info.event_type_id",
]
s3db.configure(tablename,

s3db.configure(tablename,
list_fields = list_fields,
)

Expand Down Expand Up @@ -536,15 +536,15 @@ def custom_widget_fn_3(r, **attr):
# Do not show for the actual area
field = atable[f]
field.writable = field.readable = False

# 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

elif r.component_name == "resource":
atable = r.component.table
# Limit to those for this Alert
Expand All @@ -554,7 +554,7 @@ def custom_widget_fn_3(r, **attr):
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)
Expand Down Expand Up @@ -625,7 +625,7 @@ def postp(r, output):
# First get the info_id
itable = s3db.cap_info
rows = db(itable.alert_id == lastid).select(itable.id)

rtable = s3db.cap_resource
r_unwanted_fields = set(("deleted_rb",
"owned_by_user",
Expand Down Expand Up @@ -758,7 +758,7 @@ def template():

viewing = request.vars["viewing"]
tablename = "cap_alert"

if viewing:
table, _id = viewing.strip().split(".")
if table == tablename:
Expand All @@ -771,11 +771,11 @@ def prep(r):
"incidents",
"info.category",
]

s3db.configure(tablename,
list_fields = list_fields,
)

for f in ("identifier", "msg_type"):
field = atable[f]
field.writable = False
Expand Down Expand Up @@ -809,18 +809,18 @@ def prep(r):
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 @@ -868,19 +868,19 @@ def area():
Should only be accessed for defining area template
"""

def prep(r):
def prep(r):
artable = s3db.cap_area
for f in ("alert_id", "info_id"):
field = artable[f]
field.writable = False
field.readable = 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.
Expand Down Expand Up @@ -908,7 +908,7 @@ def warning_priority():

# -----------------------------------------------------------------------------
def priority_get():

try:
event_type_id = request.args[0]
except:
Expand All @@ -919,7 +919,7 @@ def priority_get():
except:
result = current.xml.json_message(False, 400, "Invalid Event Type!")
else:
# Get Event Name for Event ID
# Get Event Name for Event ID
etable = s3db.event_event_type
item = db(etable.id == event_type_id).select(etable.name,
limitby=(0, 1)
Expand All @@ -931,7 +931,7 @@ def priority_get():
else:
wptable = s3db.cap_warning_priority
query = (wptable.event_type == event_type_name)

rows = db(query).select(wptable.id,
wptable.name,
orderby = wptable.id)
Expand All @@ -942,26 +942,26 @@ def priority_get():
[{"id": "", "name": T("Undefined")}]
result = jsons(row_dict)
else:
rows = db(wptable.event_type == "others").select(wptable.id,
rows = db(wptable.event_type == "others").select(wptable.id,
wptable.name,
orderby = wptable.id)

row_dict = [{"id": r.id, "name": T(r.name)} for r in rows] + \
[{"id": "", "name": T("Undefined")}]
result = jsons(row_dict)
finally:
response.headers["Content-Type"] = "application/json"
return result

# -----------------------------------------------------------------------------
def compose():
"""
Send message to the people with role of Alert Approval
"""

# For SAMBRO, permission is checked by the Authentication Roles but the permission
# should be checked if CAP module is enabled
if settings.has_module("msg"):
if settings.has_module("msg"):
# Notify People with the role of Alert Approval via email and SMS
pe_ids = get_vars.get("pe_ids")
alert_id = get_vars.get("cap_alert.id")
Expand All @@ -972,7 +972,7 @@ def compose():
msg.send_by_pe_id(pe_ids, subject, message)
msg.send_by_pe_id(pe_ids, subject, message, contact_method = "SMS")
session.confirmation = T("Alert Approval Notified")

redirect(URL(c="cap", f="alert"))

# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -1270,19 +1270,19 @@ def set_priority_js():
""" Output json for priority field """

wptable = s3db.cap_warning_priority
rows = db(wptable).select(wptable.name,
wptable.urgency,

rows = db(wptable).select(wptable.name,
wptable.urgency,
wptable.severity,
wptable.certainty,
wptable.certainty,
wptable.color_code,
orderby = wptable.name,
)

from gluon.serializers import json as jsons
p_settings = [(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)
js_global = s3.js_global
if not priority_conf in js_global:
Expand Down
4 changes: 2 additions & 2 deletions controllers/project.py
Expand Up @@ -230,7 +230,7 @@ def prep(r):
filter_opts=[r.id],
)
# @ToDo: end_date cannot be before Project Start
#ctable.end_date.requires =
#ctable.end_date.requires =

# Have a filter for indicator in indicator data report
#if r.method == "report":
Expand Down Expand Up @@ -1101,7 +1101,7 @@ def dt_row_actions(component):
field.readable = field.writable = False

return True
s3.prep = prep
s3.prep = prep

return s3_rest_controller()

Expand Down
6 changes: 3 additions & 3 deletions controllers/req.py
Expand Up @@ -318,7 +318,7 @@ def prep(r):
else:
if r.id:
table.is_template.readable = table.is_template.writable = False

method = r.method
if method in (None, "create"):
# Hide fields which don't make sense in a Create form
Expand Down Expand Up @@ -644,7 +644,7 @@ def postp(r, output):
# Create form
# @ToDo: DRY
if not settings.get_req_inline_forms():
form_vars = output["form"].vars
form_vars = output["form"].vars
type = form_vars.type
if type == "1":
# Stock: Open Tab for Items
Expand Down Expand Up @@ -786,7 +786,7 @@ def postp(r, output):
# Create form
# @ToDo: DRY
if not settings.get_req_inline_forms():
form_vars = output["form"].vars
form_vars = output["form"].vars
req_type = form_vars.type
if req_type == "1":
# Stock: Open Tab for Items
Expand Down
12 changes: 6 additions & 6 deletions models/tasks.py
Expand Up @@ -43,24 +43,24 @@ def maintenance(period="daily"):

# -----------------------------------------------------------------------------
if settings.has_module("cap"):

# -----------------------------------------------------------------------------
def cap_ftp_sync(user_id=None):
""" Get all the ftp repository and synchronize them """

if user_id:
# Authenticate
auth.s3_impersonate(user_id)

rows = db(s3db.sync_repository.apitype == "ftp").select()

if rows:
sync = current.sync
for row in rows:
sync.synchronize(row)

tasks["cap_ftp_sync"] = cap_ftp_sync

# -----------------------------------------------------------------------------
if settings.has_module("doc"):

Expand Down
2 changes: 1 addition & 1 deletion modules/s3/s3gis.py
Expand Up @@ -4684,7 +4684,7 @@ def propagate(parent):
@param parent: gis_location id of parent
"""

# No need to filter out deleted since the parent FK is None for these records
# No need to filter out deleted since the parent FK is None for these records
query = (table.parent == parent) & \
(table.inherited == True)
rows = db(query).select(*fields)
Expand Down
19 changes: 13 additions & 6 deletions modules/s3/s3grouped.py
Expand Up @@ -1364,6 +1364,14 @@ def check_label(colname):
if key:
output["k"] = key

representations = None
renderer = represent.get(key) if represent else None

# Bulk represent?
if renderer and hasattr(renderer, "bulk"):
values = [group[key] for group in self.groups]
representations = renderer.bulk(values)

data = []
add_group = data.append
for group in self.groups:
Expand All @@ -1376,12 +1384,11 @@ def check_label(colname):

# Add subgroup attribute value
value = group[key]
renderer = represent.get(key) if represent else None
if renderer is None:
value = s3_unicode(value).encode("utf-8")
else:
# @todo: call bulk-represent if available
value = s3_unicode(renderer(value)).encode("utf-8")
if representations is not None:
value = representations.get(value)
elif renderer is not None:
value = renderer(value)
value = s3_unicode(value).encode("utf-8")
gdict["v"] = value
add_group(gdict)

Expand Down
4 changes: 2 additions & 2 deletions modules/s3/s3msg.py
Expand Up @@ -661,7 +661,7 @@ def dispatch_to_pe_id(pe_id,
ptable.on((ptable.id == ttable.person_id) & \
(ptable.deleted != True)),
]

atable = s3db.table("deploy_alert")
if atable:
ltable = db.deploy_alert_recipient
Expand Down Expand Up @@ -2061,7 +2061,7 @@ def poll_twitter(channel_id):
Function to call to fetch tweets into msg_twitter table
- called via Scheduler or twitter_inbox controller
http://tweepy.readthedocs.org/en/v3.3.0/api.html
http://tweepy.readthedocs.org/en/v3.3.0/api.html
"""

try:
Expand Down
2 changes: 1 addition & 1 deletion modules/s3/s3translate.py
Expand Up @@ -872,7 +872,7 @@ def get_database_strings(all_template_flag):
reusable_field = s3db.get(fieldname)
# Excludes lambdas which are in defaults()
# i.e. reusable fields in disabled modules
if reusable_field and isinstance(reusable_field, S3ReusableField):
if reusable_field and isinstance(reusable_field, S3ReusableField):
represent = reusable_field.attr.represent
if hasattr(represent, "translate"):
translate = represent.translate
Expand Down

0 comments on commit f4029f0

Please sign in to comment.