Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "No object found for UID: <laboratory_uid>" in report preview #2146

Merged
merged 3 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
2.3.0 (unreleased)
------------------

- #2146 Fix "No object found for UID: <laboratory_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
Expand Down
38 changes: 38 additions & 0 deletions src/senaite/core/setuphandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
"""
Expand Down
15 changes: 15 additions & 0 deletions src/senaite/core/upgrade/v02_03_000.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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]")