From 7f1b828e3f5a633418735a0855f77820f9be30e1 Mon Sep 17 00:00:00 2001 From: Ramon Bartl Date: Sun, 23 Feb 2020 13:15:10 +0100 Subject: [PATCH 1/6] Added custom keyword index to query contained sample uids in reports --- bika/lims/catalog/indexers/arreport.py | 30 +++++++++++++++++++++++ bika/lims/catalog/indexers/configure.zcml | 3 +++ bika/lims/setuphandlers.py | 1 + bika/lims/upgrade/v01_03_003.py | 3 +++ 4 files changed, 37 insertions(+) create mode 100644 bika/lims/catalog/indexers/arreport.py diff --git a/bika/lims/catalog/indexers/arreport.py b/bika/lims/catalog/indexers/arreport.py new file mode 100644 index 0000000000..2f803e968b --- /dev/null +++ b/bika/lims/catalog/indexers/arreport.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# +# This file is part of SENAITE.CORE. +# +# SENAITE.CORE is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, version 2. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., 51 +# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Copyright 2018-2020 by it's authors. +# Some rights reserved, see README and LICENSE. + +from plone.indexer import indexer + +from bika.lims.interfaces import IARReport + + +@indexer(IARReport) +def contained_sample_uids(instance): + """Returns a list of UIDs of the contained Samples + """ + return instance.getRawContainedAnalysisRequests() diff --git a/bika/lims/catalog/indexers/configure.zcml b/bika/lims/catalog/indexers/configure.zcml index a1eb0833fe..03f2184ce7 100644 --- a/bika/lims/catalog/indexers/configure.zcml +++ b/bika/lims/catalog/indexers/configure.zcml @@ -43,6 +43,9 @@ + + + diff --git a/bika/lims/setuphandlers.py b/bika/lims/setuphandlers.py index 0b2f95908d..fb681cc43f 100644 --- a/bika/lims/setuphandlers.py +++ b/bika/lims/setuphandlers.py @@ -192,6 +192,7 @@ ("bika_setup_catalog", "title", "", "FieldIndex"), ("portal_catalog", "Analyst", "", "FieldIndex"), + ("portal_catalog", "contained_sample_uids", "", "KeywordIndex"), ) COLUMNS = ( diff --git a/bika/lims/upgrade/v01_03_003.py b/bika/lims/upgrade/v01_03_003.py index b096016c4b..b85e62794d 100644 --- a/bika/lims/upgrade/v01_03_003.py +++ b/bika/lims/upgrade/v01_03_003.py @@ -133,6 +133,9 @@ # Default listing_searchable_text index adapter for setup_catalog ("bika_setup_catalog", "category_uid", "KeywordIndex"), + + # Allows to search ARReports where the current Sample is contained + ("portal_catalog", "contained_sample_uids", "KeywordIndex"), ] INDEXES_TO_REMOVE = [ From de8b8706d86fba547956b2be5e12dc4e6b29e49e Mon Sep 17 00:00:00 2001 From: Ramon Bartl Date: Sun, 23 Feb 2020 13:16:03 +0100 Subject: [PATCH 2/6] Refactored published_results view for Samples --- .../analysisrequest/published_results.py | 149 ++++-------------- bika/lims/browser/publish/configure.zcml | 11 +- bika/lims/browser/publish/reports_listing.py | 8 +- 3 files changed, 45 insertions(+), 123 deletions(-) diff --git a/bika/lims/browser/analysisrequest/published_results.py b/bika/lims/browser/analysisrequest/published_results.py index 4584be9861..48ab2e90aa 100644 --- a/bika/lims/browser/analysisrequest/published_results.py +++ b/bika/lims/browser/analysisrequest/published_results.py @@ -18,135 +18,48 @@ # Copyright 2018-2020 by it's authors. # Some rights reserved, see README and LICENSE. -from Products.CMFCore.utils import getToolByName from bika.lims import api -from bika.lims import bikaMessageFactory as _ -from bika.lims.browser.bika_listing import BikaListingView -from bika.lims.utils import t +from bika.lims.browser.publish.reports_listing import ReportsListingView -class AnalysisRequestPublishedResults(BikaListingView): +class AnalysisRequestPublishedResults(ReportsListingView): """View of published results - - Prints the list of pdf files with each publication dates, the user - responsible of that publication, the emails of the addressees (and/or) - client contact names with the publication mode used (pdf, email, etc.) """ - # I took IViewView away, because transitions selected in the edit-bar - # cause errors due to wrong context, when invoked from this view, and I - # don't know why. - # implements(IViewView) def __init__(self, context, request): super(AnalysisRequestPublishedResults, self).__init__(context, request) - self.catalog = "portal_catalog" + + # get the client for the catalog query + client = context.getClient() + client_path = api.get_path(client) + + # get the UID of the current context (sample) + sample_uid = api.get_uid(context) + self.contentFilter = { - 'portal_type': 'ARReport', - 'path': { - 'query': api.get_path(self.context), - 'depth': 1, + "portal_type": "ARReport", + "path": { + "query": client_path, + "depth": 2, }, - 'sort_order': 'reverse' + # search all reports where the current sample is contained + "contained_sample_uids": [sample_uid], + "sort_on": "created", + "sort_order": "descending", } - self.context_actions = {} - self.show_select_column = True - self.show_workflow_action_buttons = False - self.form_id = 'published_results' - self.icon = self.portal_url + "/++resource++bika.lims.images/report_big.png" - self.title = self.context.translate(_("Published results")) - self.columns = { - 'Title': {'title': _('File')}, - 'FileSize': {'title': _('Size')}, - 'Date': {'title': _('Published Date')}, - 'PublishedBy': {'title': _('Published By')}, - 'DatePrinted': {'title': _('Printed Date')}, - 'Recipients': {'title': _('Recipients')}, - } + # disable the searchbox in this listing + self.show_search = False + + # only allow the email transition at this level self.review_states = [ - {'id': 'default', - 'title': 'All', - 'contentFilter': {}, - 'columns': ['Title', - 'FileSize', - 'Date', - 'PublishedBy', - 'DatePrinted', - 'Recipients']}, + { + "id": "default", + "title": "All", + "contentFilter": {}, + "columns": self.columns.keys(), + "custom_transitions": [ + self.send_email_transition, + ] + }, ] - - def __call__(self): - # Printing workflow enabled? - # If not, remove the Column - self.printwfenabled = self.context.bika_setup.getPrintingWorkflowEnabled() - printed_colname = 'DatePrinted' - if not self.printwfenabled and printed_colname in self.columns: - # Remove "Printed" columns - del self.columns[printed_colname] - tmprvs = [] - for rs in self.review_states: - tmprs = rs - tmprs['columns'] = [c for c in rs.get('columns', []) if - c != printed_colname] - tmprvs.append(tmprs) - self.review_states = tmprvs - - template = BikaListingView.__call__(self) - return template - - def contentsMethod(self, contentFilter): - """ - ARReport objects associated to the current Analysis request. - If the user is not a Manager or LabManager or Client, no items are - displayed. - """ - allowedroles = ['Manager', 'LabManager', 'Client', 'LabClerk'] - pm = getToolByName(self.context, "portal_membership") - member = pm.getAuthenticatedMember() - roles = member.getRoles() - allowed = [a for a in allowedroles if a in roles] - return self.context.objectValues('ARReport') if allowed else [] - - def folderitem(self, obj, item, index): - obj_url = obj.absolute_url() - pdf = obj.getPdf() - filesize = 0 - title = _('Download') - anchor = "%s" % \ - (obj_url, _("Download")) - try: - filesize = pdf.get_size() - filesize = filesize / 1024 if filesize > 0 else 0 - except: - # POSKeyError: 'No blob file' - # Show the record, but not the link - title = _('Not available') - anchor = title - - item['Title'] = title - item['FileSize'] = '%sKb' % filesize - fmt_date = self.ulocalized_time(obj.created(), long_format=1) - item['Date'] = fmt_date - item['PublishedBy'] = self.user_fullname(obj.Creator()) - - if self.printwfenabled: - # The date when the Results Report was printed (if so) - item['DatePrinted'] = '' - fmt_date = obj.getDatePrinted() if hasattr(obj, 'getDatePrinted') else '' - if (fmt_date): - fmt_date = self.ulocalized_time(fmt_date, long_format=1) - item['DatePrinted'] = fmt_date - if obj.getDatePrinted() is None: - item['after']['DatePrinted'] = ("" % - (t(_("Has not been Printed.")))) - - recip = [] - for recipient in obj.getRecipients(): - email = recipient['EmailAddress'] - val = recipient['Fullname'] - if email: - val = "%s" % (email, val) - recip.append(val) - item['replace']['Recipients'] = ', '.join(recip) - item['replace']['Title'] = anchor - return item diff --git a/bika/lims/browser/publish/configure.zcml b/bika/lims/browser/publish/configure.zcml index 4809fcb919..26c6e55958 100644 --- a/bika/lims/browser/publish/configure.zcml +++ b/bika/lims/browser/publish/configure.zcml @@ -22,7 +22,7 @@ layer="bika.lims.interfaces.IBikaLIMS" /> - + + + + Date: Sun, 23 Feb 2020 13:22:32 +0100 Subject: [PATCH 3/6] Changelog updated --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 8925b6f1dc..1e4b18809a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -32,7 +32,7 @@ Changelog - #1466 Support for "readonly" and "hidden" visibility modes in ReferenceWidget **Changed** - +- #1555 List all multi-reports for samples, where the current sample is contained - #1543 Sort navigation child-nodes alphabetically - #1539 Avoid unnecessary Price recalculations in Sample Add Form - #1532 Updated jQuery Barcode to version 2.2.0 From 482bbd80e34122049003c5253d5145d4915353ab Mon Sep 17 00:00:00 2001 From: Ramon Bartl Date: Wed, 26 Feb 2020 13:44:24 +0100 Subject: [PATCH 4/6] Improved index name contained_sample_uid -> report_sample_uid --- bika/lims/browser/analysisrequest/published_results.py | 2 +- bika/lims/catalog/indexers/arreport.py | 2 +- bika/lims/catalog/indexers/configure.zcml | 2 +- bika/lims/setuphandlers.py | 2 +- bika/lims/upgrade/v01_03_003.py | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bika/lims/browser/analysisrequest/published_results.py b/bika/lims/browser/analysisrequest/published_results.py index 48ab2e90aa..3e4a77a752 100644 --- a/bika/lims/browser/analysisrequest/published_results.py +++ b/bika/lims/browser/analysisrequest/published_results.py @@ -43,7 +43,7 @@ def __init__(self, context, request): "depth": 2, }, # search all reports where the current sample is contained - "contained_sample_uids": [sample_uid], + "report_sample_uid": [sample_uid], "sort_on": "created", "sort_order": "descending", } diff --git a/bika/lims/catalog/indexers/arreport.py b/bika/lims/catalog/indexers/arreport.py index 2f803e968b..be0c7adeaa 100644 --- a/bika/lims/catalog/indexers/arreport.py +++ b/bika/lims/catalog/indexers/arreport.py @@ -24,7 +24,7 @@ @indexer(IARReport) -def contained_sample_uids(instance): +def report_sample_uid(instance): """Returns a list of UIDs of the contained Samples """ return instance.getRawContainedAnalysisRequests() diff --git a/bika/lims/catalog/indexers/configure.zcml b/bika/lims/catalog/indexers/configure.zcml index 03f2184ce7..7f07cc18d5 100644 --- a/bika/lims/catalog/indexers/configure.zcml +++ b/bika/lims/catalog/indexers/configure.zcml @@ -44,7 +44,7 @@ - + diff --git a/bika/lims/setuphandlers.py b/bika/lims/setuphandlers.py index fb681cc43f..8660387cea 100644 --- a/bika/lims/setuphandlers.py +++ b/bika/lims/setuphandlers.py @@ -192,7 +192,7 @@ ("bika_setup_catalog", "title", "", "FieldIndex"), ("portal_catalog", "Analyst", "", "FieldIndex"), - ("portal_catalog", "contained_sample_uids", "", "KeywordIndex"), + ("portal_catalog", "report_sample_uid", "", "KeywordIndex"), ) COLUMNS = ( diff --git a/bika/lims/upgrade/v01_03_003.py b/bika/lims/upgrade/v01_03_003.py index b85e62794d..e762ce2c3c 100644 --- a/bika/lims/upgrade/v01_03_003.py +++ b/bika/lims/upgrade/v01_03_003.py @@ -134,8 +134,8 @@ # Default listing_searchable_text index adapter for setup_catalog ("bika_setup_catalog", "category_uid", "KeywordIndex"), - # Allows to search ARReports where the current Sample is contained - ("portal_catalog", "contained_sample_uids", "KeywordIndex"), + # Allows to search ARReports where the current Sample UID is included + ("portal_catalog", "report_sample_uid", "KeywordIndex"), ] INDEXES_TO_REMOVE = [ From 32c6b1c4707bf450b1d7bc32353e916efdd0caba Mon Sep 17 00:00:00 2001 From: Ramon Bartl Date: Wed, 26 Feb 2020 13:46:43 +0100 Subject: [PATCH 5/6] Better comment --- bika/lims/browser/analysisrequest/published_results.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bika/lims/browser/analysisrequest/published_results.py b/bika/lims/browser/analysisrequest/published_results.py index 3e4a77a752..7335d5e268 100644 --- a/bika/lims/browser/analysisrequest/published_results.py +++ b/bika/lims/browser/analysisrequest/published_results.py @@ -42,7 +42,7 @@ def __init__(self, context, request): "query": client_path, "depth": 2, }, - # search all reports where the current sample is contained + # search all reports, where the current sample UID is included "report_sample_uid": [sample_uid], "sort_on": "created", "sort_order": "descending", From 57d75cdd53856da75acd0fb0c226e60ffd1d20ad Mon Sep 17 00:00:00 2001 From: Ramon Bartl Date: Thu, 27 Feb 2020 13:12:19 +0100 Subject: [PATCH 6/6] Changed index name to `sample_uid` --- bika/lims/browser/analysisrequest/published_results.py | 2 +- bika/lims/catalog/indexers/arreport.py | 2 +- bika/lims/catalog/indexers/configure.zcml | 2 +- bika/lims/setuphandlers.py | 2 +- bika/lims/upgrade/v01_03_003.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bika/lims/browser/analysisrequest/published_results.py b/bika/lims/browser/analysisrequest/published_results.py index 7335d5e268..a9e7ca7075 100644 --- a/bika/lims/browser/analysisrequest/published_results.py +++ b/bika/lims/browser/analysisrequest/published_results.py @@ -43,7 +43,7 @@ def __init__(self, context, request): "depth": 2, }, # search all reports, where the current sample UID is included - "report_sample_uid": [sample_uid], + "sample_uid": [sample_uid], "sort_on": "created", "sort_order": "descending", } diff --git a/bika/lims/catalog/indexers/arreport.py b/bika/lims/catalog/indexers/arreport.py index be0c7adeaa..a36d88d481 100644 --- a/bika/lims/catalog/indexers/arreport.py +++ b/bika/lims/catalog/indexers/arreport.py @@ -24,7 +24,7 @@ @indexer(IARReport) -def report_sample_uid(instance): +def sample_uid(instance): """Returns a list of UIDs of the contained Samples """ return instance.getRawContainedAnalysisRequests() diff --git a/bika/lims/catalog/indexers/configure.zcml b/bika/lims/catalog/indexers/configure.zcml index 7f07cc18d5..68b48f94cf 100644 --- a/bika/lims/catalog/indexers/configure.zcml +++ b/bika/lims/catalog/indexers/configure.zcml @@ -44,7 +44,7 @@ - + diff --git a/bika/lims/setuphandlers.py b/bika/lims/setuphandlers.py index 8660387cea..6cc8aa358a 100644 --- a/bika/lims/setuphandlers.py +++ b/bika/lims/setuphandlers.py @@ -192,7 +192,7 @@ ("bika_setup_catalog", "title", "", "FieldIndex"), ("portal_catalog", "Analyst", "", "FieldIndex"), - ("portal_catalog", "report_sample_uid", "", "KeywordIndex"), + ("portal_catalog", "sample_uid", "", "KeywordIndex"), ) COLUMNS = ( diff --git a/bika/lims/upgrade/v01_03_003.py b/bika/lims/upgrade/v01_03_003.py index e762ce2c3c..ab547dcd95 100644 --- a/bika/lims/upgrade/v01_03_003.py +++ b/bika/lims/upgrade/v01_03_003.py @@ -135,7 +135,7 @@ ("bika_setup_catalog", "category_uid", "KeywordIndex"), # Allows to search ARReports where the current Sample UID is included - ("portal_catalog", "report_sample_uid", "KeywordIndex"), + ("portal_catalog", "sample_uid", "KeywordIndex"), ] INDEXES_TO_REMOVE = [