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 _ |
23
|
|
|
from bika.lims import api |
24
|
|
|
from bika.lims.interfaces import IDeactivable |
25
|
|
|
from plone.supermodel import model |
26
|
|
|
from Products.CMFCore import permissions |
27
|
|
|
from senaite.core.catalog import SETUP_CATALOG |
28
|
|
|
from senaite.core.content.base import Container |
29
|
|
|
from senaite.core.interfaces import ISamplePreservation |
30
|
|
|
from zope import schema |
31
|
|
|
from zope.interface import implementer |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
class ISamplePreservationSchema(model.Schema): |
35
|
|
|
"""Schema interface |
36
|
|
|
""" |
37
|
|
|
|
38
|
|
|
title = schema.TextLine( |
39
|
|
|
title=u"Title", |
40
|
|
|
required=False, |
41
|
|
|
) |
42
|
|
|
|
43
|
|
|
description = schema.Text( |
44
|
|
|
title=u"Description", |
45
|
|
|
required=False, |
46
|
|
|
) |
47
|
|
|
|
48
|
|
|
category = schema.Choice( |
49
|
|
|
title=_( |
50
|
|
|
u"label_samplepreservation_category", |
51
|
|
|
default=u"Category" |
52
|
|
|
), |
53
|
|
|
source="senaite.core.vocabularies.samplepreservation.categories", |
54
|
|
|
default="lab", |
55
|
|
|
required=True, |
56
|
|
|
) |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
@implementer(ISamplePreservation, ISamplePreservationSchema, IDeactivable) |
60
|
|
|
class SamplePreservation(Container): |
61
|
|
|
"""Sample preservation |
62
|
|
|
""" |
63
|
|
|
# Catalogs where this type will be catalogued |
64
|
|
|
_catalogs = [SETUP_CATALOG] |
65
|
|
|
|
66
|
|
|
security = ClassSecurityInfo() |
67
|
|
|
|
68
|
|
|
@security.protected(permissions.View) |
69
|
|
|
def getCategory(self): |
70
|
|
|
accessor = self.accessor("category") |
71
|
|
|
value = accessor(self) or "" |
72
|
|
|
return value.encode("utf-8") |
73
|
|
|
|
74
|
|
|
@security.protected(permissions.ModifyPortalContent) |
75
|
|
|
def setCategory(self, value): |
76
|
|
|
mutator = self.mutator("category") |
77
|
|
|
mutator(self, api.safe_unicode(value)) |
78
|
|
|
|