Skip to content

Commit

Permalink
Project: Fix ability to edit HR link details, Ensure project_id removed
Browse files Browse the repository at this point in the history
from Details page datatables
RMSAmericas: Tweak permissions & config
  • Loading branch information
flavour committed Oct 2, 2015
1 parent 5826631 commit e4069c7
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 86 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nursix-1.1.0-devel-2853-ga6fbbfe (2015-10-02 13:10:53)
5826631 (2015-10-02 18:04:14)
55 changes: 54 additions & 1 deletion controllers/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,28 @@ def prep(r):
field.default = organisation_id
field.readable = field.writable = False

elif r.method == "details":
# Until we can automate this inside s3profile
# - remove the fkey from the list_fields
configure = s3db.configure
get_config = s3db.get_config
define_resource = s3db.resource
for tablename in ("project_organisation",
"project_location",
"project_beneficiary",
"project_human_resource_project",
):
s3db.table(tablename)
list_fields = get_config(tablename, "list_fields")
if not list_fields:
list_fields = define_resource(tablename).list_fields()
try:
list_fields.remove("project_id")
except:
# Already removed
pass
configure(tablename, list_fields=list_fields)

if r.id:
r.table.human_resource_id.represent = \
s3db.hrm_HumanResourceRepresent(show_link=True)
Expand Down Expand Up @@ -292,7 +314,7 @@ def prep(r):
)
)

elif component_name == "human_resource":
elif component_name in ("human_resource", "human_resource_project"):

htable = s3db.hrm_human_resource
htable.person_id.represent = \
Expand Down Expand Up @@ -325,6 +347,37 @@ def prep(r):
sort=True
)

# @ToDo:
#if settings.has_module("budget"):
# from s3 import S3SQLCustomForm, S3SQLInlineComponent
# field = s3db.budget_allocation.budget_entity_id
# field.readable = field.writable = True
# field.requires = S3Represent(lookup="budget_budget", key="budget_entity_id")
# field.requires = IS_ONE_OF()
#
# crud_form = S3SQLCustomForm("project_id",
# "human_resource_id",
# "status",
# S3SQLInlineComponent("allocation",
# label = T("Budget"),
# fields = ["budget_entity_id",
# "start_date",
# "end_date",
# "daily_cost",
# ],
# ),
# )
# s3db.configure("project_human_resoruce_project",
# crud_form = crud_form,
# list_fields = [#"project_id", # Not being dropped in component view
# "human_resource_id",
# "status",
# "allocation.budget_entity_id",
# "allocation.start_date",
# "allocation.end_date",
# "allocation.daily_cost",
# ],

elif component_name == "document":
# Hide unnecessary fields
dtable = component.table
Expand Down
6 changes: 5 additions & 1 deletion languages/es.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@
'Add Level 1 Assessment': 'Añadir evaluación de nivel 1',
'Add Level 2 Assessment': 'Añadir evaluación de nivel 2',
'Add Line': 'Añadir Línea',
'Add Locations': 'Añadir ubicaciones',
'Add Location': 'Añadir Ubicacion',
'Add Locations': 'Añadir Ubicaciones',
'Add Log Entry': 'Añadir Entrada de Registro',
'Add Member': 'Añadir Miembro',
'Add Membership': 'Añadir Membresía',
Expand Down Expand Up @@ -1316,6 +1317,7 @@
'Communication': 'Comunicación',
'Communications': 'comunicaciones',
'Communities': 'Comunidades',
'Community': 'Comunidad',
'Community Action Planning': 'Planificación de Acción Comunitaria',
'Community Based Health and First Aid (CBHFA)': 'Basado en la Comunidad de la Salud y Primeros Auxilios (SPAC)',
'Community Centre': 'Centro de la comunidad',
Expand Down Expand Up @@ -3431,6 +3433,7 @@
'Layout': 'Diseño',
'Leader': 'Líder',
'Lebanon': 'Líbano',
'Left': 'Salido',
'Left-to-Right': 'De izquierda a derecha',
'Legend Format': 'Formato de la leyenda',
'Length (m)': 'Largo (m)',
Expand Down Expand Up @@ -4142,6 +4145,7 @@
'No Level 2 Assessments currently registered': 'No hay evaluaciones nivel 2 actualmente registradas',
'No Locations currently available': 'No hay ubicaciones disponibles en la actualidad',
'No Locations currently registered': 'No existen lugares actualmente registrados',
'No Locations Found': 'Ninguna ubicaciones encontrada',
'No Map Profiles currently defined': 'Sin configuraciones de correlación actualmente definidas',
'No Map Profiles currently registered in this event': 'Sin configuraciones de correlación actualmente definidas en este evento',
'No Map Profiles currently registered in this scenario': 'Sin configuraciones de correlación actualmente registradas en este escenario',
Expand Down
15 changes: 6 additions & 9 deletions modules/s3/s3profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,15 +551,12 @@ def _datatable(self, r, widget, **attr):
tablename = widget.get("tablename")
resource, context = self._resolve_context(r, tablename, context)

# Define target resource
table = resource.table
get_config = resource.get_config

# List fields
list_fields = widget.get("list_fields",
get_config("list_fields", None))
list_fields = widget.get("list_fields")
if not list_fields:
list_fields = [f for f in table.fields if table[f].readable]
# @ToDo: Set the parent so that the fkey gets removed from the list_fields
#resource.parent = s3db.resource("")
list_fields = resource.list_fields()

# Widget filter option
widget_filter = widget.get("filter")
Expand Down Expand Up @@ -621,7 +618,7 @@ def default_orderby():
# ORDERBY fallbacks: widget->resource->default
orderby = widget.get("orderby")
if not orderby:
orderby = get_config("orderby")
orderby = resource.get_config("orderby")
if not orderby:
orderby = default_orderby()

Expand Down Expand Up @@ -716,7 +713,7 @@ def default_orderby():
if not orderby:
orderby = widget.get("orderby")
if not orderby:
orderby = get_config("orderby")
orderby = resource.get_config("orderby")
if not orderby:
orderby = default_orderby()

Expand Down
5 changes: 4 additions & 1 deletion modules/s3/s3rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ def __init__(self,

tablename = "%s_%s" % (self.prefix, self.name)

if self.method == "review":
if not current.deployment_settings.get_auth_record_approval():
# Record Approval is off
approved, unapproved = True, True
elif self.method == "review":
approved, unapproved = False, True
elif auth.s3_has_permission("review", tablename, self.id):
# Approvers should be able to edit records during review
Expand Down
1 change: 1 addition & 0 deletions modules/s3/s3xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,7 @@ def gis_encode(self,
LatLon = latlons[tablename].get(record_id, None)
if LatLon:
# @ToDo: Support records with multiple locations
# via making these also use the map element
lat = LatLon[0]
lon = LatLon[1]
if lat is not None and lon is not None:
Expand Down
43 changes: 10 additions & 33 deletions modules/s3db/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2750,6 +2750,7 @@ def model(self):
),
Field("status", "integer",
default = 1,
label = T("Status"),
represent = lambda opt: \
status_opts.get(opt, current.messages.UNKNOWN_OPT),
requires = IS_IN_SET(status_opts),
Expand All @@ -2769,32 +2770,7 @@ def model(self):
msg_record_deleted = T("Human Resource unassigned"),
msg_list_empty = T("No Human Resources currently assigned to this project"))

if settings.has_module("budget"):
crud_form = S3SQLCustomForm("project_id",
"human_resource_id",
"status",
S3SQLInlineComponent("allocation",
label = T("Budget"),
fields = ["budget_id",
"start_date",
"end_date",
"daily_cost",
],
),
)
else:
crud_form = None

self.configure(tablename,
crud_form = crud_form,
list_fields = [#"project_id", # Not being dropped in component view
"human_resource_id",
"status",
"allocation.budget_id",
"allocation.start_date",
"allocation.end_date",
"allocation.daily_cost",
],
onvalidation = self.project_human_resource_onvalidation,
super_entity = "budget_cost_item",
)
Expand All @@ -2806,16 +2782,17 @@ def model(self):
@staticmethod
def project_human_resource_onvalidation(form):
"""
Prevent the same hrm_human_resource record being added more than
once.
Prevent the same human_resource record being added more than once
"""

# The project human resource table
hr = current.s3db.project_human_resource_project

# Fetch the first row that has the same project and human resource ids
query = (hr.human_resource_id == form.vars.human_resource_id) & \
(hr.project_id == form.request_vars.project_id)
# (which isn't this record!)
form_vars = form.request_vars
query = (hr.human_resource_id == form_vars.human_resource_id) & \
(hr.project_id == form_vars.project_id) & \
(hr.id != form_vars.id)
row = current.db(query).select(hr.id,
limitby=(0, 1)).first()

Expand Down Expand Up @@ -9093,12 +9070,12 @@ def dt_row_actions(component):
# NB T() here to prevent requiring an extra translation of 'Add <translation of Staff>'
label_create = T("Add %(staff)s") % dict(staff=STAFF),
type = "datatable",
actions = dt_row_actions("human_resource"),
tablename = "hrm_human_resource",
actions = dt_row_actions("human_resource_project"),
tablename = "project_human_resource_project",
context = "project",
create_controller = "project",
create_function = "project",
create_component = "human_resource",
create_component = "human_resource_project",
pagesize = None, # all records
)
profile_widgets.append(hr_widget)
Expand Down
4 changes: 4 additions & 0 deletions modules/templates/RMSAmericas/auth_roles.csv
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ ORG_ADMIN,Organisation Admin,Can manage Organisation Users and control all recor
ORG_ADMIN,Organisation Admin,Can manage Organisation Users and control all record permissions,,,project_status,,READ,,,,,
ORG_ADMIN,Organisation Admin,Can manage Organisation Users and control all record permissions,,,project_theme,,READ,,,,,
ORG_ADMIN,Organisation Admin,Can manage Organisation Users and control all record permissions,,,project_goal,,READ|CREATE|UPDATE|DELETE,,,,,
ORG_ADMIN,Organisation Admin,Can manage Organisation Users and control all record permissions,,,project_human_resource_project,,READ|CREATE|UPDATE|DELETE,,,,,
ORG_ADMIN,Organisation Admin,Can manage Organisation Users and control all record permissions,,,project_location,,READ|CREATE|UPDATE|DELETE,,,,,
ORG_ADMIN,Organisation Admin,Can manage Organisation Users and control all record permissions,,,project_outcome,,READ|CREATE|UPDATE|DELETE,,,,,
ORG_ADMIN,Organisation Admin,Can manage Organisation Users and control all record permissions,,,project_output,,READ|CREATE|UPDATE|DELETE,,,,,
Expand Down Expand Up @@ -118,6 +119,7 @@ monitoring_evaluation,M&E,,,,project_hazard,,READ,,,,,
monitoring_evaluation,M&E,,,,project_status,,READ,,,,,
monitoring_evaluation,M&E,,,,project_theme,,READ,,,,,
monitoring_evaluation,M&E,,,,project_goal,,READ|CREATE|UPDATE|DELETE,,,,,
monitoring_evaluation,M&E,,,,project_human_resource_project,,READ|CREATE|UPDATE|DELETE,,,,,
monitoring_evaluation,M&E,,,,project_location,,READ|CREATE|UPDATE,,,,,
monitoring_evaluation,M&E,,,,project_outcome,,READ|CREATE|UPDATE|DELETE,,,,,
monitoring_evaluation,M&E,,,,project_output,,READ|CREATE|UPDATE|DELETE,,,,,
Expand Down Expand Up @@ -165,6 +167,7 @@ project_manager,Project Manager,,,,project_hazard,,READ,,,,,
project_manager,Project Manager,,,,project_status,,READ,,,,,
project_manager,Project Manager,,,,project_theme,,READ,,,,,
project_manager,Project Manager,,,,project_goal,,READ|CREATE,,,,,
project_manager,Project Manager,,,,project_human_resource_project,,READ|CREATE,READ|CREATE|UPDATE|DELETE,,,,
project_manager,Project Manager,,,,project_location,,READ|CREATE,,,,,
project_manager,Project Manager,,,,project_outcome,,READ|CREATE,,,,,
project_manager,Project Manager,,,,project_output,,READ|CREATE,,,,,
Expand Down Expand Up @@ -212,6 +215,7 @@ project_reader,Project Reader,,,,project_hazard,,READ,,,,,
project_reader,Project Reader,,,,project_status,,READ,,,,,
project_reader,Project Reader,,,,project_theme,,READ,,,,,
project_reader,Project Reader,,,,project_goal,,READ,,,,,
project_reader,Project Reader,,,,project_human_resource_project,,READ,,,,,
project_reader,Project Reader,,,,project_location,,READ,,,,,
project_reader,Project Reader,,,,project_outcome,,READ,,,,,
project_reader,Project Reader,,,,project_output,,READ,,,,,
Expand Down
48 changes: 9 additions & 39 deletions modules/templates/RMSAmericas/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def config(settings):
#"member": T("Member")
}

settings.auth.record_approval = True
#settings.auth.record_approval = True

# @ToDo: Should we fallback to organisation_id if site_id is None?
settings.auth.registration_roles = {"site_id": ["reader",
Expand Down Expand Up @@ -1749,42 +1749,6 @@ def customise_survey_series_controller(**attr):

settings.customise_survey_series_controller = customise_survey_series_controller

# -----------------------------------------------------------------------------
# Projects
# Uncomment this to use settings suitable for a global/regional organisation (e.g. DRR)
settings.project.mode_3w = True
# Uncomment this to use DRR (Disaster Risk Reduction) extensions
settings.project.mode_drr = True
# Uncomment this to use Activity Types for Activities & Projects
settings.project.activity_types = True
# Uncomment this to use Codes for projects
settings.project.codes = True
# Uncomment this to call project locations 'Communities'
settings.project.community = True
# Uncomment this to enable Hazards in 3W projects
settings.project.hazards = True
# Uncomment this to enable Indicators in projects
# Just HNRC
#settings.project.indicators = True
# Uncomment this to use multiple Budgets per project
settings.project.multiple_budgets = True
# Uncomment this to use multiple Organisations per project
settings.project.multiple_organisations = True
# Uncomment this to enable Programmes in projects
settings.project.programmes = True
# Uncomment this to enable Themes in 3W projects
settings.project.themes = True
# Uncomment this to customise
# Links to Filtered Components for Donors & Partners
settings.project.organisation_roles = {
1: T("Host National Society"),
2: T("Partner"),
3: T("Donor"),
#4: T("Customer"), # T("Beneficiary")?
#5: T("Supplier"),
9: T("Partner National Society"),
}

# -------------------------------------------------------------------------
def household_inject_form_script(r, record):
"""
Expand Down Expand Up @@ -2015,7 +1979,7 @@ def customise_project_project_controller(**attr):
# @ToDo: Use Inter-American Framework instead (when extending to Zone office)
# @ToDo: Add 'Business Line' (when extending to Zone office)
settings.project.details_tab = True
settings.project.community_volunteers = True
#settings.project.community_volunteers = True
# Done in a more structured way instead
objectives = None
outputs = None
Expand Down Expand Up @@ -2366,9 +2330,15 @@ def customise_project_indicator_data_resource(r, tablename):
# -----------------------------------------------------------------------------
def customise_project_location_resource(r, tablename):

table = current.s3db.project_location
s3db = current.s3db
table = s3db.project_location
table.name.readable = False
table.percentage.readable = table.percentage.writable = False
list_fields = s3db.get_config(tablename, "list_fields")
try:
list_fields.remove((T("Activity Types"), "activity_type.name"))
except:
pass

settings.customise_project_location_resource = customise_project_location_resource

Expand Down
4 changes: 3 additions & 1 deletion static/formats/geojson/export.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,9 @@
</xsl:call-template>
</xsl:when> -->
<xsl:when test="./map[1]/@lon!='null'">
<!-- @ToDo: Support records with multiple locations -->
<!-- @ToDo: Support records with multiple locations
via making these also use the map element
-->
<xsl:choose>
<xsl:when test="count(//resource)=1">
<type>Feature</type>
Expand Down

0 comments on commit e4069c7

Please sign in to comment.