Passed
Push — 2.x ( 908061...0c6678 )
by Ramon
27:59 queued 21:19
created

SamplePoint.setSamplingFrequency()   A

Complexity

Conditions 1

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 1
nop 2
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 senaiteMessageFactory as _
23
from bika.lims.interfaces import IDeactivable
24
from plone.autoform import directives
25
from plone.namedfile.field import NamedBlobFile
26
from plone.supermodel import model
27
from Products.CMFCore import permissions
28
from senaite.core.catalog import SETUP_CATALOG
29
from senaite.core.content.base import Container
30
from senaite.core.content.mixins import ClientAwareMixin
31
from senaite.core.interfaces import ISamplePoint
32
from senaite.core.schema import DurationField
33
from senaite.core.schema import UIDReferenceField
34
from senaite.core.schema.coordinatefield import LatitudeCoordinateField
35
from senaite.core.schema.coordinatefield import LongitudeCoordinateField
36
from senaite.core.z3cform.widgets.uidreference import UIDReferenceWidgetFactory
37
from zope import schema
38
from zope.interface import implementer
39
40
41
class ISamplePointSchema(model.Schema):
42
    """Schema interface
43
    """
44
45
    model.fieldset(
46
        "location",
47
        label=_(u"fieldset_samplepoint_location", default=u"Location"),
48
        fields=[
49
            "latitude",
50
            "longitude",
51
            "elevation",
52
        ]
53
    )
54
55
    title = schema.TextLine(
56
        title=_(
57
            u"title_samplepoint_title",
58
            default=u"Name"
59
        ),
60
        required=True,
61
    )
62
63
    description = schema.Text(
64
        title=_(
65
            u"title_samplepoint_description",
66
            default=u"Description"
67
        ),
68
        required=False,
69
    )
70
71
    latitude = LatitudeCoordinateField(
72
        title=_(
73
            u"title_samplepoint_latitude",
74
            default=u"Latitude"
75
        ),
76
        description=_(
77
            u"description_samplepoint_latitude",
78
            default=u"Enter the Sample Point's latitude in degrees 0-90, "
79
                    u"minutes 0-59, seconds 0-59.9999 and N/S indicator"
80
        ),
81
        required=False,
82
    )
83
84
    longitude = LongitudeCoordinateField(
85
        title=_(
86
            u'title_samplepoint_longitude',
87
            default=u"Longitude"
88
        ),
89
        description=_(
90
            u"description_samplepoint_longitude",
91
            default=u"Enter the Sample Point's longitude in degrees 0-180, "
92
                    u"minutes 0-59, seconds 0-59.9999 and E/W indicator"
93
        ),
94
        required=False,
95
    )
96
97
    elevation = schema.TextLine(
98
        title=_(
99
            u'title_samplepoint_elevation',
100
            default=u"Elevation"
101
        ),
102
        description=_(
103
            u"description_samplepoint_elevation",
104
            default=u"The height or depth at which the sample has to be taken"
105
        ),
106
        required=False,
107
    )
108
109
    sampling_frequency = DurationField(
110
        title=_(
111
            u"title_samplepoint_sampling_frequency",
112
            default=u"Sampling Frequency"
113
        ),
114
        description=_(
115
            u"description_samplepoint_sampling_frequency",
116
            default=u"If a sample is taken periodically at this sample point, "
117
                    u"enter frequency here, e.g. weekly"
118
        ),
119
        required=False,
120
    )
121
122
    directives.widget(
123
        "sample_types",
124
        UIDReferenceWidgetFactory,
125
        catalog=SETUP_CATALOG,
126
        query={
127
            "is_active": True,
128
            "sort_on": "title",
129
            "sort_order": "ascending",
130
        },
131
    )
132
    sample_types = UIDReferenceField(
133
        title=_(
134
            u"title_samplepoint_sampling_sample_types",
135
            default=u"Sample Types"
136
        ),
137
        description=_(
138
            u"description_samplepoint_sampling_sample_types",
139
            default=u"The list of sample types that can be collected "
140
                    u"at this sample point. The field for the selection of "
141
                    u"a sample point in sample creation and edit forms "
142
                    u"will be filtered in accordance. Still, sample points "
143
                    u"that do not have any sample type assigned will "
144
                    u"always be available for selection, regardless of the "
145
                    u"type."
146
        ),
147
        relationship="SamplePointSampleType",
148
        allowed_types=("SampleType", ),
149
        multi_valued=True,
150
        required=False,
151
    )
152
153
    composite = schema.Bool(
154
        title=_(
155
            u"title_samplepoint_composite",
156
            default=u"Composite"
157
        ),
158
        description=_(
159
            u"description_samplepoint_composite",
160
            default=u"Check this box if the samples taken at this point are "
161
                    u"'composite' and put together from more than one sub "
162
                    u"sample, e.g. several surface samples from a dam mixed "
163
                    u"together to be a representative sample for the dam. The "
164
                    u"default, unchecked, indicates 'grab' samples"
165
        ),
166
        required=False,
167
    )
168
169
    attachment_file = NamedBlobFile(
170
        title=_(
171
            u"title_samplepoint_attachment_file",
172
            default=u"Attachment"
173
        ),
174
        required=False,
175
    )
176
177
178
@implementer(ISamplePoint, ISamplePointSchema, IDeactivable)
179
class SamplePoint(Container, ClientAwareMixin):
180
    """Sample point
181
    """
182
    # Catalogs where this type will be catalogued
183
    _catalogs = [SETUP_CATALOG]
184
185
    security = ClassSecurityInfo()
186
187
    @security.protected(permissions.View)
188
    def getLatitude(self):
189
        accessor = self.accessor("latitude")
190
        return accessor(self)
191
192
    @security.protected(permissions.ModifyPortalContent)
193
    def setLatitude(self, value):
194
        mutator = self.mutator("latitude")
195
        mutator(self, value)
196
197
    # BBB: AT schema field property
198
    Latitude = property(getLatitude, setLatitude)
199
200
    @security.protected(permissions.View)
201
    def getLongitude(self):
202
        accessor = self.accessor("longitude")
203
        return accessor(self)
204
205
    @security.protected(permissions.ModifyPortalContent)
206
    def setLongitude(self, value):
207
        mutator = self.mutator("longitude")
208
        mutator(self, value)
209
210
    # BBB: AT schema field property
211
    Longitude = property(getLongitude, setLongitude)
212
213
    @security.protected(permissions.View)
214
    def getElevation(self):
215
        accessor = self.accessor("elevation")
216
        return accessor(self)
217
218
    @security.protected(permissions.ModifyPortalContent)
219
    def setElevation(self, value):
220
        mutator = self.mutator("elevation")
221
        mutator(self, value)
222
223
    # BBB: AT schema field property
224
    Elevation = property(getElevation, setElevation)
225
226
    @security.protected(permissions.View)
227
    def getSamplingFrequency(self):
228
        accessor = self.accessor("sampling_frequency")
229
        return accessor(self)
230
231
    @security.protected(permissions.ModifyPortalContent)
232
    def setSamplingFrequency(self, value):
233
        mutator = self.mutator("sampling_frequency")
234
        mutator(self, value)
235
236
    # BBB: AT schema field property
237
    SamplingFrequency = property(getSamplingFrequency, setSamplingFrequency)
238
239
    @security.protected(permissions.View)
240
    def getRawSampleTypes(self):
241
        accessor = self.accessor("sample_types", raw=True)
242
        return accessor(self) or []
243
244
    @security.protected(permissions.View)
245
    def getSampleTypes(self):
246
        accessor = self.accessor("sample_types")
247
        return accessor(self) or []
248
249
    @security.protected(permissions.ModifyPortalContent)
250
    def setSampleTypes(self, value):
251
        mutator = self.mutator("sample_types")
252
        mutator(self, value)
253
254
    @security.protected(permissions.View)
255
    def getComposite(self):
256
        accessor = self.accessor("composite")
257
        return accessor(self)
258
259
    @security.protected(permissions.ModifyPortalContent)
260
    def setComposite(self, value):
261
        mutator = self.mutator("composite")
262
        mutator(self, value)
263
264
    # BBB: AT schema field property
265
    Composite = property(getComposite, setComposite)
266
267
    @security.protected(permissions.View)
268
    def getAttachmentFile(self):
269
        accessor = self.accessor("attachment_file")
270
        return accessor(self)
271
272
    @security.protected(permissions.ModifyPortalContent)
273
    def setAttachmentFile(self, value):
274
        mutator = self.mutator("attachment_file")
275
        mutator(self, value)
276
277
    # BBB: AT schema field property
278
    AttachmentFile = property(getAttachmentFile, setAttachmentFile)
279