|
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
|
|
|
@security.public |
|
67
|
|
|
def getRaw(self, instance, **kw): |
|
68
|
|
|
return getattr(instance, self.getName()) |
|
69
|
|
|
|
|
70
|
|
|
@security.private |
|
71
|
|
|
def setRaw(self, instance, uids): |
|
72
|
|
|
uids = uids if uids else [] |
|
73
|
|
|
setattr(instance, self.getName(), uids) |
|
74
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
registerField(ARAnalysesField, |
|
77
|
|
|
title="Analyses", |
|
78
|
|
|
description="Manages Analyses of ARs") |
|
79
|
|
|
|