Passed
Push — 2.x ( c4167f...96e9ed )
by Ramon
06:12
created

senaite.core.content.samplepreservation   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 39
dl 0
loc 78
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A SamplePreservation.setCategory() 0 4 1
A SamplePreservation.getCategory() 0 5 1
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