Skip to content

Commit

Permalink
DRKCM: add sector filter to response action view
Browse files Browse the repository at this point in the history
  • Loading branch information
nursix committed Feb 22, 2024
1 parent 4c80fdc commit 1455ddb
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nursix-dev-5852-g3dc92ec1b (2024-02-20 17:19:12)
nursix-dev-5853-g4c80fdc2f (2024-02-22 16:43:37)
14 changes: 14 additions & 0 deletions modules/templates/DRKCM/customise/dvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,18 @@ def configure_response_action_filters(r,
]

if use_theme:
settings = current.deployment_settings
themes_details = settings.get_dvr_response_themes_details()
themes_sectors = settings.get_dvr_response_themes_sectors()
if themes_details and themes_sectors:
from ..helpers import response_theme_sectors
filter_widgets.insert(-2,
OptionsFilter("response_action_theme.theme_id$sector_id",
header = True,
hidden = True,
options = response_theme_sectors,
))

filter_widgets.insert(-2,
OptionsFilter("response_theme_ids",
header = True,
Expand All @@ -1557,6 +1569,8 @@ def configure_response_action_filters(r,
org_filter = True,
),
))


if use_response_type:
filter_widgets.insert(3,
HierarchyFilter("response_type_id",
Expand Down
38 changes: 38 additions & 0 deletions modules/templates/DRKCM/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,44 @@ def case_default_org():

return default_org, multiple_orgs

# =============================================================================
def response_theme_sectors():
"""
Looks up the sectors of all organisations the user
can access response actions for; for sector-filter
in response action perspective
Returns:
a dict {sector_id: sector_name}
"""

T = current.T

db = current.db
s3db = current.s3db
auth = current.auth

stable = s3db.org_sector
ltable = s3db.org_sector_organisation
otable = s3db.org_organisation

realms = auth.permission.permitted_realms("dvr_response_action", "read")
if realms:
query = (otable.pe_id.belongs(realms)) & \
(otable.deleted == False)
organisation_ids = db(query)._select(otable.id)
join = ltable.on((ltable.sector_id == stable.id) & \
(ltable.organisation_id.belongs(organisation_ids)) & \
(ltable.deleted == False))
else:
join = None

sectors = db(stable.deleted == False).select(stable.id,
stable.name,
join = join,
)
return {s.id: T(s.name) for s in sectors}

# =============================================================================
def get_total_consultations(person):
"""
Expand Down

0 comments on commit 1455ddb

Please sign in to comment.