| Total Complexity | 6 |
| Total Lines | 45 |
| Duplicated Lines | 42.22 % |
| Changes | 0 | ||
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 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): |
|
|
|
|||
| 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 |