From ed4a5a1565b8e155a6a04120b33533effcc1f53f Mon Sep 17 00:00:00 2001 From: Michael Howden Date: Sat, 21 Feb 2015 00:38:52 +1300 Subject: [PATCH] * Default "index" resources to summary method * Adding Report Options & Defaults * Removing extra embedded table if there is no Org Logo (return "") * Menus check if skills and certificates are enabled --- controllers/asset.py | 7 -- controllers/inv.py | 6 -- modules/s3cfg.py | 6 ++ modules/s3db/org.py | 133 ++++++++++++++++++++-------- modules/s3menus.py | 27 ++++-- modules/templates/IFRC/config.py | 2 - modules/templates/default/config.py | 2 + 7 files changed, 121 insertions(+), 62 deletions(-) diff --git a/controllers/asset.py b/controllers/asset.py index 9817eadc01..bda5b8b418 100644 --- a/controllers/asset.py +++ b/controllers/asset.py @@ -142,13 +142,6 @@ def supplier(): msg_list_empty = T("No Suppliers currently registered") ) - # Modify filter_widgets - filter_widgets = s3db.get_config("org_organisation", "filter_widgets") - # Remove type (always 'Supplier') - filter_widgets.pop(1) - # Remove sector (not relevant) - filter_widgets.pop(1) - return s3db.org_organisation_controller() # ----------------------------------------------------------------------------- diff --git a/controllers/inv.py b/controllers/inv.py index 4f8e31148a..3721db8d8d 100644 --- a/controllers/inv.py +++ b/controllers/inv.py @@ -453,12 +453,6 @@ def supplier(): msg_list_empty = T("No Suppliers currently registered") ) - # Modify filter_widgets - filter_widgets = s3db.get_config("org_organisation", "filter_widgets") - # Remove type (always 'Supplier') - filter_widgets.pop(1) - # Remove sector (not relevant) - filter_widgets.pop(1) # Open record in this controller after creation s3db.configure("org_organisation", diff --git a/modules/s3cfg.py b/modules/s3cfg.py index 9d873d7097..5edc9c6aac 100644 --- a/modules/s3cfg.py +++ b/modules/s3cfg.py @@ -2776,6 +2776,12 @@ def get_org_autocomplete(self): """ return self.org.get("autocomplete", False) + def get_org_sector(self): + """ + Whether to use an Organization Sector field + """ + return self.org.get("sector", False) + def get_org_branches(self): """ Whether to support Organisation Branches or not diff --git a/modules/s3db/org.py b/modules/s3db/org.py index 4f0e96b1b5..6913a77c14 100644 --- a/modules/s3db/org.py +++ b/modules/s3db/org.py @@ -397,6 +397,15 @@ def model(self): "comments", ] + use_sector = settings.get_org_sector() + if use_sector: + form_fields.insert(3, S3SQLInlineLink("sector", + columns = 4, + label = T("Sectors"), + field = "sector_id", + ), + ) + if settings.get_org_summary(): # Include Summary fields in form position = form_fields.index("year") @@ -437,6 +446,8 @@ def model(self): "acronym", "comments", ] + if use_sector: + text_fields += ["sector.name", "sector.abrv"] if settings.get_L10n_translate_org_organisation(): text_fields.extend(("name.name_l10n", @@ -490,26 +501,60 @@ def model(self): widgets = org_widgets, ) - filter_widgets = [ - S3TextFilter(text_fields, - label = T("Search"), - comment = text_comment, - #_class = "filter-search", - ), - # NB Order is important here - gets popped in asset & inv controllers & IFRC template - type_filter, - # NB Order is important here - gets popped in asset & inv controllers & IFRC template - S3OptionsFilter("sector_organisation.sector_id", - options = lambda: \ - get_s3_filter_opts("org_sector", - location_filter=True, - none=True, - translate=True), - ), - S3OptionsFilter("country", - #label = T("Home Country"), - ), - ] + list_fields = ["id", + "name", + "acronym", + "organisation_organisation_type.organisation_type_id", + "website" + ] + + if use_sector: + list_fields.insert(4,"sector_organisation.sector_id") + + filter_widgets = [S3TextFilter(text_fields, + label = T("Search"), + comment = text_comment, + #_class = "filter-search", + ), + ] + append = filter_widgets.append + + # Don't add Type or Sector Filters for Supplier organizations in the asset and inv controllers + if current.request.function != "supplier": + append(type_filter) + if use_sector: + append(S3OptionsFilter("sector_organisation.sector_id", + options = lambda: \ + get_s3_filter_opts("org_sector", + location_filter=True, + none=True, + translate=True), + ) + ) + + append(S3OptionsFilter("country", + #label = T("Home Country"), + ), + ) + + report_fields = ["organisation_organisation_type.organisation_type_id", + "country", + ] + if use_sector: + report_fields.insert(1, "sector_organisation.sector_id") + report_options = Storage(rows = report_fields, + cols = report_fields, + fact = ["count(id)", + "list(name)", + ], + defaults=Storage(rows = "country", + cols = "organisation_organisation_type.organisation_type_id", + fact = "count(id)", + totals = True, + chart = "spectrum:cols", + #table = "collapse", + ), + ) location_context = settings.get_org_organisation_location_context() @@ -520,17 +565,13 @@ def model(self): crud_form = crud_form, deduplicate = self.organisation_duplicate, filter_widgets = filter_widgets, - list_fields = ["id", - "name", - "acronym", - "organisation_organisation_type.organisation_type_id", - "website" - ], + list_fields = list_fields, list_layout = org_organisation_list_layout, list_orderby = "org_organisation.name", onaccept = self.org_organisation_onaccept, ondelete = self.org_organisation_ondelete, referenced_by = [(utablename, "organisation_id")], + report_options = report_options, super_entity = "pr_pentity", ) @@ -3361,9 +3402,6 @@ def model(self): msg_record_deleted = T("Facility deleted"), msg_list_empty = T("No Facilities currently registered")) - # Which levels of Hierarchy are we using? - levels = current.gis.get_relevant_hierarchy_levels() - text_fields = ["name", "code", "comments", @@ -3376,6 +3414,8 @@ def model(self): "organisation_id", ] + # Which levels of Hierarchy are we using? + levels = current.gis.get_relevant_hierarchy_levels() for level in levels: lfield = "location_id$%s" % level report_fields.append(lfield) @@ -3482,6 +3522,7 @@ def model(self): cols = "site_facility_type.facility_type_id", fact = "count(id)", totals = True, + chart = "barchart:rows", ), ) @@ -4109,9 +4150,6 @@ def model(self): #hidden = True, ) - # Which levels of Hierarchy are we using? - levels = current.gis.get_relevant_hierarchy_levels() - text_fields = ["name", "code", "comments", @@ -4119,16 +4157,19 @@ def model(self): "organisation_id$acronym", ] - list_fields = ["id", - "name", - "organisation_id", # Filtered in Component views - "office_type_id", - ] + report_fields = ["name", + "organisation_id", # Filtered in Component views + "office_type_id", + ] + # Which levels of Hierarchy are we using? + levels = current.gis.get_relevant_hierarchy_levels() for level in levels: lfield = "location_id$%s" % level + report_fields.append(lfield) text_fields.append(lfield) + list_fields = list(report_fields) list_fields += [(T("Address"), "location_id$addr_street"), "phone1", "email", @@ -4151,6 +4192,21 @@ def model(self): ), ] + report_options = Storage( + rows = report_fields, + cols = report_fields, + fact = ["count(id)", + "list(name)", + ], + defaults = Storage(rows = lfield, # Lowest-level of hierarchy + cols = "office_type_id", + fact = "count(id)", + totals = True, + chart = "spectrum:rows", + ), + ) + + configure(tablename, context = {"location": "location_id", "organisation": "organisation_id", @@ -4177,6 +4233,7 @@ def model(self): "recv", "address", ), + report_options = report_options, super_entity = ("doc_entity", "pr_pentity", "org_site"), update_realm = True, ) @@ -4430,7 +4487,7 @@ def org_organisation_logo(id, _height=60, ) return logo - return DIV() # no logo so return an empty div + return "" # ============================================================================= def org_parents(organisation_id, path=[]): diff --git a/modules/s3menus.py b/modules/s3menus.py index 2d16dcf10f..160f50b9e9 100644 --- a/modules/s3menus.py +++ b/modules/s3menus.py @@ -982,6 +982,8 @@ def hrm(): # to have them checked only immediately before rendering: manager_mode = lambda i: s3.hrm.mode is None personal_mode = lambda i: s3.hrm.mode is not None + skills = lambda i: settings.get_hrm_use_skills() + certificates = lambda i: settings.get_hrm_use_certificates() is_org_admin = lambda i: s3.hrm.orgs and True or \ ADMIN in s3.roles settings = current.deployment_settings @@ -994,14 +996,15 @@ def hrm(): check=manager_mode)( M("Create", m="create"), M("Search by Skills", f="competency"), + M("Search by Skills", f="competency", check=skills), M("Import", f="person", m="import", vars={"group":"staff"}, p="create"), ), M("Staff & Volunteers (Combined)", c="hrm", f="human_resource", m="summary", - check=[manager_mode, vol_enabled]), + check=(manager_mode, vol_enabled)), M(teams, f="group", - check=[manager_mode, use_teams])( + check=(manager_mode, use_teams))( M("Create", m="create"), M("Search Members", f="group_membership"), M("Import", f="group_membership", m="import"), @@ -1015,7 +1018,7 @@ def hrm(): M("Create", m="create"), ), M("Skill Catalog", f="skill", - check=manager_mode)( + check=(manager_mode, skills))( M("Create", m="create"), #M("Skill Provisions", f="skill_provision"), ), @@ -1071,23 +1074,25 @@ def vol(): show_programmes = lambda i: settings.get_hrm_vol_experience() == "programme" show_tasks = lambda i: settings.has_module("project") and \ settings.get_project_mode_task() + skills = lambda i: settings.get_hrm_use_skills() + certificates = lambda i: settings.get_hrm_use_certificates() teams = settings.get_hrm_teams() use_teams = lambda i: teams show_staff = lambda i: settings.get_hrm_show_staff() return M(c="vol")( M("Volunteers", f="volunteer", m="summary", - check=[manager_mode])( + check=(manager_mode))( M("Create", m="create"), - M("Search by skills", f="competency"), + M("Search by skills", f="competency", check=skills), M("Import", f="person", m="import", vars={"group":"volunteer"}, p="create"), ), M("Staff & Volunteers (Combined)", c="vol", f="human_resource", m="summary", - check=[manager_mode, show_staff]), + check=(manager_mode, show_staff)), M(teams, f="group", - check=[manager_mode, use_teams])( + check=(manager_mode, use_teams))( M("Create", m="create"), M("Search Members", f="group_membership"), M("Import", f="group_membership", m="import"), @@ -1117,7 +1122,7 @@ def vol(): #M("Course Certificates", f="course_certificate"), ), M("Certificate Catalog", f="certificate", - check=manager_mode)( + check=(manager_mode, certificates))( M("Create", m="create"), #M("Skill Equivalence", f="certificate_skill"), ), @@ -1460,7 +1465,11 @@ def org(): M("Map", m="map"), M("Import", m="import") ), - M("Facilities", f="facility", m="summary")( + M("Facilities", f="facility")( + M("Create", m="create"), + M("Import", m="import"), + ), + M("Resource Inventory", f="resource")( M("Create", m="create"), M("Import", m="import") ), diff --git a/modules/templates/IFRC/config.py b/modules/templates/IFRC/config.py index 95ac05c2df..0f41433782 100644 --- a/modules/templates/IFRC/config.py +++ b/modules/templates/IFRC/config.py @@ -2369,8 +2369,6 @@ def custom_prep(r): filter_widgets = resource.get_config("filter_widgets") # Remove type (always 'RC') filter_widgets.pop(1) - # Remove sector (not relevant) - filter_widgets.pop(1) # Modify CRUD Strings s3.crud_strings.org_organisation = Storage( diff --git a/modules/templates/default/config.py b/modules/templates/default/config.py index 3a4549c930..e4d9ccbc91 100644 --- a/modules/templates/default/config.py +++ b/modules/templates/default/config.py @@ -503,6 +503,8 @@ def config(settings): # Organisations # Uncomment to use an Autocomplete for Organisation lookup fields #settings.org.autocomplete = True + # Enable the Organisation Sector field + #settings.org.sector = True # Enable the use of Organisation Branches #settings.org.branches = True # Show branches as tree rather than as table