Passed
Push — master ( ef1ceb...20aa4c )
by Jordi
06:12
created

AnalysisRequestManageResultsView.__call__()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nop 1
1
# -*- coding: utf-8 -*-
2
#
3
# This file is part of SENAITE.CORE
4
#
5
# Copyright 2018 by it's authors.
6
# Some rights reserved. See LICENSE.rst, CONTRIBUTORS.rst.
7
8
from bika.lims import bikaMessageFactory as _
9
from bika.lims.browser.analysisrequest import AnalysisRequestViewView
10
from Products.CMFPlone.utils import safe_unicode
11
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
12
13
14
class AnalysisRequestManageResultsView(AnalysisRequestViewView):
15
    """Manage Results View
16
    """
17
    template = ViewPageTemplateFile(
18
        "templates/analysisrequest_manage_results.pt")
19
20
    def __call__(self):
21
        self.checkInstrumentsValidity()
22
        return self.template()
23
24 View Code Duplication
    def checkInstrumentsValidity(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
25
        """Checks the validity of the instruments used in the Analyses
26
27
        If an analysis with an invalid instrument (out-of-date or with
28
        calibration tests failed) is found, a warn message will be displayed.
29
        """
30
        invalid = []
31
32
        ans = [a.getObject() for a in self.context.getAnalyses()]
33
        for an in ans:
34
            valid = an.isInstrumentValid()
35
            if not valid:
36
                inv = '%s (%s)' % (safe_unicode(an.Title()),
37
                                   safe_unicode(an.getInstrument().Title()))
38
                if inv not in invalid:
39
                    invalid.append(inv)
40
        if len(invalid) > 0:
41
            message = _("Some analyses use out-of-date or uncalibrated "
42
                        "instruments. Results edition not allowed")
43
            message = "%s: %s" % (message, (', '.join(invalid)))
44
            self.context.plone_utils.addPortalMessage(message, 'warn')
45