Passed
Push — 2.x ( 380493...9aebce )
by Jordi
06:51
created

bika.lims.browser.fields.aranalysesfield.ARAnalysesField.add_analysis()   B

Complexity

Conditions 7

Size

Total Lines 59
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 59
rs 7.784
c 0
b 0
f 0
cc 7
nop 4

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
# -*- coding: utf-8 -*-
2
#
3
# This file is part of SENAITE.CORE.
4
#
5
# SENAITE.CORE is free software: you can redistribute it and/or modify it under
6
# the terms of the GNU General Public License as published by the Free Software
7
# Foundation, version 2.
8
#
9
# This program is distributed in the hope that it will be useful, but WITHOUT
10
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12
# details.
13
#
14
# You should have received a copy of the GNU General Public License along with
15
# this program; if not, write to the Free Software Foundation, Inc., 51
16
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
#
18
# Copyright 2018-2024 by it's authors.
19
# Some rights reserved, see README and LICENSE.
20
21
from AccessControl import ClassSecurityInfo
22
from bika.lims.interfaces import IARAnalysesField
23
from Products.Archetypes.public import Field
24
from Products.Archetypes.public import ObjectField
25
from Products.Archetypes.Registry import registerField
26
from senaite.core.interfaces import IDataManager
27
from zope.component._api import queryMultiAdapter
28
from zope.interface import implements
29
30
"""Field to manage Analyses on ARs
31
32
Please see the assigned doctest at tests/doctests/ARAnalysesField.rst
33
34
Run this test from the buildout directory:
35
36
    bin/test test_textual_doctests -t ARAnalysesField
37
"""
38
39
40
class ARAnalysesField(ObjectField):
41
    """A field that stores Analyses instances
42
    """
43
    implements(IARAnalysesField)
44
45
    security = ClassSecurityInfo()
46
    _properties = Field._properties.copy()
47
    _properties.update({
48
        "type": "analyses",
49
        "default": None,
50
    })
51
52
    @security.public
53
    def get(self, instance, **kw):
54
        # See `senaite.core.datamanagers.field.sample_analyses`
55
        dm = queryMultiAdapter((instance, instance.REQUEST, self),
56
                               interface=IDataManager, name="Analyses")
57
        return dm.get(**kw)
58
59
    @security.private
60
    def set(self, instance, items, prices=None, specs=None, hidden=None, **kw):
61
        # See `senaite.core.datamanagers.field.sample_analyses`
62
        dm = queryMultiAdapter((instance, instance.REQUEST, self),
63
                               interface=IDataManager, name="Analyses")
64
        return dm.set(items, prices, specs, hidden, **kw)
65
66
67
registerField(ARAnalysesField,
68
              title="Analyses",
69
              description="Manages Analyses of ARs")
70