diff --git a/CHANGES.rst b/CHANGES.rst index 4318baf7c6..3d922badfc 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,7 @@ Changelog 2.3.0 (unreleased) ------------------ +- #2146 Fix "No object found for UID: " in report preview - #2145 Crop page navigation for DX reference widget - #2143 Fix Traceback when using readonly decorator for objects w/o __name__ - #2140 Allow to enable/disable analysis categories for samples diff --git a/src/senaite/core/setuphandlers.py b/src/senaite/core/setuphandlers.py index 69377f3ddb..95d384d35c 100644 --- a/src/senaite/core/setuphandlers.py +++ b/src/senaite/core/setuphandlers.py @@ -226,6 +226,7 @@ def install(context): setup_other_catalogs(portal) setup_catalog_mappings(portal) setup_auditlog_catalog_mappings(portal) + setup_catalogs_order(portal) setup_content_structure(portal) add_senaite_setup(portal) add_dexterity_portal_items(portal) @@ -480,6 +481,43 @@ def setup_auditlog_catalog_mappings(portal): AUDITLOG_CATALOG, portal_type)) +def setup_catalogs_order(portal): + """Ensures the order of catalogs portal types are bound to is correct + This is required because senaite.app.supermodel uses the first catalog + the portal type is associated with when retrieving brains + """ + logger.info("Setup Catalogs order ...") + + def sort_catalogs(id1, id2): + if id1 == id2: + return 0 + + # Audit-log catalog is always the last! + if id1 == AUDITLOG_CATALOG: + return 1 + if id2 == AUDITLOG_CATALOG: + return -1 + + # Catalogs sorted, senaite_* always first + senaite = map(lambda cat_id: cat_id.startswith("senaite_"), [id1, id2]) + if not all(senaite) and any(senaite): + # Item starting with senaite always gets max priority + if id1.startswith("senaite_"): + return -1 + return 1 + + if id1 < id2: + return -1 + return 1 + + at = api.get_tool("archetype_tool") + for portal_type, catalogs in at.listCatalogs().items(): + sorted_catalogs = sorted(catalogs, cmp=sort_catalogs) + at.setCatalogsByType(portal_type, sorted_catalogs) + + logger.info("Setup Catalogs order [DONE]") + + def remove_default_content(portal): """Remove default Plone contents """ diff --git a/src/senaite/core/upgrade/v02_03_000.py b/src/senaite/core/upgrade/v02_03_000.py index ab09941180..d23a0aaa11 100644 --- a/src/senaite/core/upgrade/v02_03_000.py +++ b/src/senaite/core/upgrade/v02_03_000.py @@ -32,6 +32,7 @@ from senaite.core.setuphandlers import add_senaite_setup from senaite.core.setuphandlers import setup_auditlog_catalog_mappings from senaite.core.setuphandlers import setup_catalog_mappings +from senaite.core.setuphandlers import setup_catalogs_order from senaite.core.setuphandlers import setup_core_catalogs from senaite.core.upgrade import upgradestep from senaite.core.upgrade.utils import UpgradeUtils @@ -76,9 +77,13 @@ def upgrade(tool): # Ensure the catalog mappings for Analyses and Samples is correct # https://github.com/senaite/senaite.core/pull/2130 setup_catalog_mappings(portal, catalog_mappings=CATALOG_MAPPINGS) + # remap auditlog catalog setup_auditlog_catalog_mappings(portal) + # ensure the catalogs assigned to types are sorted correctly + setup_catalogs_order(portal) + # Add new setup folder to portal add_senaite_setup(portal) @@ -91,6 +96,7 @@ def upgrade(tool): move_arreports_to_report_catalog(portal) migrate_analysis_services_fields(portal) migrate_analyses_fields(portal) + reindex_laboratory(portal) logger.info("{0} upgraded to version {1}".format(product, version)) return True @@ -420,3 +426,12 @@ def fixed_point_value_to_string(value, precision): str_value = template % (sign, front, fra) # strip off trailing zeros and possible dot return str_value.rstrip("0").rstrip(".") + + +def reindex_laboratory(portal): + """Forces the reindex of laboratory content type + """ + logger.info("Reindexing laboratory content type ...") + setup = api.get_setup() + setup.laboratory.reindexObject() + logger.info("Reindexing laboratory content type [DONE]")