Skip to content

Commit

Permalink
Profile: Bugfix
Browse files Browse the repository at this point in the history
Deploy: Start generalising beyond RDRT usecase
RMSAmericas: Start customising deploy
  • Loading branch information
flavour committed Feb 19, 2016
1 parent b0bdcf0 commit ca6fbd4
Show file tree
Hide file tree
Showing 14 changed files with 446 additions and 147 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
f34fb54 (2016-02-19 10:35:32)
b0bdcf0 (2016-02-19 14:53:53)
24 changes: 16 additions & 8 deletions controllers/deploy.py
Expand Up @@ -35,11 +35,11 @@ def mission():

def prep(r):
# Configure created_on field in deploy_mission
created_on = r.table.created_on
created_on.readable = True
created_on.label = T("Date Created")
created_on.represent = lambda d: \
s3base.S3DateTime.date_represent(d, utc=True)
#created_on = r.table.created_on
#created_on.readable = True
#created_on.label = T("Date Created")
#created_on.represent = lambda d: \
# s3base.S3DateTime.date_represent(d, utc=True)
if r.id:
# Mission-specific workflows return to the profile page
tablename = r.tablename if not r.component else r.component.tablename
Expand Down Expand Up @@ -87,6 +87,7 @@ def prep(r):
if not r.component and \
r.get_vars.get("~.status__belongs") == "2":
s3.crud_strings[r.tablename]["title_list"] = T("Active Missions")

return True
s3.prep = prep

Expand All @@ -111,14 +112,15 @@ def postp(r, output):
# In component CRUD views, have a subtitle after the rheader
output["rheader"] = TAG[""](output["rheader"],
H3(output["subtitle"]))

return output
s3.postp = postp

return s3_rest_controller(# Remove the title if we have a component
# (rheader includes the title)
notitle=lambda r: {"title": ""} \
if r.component else None,
rheader=s3db.deploy_rheader,
notitle = lambda r: {"title": ""} \
if r.component else None,
rheader = s3db.deploy_rheader,
)

# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -320,6 +322,12 @@ def experience():

return s3db.hrm_experience_controller()

# -----------------------------------------------------------------------------
def event_type():
""" RESTful CRUD Controller """

return s3_rest_controller("event", "event_type")

# -----------------------------------------------------------------------------
def job_title():
""" RESTful CRUD Controller """
Expand Down
2 changes: 1 addition & 1 deletion modules/s3/s3profile.py
Expand Up @@ -739,7 +739,7 @@ def default_orderby():
totalrows = displayrows

# Echo
draw = int(get_vars.draw or 0)
draw = int(get_vars.get("draw") or 0)

# Representation
if dt is not None:
Expand Down
7 changes: 7 additions & 0 deletions modules/s3cfg.py
Expand Up @@ -2600,6 +2600,13 @@ def get_deploy_hr_label(self):
"""
return self.deploy.get("hr_label", "Staff")

def get_deploy_team_label(self):
"""
Label for deployable Team
e.g. 'RDRT', 'RIT'
"""
return self.deploy.get("team_label", "Deployable")

# -------------------------------------------------------------------------
# Events
#
Expand Down
6 changes: 3 additions & 3 deletions modules/s3db/cms.py
Expand Up @@ -1105,9 +1105,9 @@ def cms_documentation(r, default_page, default_url):
table = r.resource.table
query = (table.name == name) & (table.deleted != True)
row = current.db(query).select(table.id,
table.title,
table.body,
limitby=(0, 1)).first()
table.title,
table.body,
limitby=(0, 1)).first()
if not row:
if name != default_page:
# Error - CMS page not found
Expand Down
131 changes: 22 additions & 109 deletions modules/s3db/deploy.py
Expand Up @@ -58,6 +58,7 @@ class S3DeploymentModel(S3Model):
names = ("deploy_mission",
"deploy_mission_id",
"deploy_mission_document",
"deploy_mission_status_opts",
"deploy_application",
"deploy_assignment",
"deploy_assignment_appraisal",
Expand Down Expand Up @@ -96,9 +97,12 @@ def model(self):
represent = self.deploy_mission_name_represent,
requires = IS_NOT_EMPTY(),
),
s3_date(default = "now",
),
# @ToDo: Link to location via link table
# link table could be event_event_location for IFRC (would still allow 1 multi-country event to have multiple missions)
self.gis_location_id(),
self.gis_location_id(widget = S3LocationSelector(),
),
# @ToDo: Link to event_type via event_id link table instead of duplicating
self.event_type_id(),
self.org_organisation_id(),
Expand All @@ -121,45 +125,7 @@ def model(self):
s3_comments(),
*s3_meta_fields())

# CRUD Form
crud_form = S3SQLCustomForm("name",
"event_type_id",
"location_id",
"code",
"status",
# Files
S3SQLInlineComponent(
"document",
name = "file",
label = T("Files"),
fields = ["file", "comments"],
filterby = dict(field = "file",
options = "",
invert = True,
)
),
# Links
S3SQLInlineComponent(
"document",
name = "url",
label = T("Links"),
fields = ["url", "comments"],
filterby = dict(field = "url",
options = None,
invert = True,
)
),
#S3SQLInlineComponent("document",
#name = "file",
#label = T("Attachments"),
#fields = ["file",
#"comments",
#],
#),
"comments",
"created_on",
)


# Profile
list_layout = deploy_MissionProfileLayout()
alert_widget = dict(label = "Alerts",
Expand Down Expand Up @@ -255,55 +221,12 @@ def model(self):
#list_layout = s3db.doc_document_list_layouts,
)

if settings.has_module("event"):
text_fields = ["name",
"code",
"event_type_id$name",
]
else:
text_fields = ["name",
"code",
]

# Table configuration
profile = URL(c="deploy", f="mission", args=["[id]", "profile"])
configure(tablename,
create_next = profile,
crud_form = crud_form,
delete_next = URL(c="deploy", f="mission", args="summary"),
filter_widgets = [
S3TextFilter(text_fields,
label=T("Search")
),
S3LocationFilter("location_id",
label=messages.COUNTRY,
widget="multiselect",
levels=["L0"],
hidden=True
),
S3OptionsFilter("event_type_id",
widget="multiselect",
hidden=True
),
S3OptionsFilter("status",
options=mission_status_opts,
hidden=True
),
S3DateFilter("created_on",
hide_time=True,
hidden=True
),
],
list_fields = ["name",
(T("Date"), "created_on"),
"event_type_id",
(T("Country"), "location_id"),
"code",
(T("Responses"), "response_count"),
(T(label), "hrquantity"),
"status",
],
orderby = "deploy_mission.created_on desc",
orderby = "deploy_mission.date desc",
profile_cols = 1,
profile_header = lambda r: \
deploy_rheader(r, profile=True),
Expand Down Expand Up @@ -527,6 +450,7 @@ def model(self):
# Pass names back to global scope (s3.*)
#
return dict(deploy_mission_id = mission_id,
deploy_mission_status_opts = mission_status_opts,
)

# -------------------------------------------------------------------------
Expand Down Expand Up @@ -790,25 +714,10 @@ def model(self):
msg_record_deleted = T("Alert deleted"),
msg_list_empty = T("No Alerts currently registered"))

# CRUD Form
crud_form = S3SQLCustomForm("mission_id",
"contact_method",
"subject",
"body",
"modified_on",
)

# Table Configuration
configure(tablename,
super_entity = "pr_pentity",
context = {"mission": "mission_id"},
crud_form = crud_form,
list_fields = ["mission_id",
"contact_method",
"subject",
"body",
"alert_recipient.human_resource_id",
],
)

# Components
Expand Down Expand Up @@ -1490,7 +1399,7 @@ def apply_method(self, r, **attr):
# =============================================================================
def deploy_apply(r, **attr):
"""
Custom method to select new RDRT members
Custom method to select new Deployables (e.g. RDRT/RIT Members)
@todo: make workflow re-usable for manual assignments
"""
Expand All @@ -1505,7 +1414,9 @@ def deploy_apply(r, **attr):

get_vars = r.get_vars
response = current.response
#settings = current.deployment_settings
settings = current.deployment_settings

deploy_team = settings.get_deploy_team_label()

if r.http == "POST":
added = 0
Expand Down Expand Up @@ -1551,9 +1462,9 @@ def deploy_apply(r, **attr):
atable.insert(human_resource_id=human_resource_id,
active=True)
added += 1
# @ToDo: Move 'RDRT' label to settings
current.session.confirmation = T("%(number)s RDRT members added") % \
dict(number=added)
current.session.confirmation = T("%(number)s %(team) members added") % \
dict(team = T(deploy_team),
number=added)
if added > 0:
redirect(URL(f="human_resource", args=["summary"], vars={}))
else:
Expand Down Expand Up @@ -1609,8 +1520,10 @@ def deploy_apply(r, **attr):
dt_id = "datatable"

# Bulk actions
# @todo: generalize label
dt_bulk_actions = [(T("Add as RDRT Members"), "add")]
dt_bulk_actions = [(T("Add as %(team)s Members") % \
dict(team = T(deploy_team)),
"add"),
]

if r.representation == "html":
# Page load
Expand Down Expand Up @@ -1666,7 +1579,7 @@ def deploy_apply(r, **attr):
_class="filter-form",
_id="datatable-filter-form",
)
fresource = current.s3db.resource(resource.tablename)
fresource = s3db.resource(resource.tablename)
alias = resource.alias if r.component else None
ff = filter_form.html(fresource,
r.get_vars,
Expand All @@ -1676,8 +1589,8 @@ def deploy_apply(r, **attr):
ff = ""

output = dict(items = items,
# @todo: generalize
title = T("Add RDRT Members"),
title = T("Add %(team)s Members") % \
dict(team = T(deploy_team)),
list_filter_form = ff)

response.view = "list_filter.html"
Expand Down

0 comments on commit ca6fbd4

Please sign in to comment.