Passed
Push — 2.x ( 9cfaa4...331aea )
by Ramon
07:57
created

ARAnalysesField.setRaw()   A

Complexity

Conditions 2

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
nop 3
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 import api
23
from bika.lims.interfaces import IARAnalysesField
24
from Products.Archetypes.public import Field
25
from Products.Archetypes.public import ObjectField
26
from Products.Archetypes.Registry import registerField
27
from senaite.core.interfaces import IDataManager
28
from zope.component._api import queryMultiAdapter
29
from zope.interface import implements
30
31
"""Field to manage Analyses on ARs
32
33
Please see the assigned doctest at tests/doctests/ARAnalysesField.rst
34
35
Run this test from the buildout directory:
36
37
    bin/test test_textual_doctests -t ARAnalysesField
38
"""
39
40
41
class ARAnalysesField(ObjectField):
42
    """A field that stores Analyses instances
43
    """
44
    implements(IARAnalysesField)
45
46
    security = ClassSecurityInfo()
47
    _properties = Field._properties.copy()
48
    _properties.update({
49
        "type": "analyses",
50
        "default": None,
51
    })
52
53
    @security.public
54
    def get(self, instance, **kw):
55
        # See `senaite.core.datamanagers.field.sample_analyses`
56
        dm = queryMultiAdapter((instance, instance.REQUEST, self),
57
                               interface=IDataManager, name="Analyses")
58
        return dm.get(**kw)
59
60
    @security.private
61
    def set(self, instance, items, prices=None, specs=None, hidden=None, **kw):
62
        # See `senaite.core.datamanagers.field.sample_analyses`
63
        dm = queryMultiAdapter((instance, instance.REQUEST, self),
64
                               interface=IDataManager, name="Analyses")
65
        return dm.set(items, prices, specs, hidden, **kw)
66
67
    @security.public
68
    def getRaw(self, instance, **kw):
69
        brains = self.get(instance)
70
        return [api.get_uid(brain) for brain in brains]
71
72
73
registerField(ARAnalysesField,
74
              title="Analyses",
75
              description="Manages Analyses of ARs")
76