Passed
Push — 2.x ( ac1fab...0dfdd1 )
by Ramon
06:57
created

senaite.core.content.multifile   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 171
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 15
eloc 109
dl 0
loc 171
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A Multifile.getDocumentType() 0 7 2
A Multifile.setDocumentVersion() 0 4 1
A Multifile.setDocumentID() 0 4 1
A Multifile.getFile() 0 4 1
A Multifile.setFile() 0 4 1
A Multifile.setDocumentLocation() 0 4 1
A Multifile.getDocumentLocation() 0 7 2
A Multifile.Title() 0 4 1
A Multifile.getDocumentID() 0 7 2
A Multifile.getDocumentVersion() 0 7 2
A Multifile.setDocumentType() 0 4 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-2025 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.api import safe_unicode as u
24
from bika.lims.interfaces import IDeactivable
25
from plone.namedfile.field import NamedBlobFile
26
from plone.supermodel import model
27
from Products.CMFCore import permissions
28
from senaite.core.content.base import Container
29
from senaite.core.interfaces import IMultifile
30
from zope import schema
31
from zope.interface import implementer
32
33
34
class IMultifileSchema(model.Schema):
35
    """Multifile Schema
36
    """
37
38
    document_id = schema.TextLine(
39
        title=_(
40
            u"label_multifile_document_id",
41
            default=u"Document ID"
42
        ),
43
        required=True,
44
    )
45
46
    file = NamedBlobFile(
47
        title=_(
48
            u"label_multifile_file",
49
            default=u"Document"
50
        ),
51
        description=_(
52
            u"description_multifile_file",
53
            default=u"File upload"
54
        ),
55
        required=True,
56
    )
57
58
    document_version = schema.TextLine(
59
        title=_(
60
            u"label_multifile_document_version",
61
            default=u"Document Version"
62
        ),
63
        required=False,
64
    )
65
66
    document_location = schema.TextLine(
67
        title=_(
68
            u"label_multifile_document_location",
69
            default=u"Document Location"
70
        ),
71
        description=_(
72
            u"description_multifile_document_location",
73
            default=u"Location where the document set is shelved"
74
        ),
75
        required=False,
76
    )
77
78
    document_type = schema.TextLine(
79
        title=_(
80
            u"label_multifile_document_type",
81
            default=u"Document Type"
82
        ),
83
        description=_(
84
            u"description_multifile_document_type",
85
            default=u"Type of document (e.g. user manual, instrument "
86
                    u"specifications, image, ...)"
87
        ),
88
        required=True,
89
    )
90
91
92
@implementer(IMultifile, IMultifileSchema, IDeactivable)
93
class Multifile(Container):
94
    """A Document/File attachment
95
    """
96
    security = ClassSecurityInfo()
97
98
    def Title(self):
99
        """Return the DocumentID as Title
100
        """
101
        return self.getDocumentID() or self.getId()
102
103
    @security.protected(permissions.View)
104
    def getDocumentID(self):
105
        accessor = self.accessor("document_id")
106
        value = accessor(self)
107
        if not value:
108
            return ""
109
        return u(value).encode("utf-8")
110
111
    @security.protected(permissions.ModifyPortalContent)
112
    def setDocumentID(self, value):
113
        mutator = self.mutator("document_id")
114
        mutator(self, u(value))
115
116
    @security.protected(permissions.View)
117
    def getFile(self):
118
        accessor = self.accessor("file")
119
        return accessor(self)
120
121
    @security.protected(permissions.ModifyPortalContent)
122
    def setFile(self, value):
123
        mutator = self.mutator("file")
124
        mutator(self, value)
125
126
    @security.protected(permissions.View)
127
    def getDocumentVersion(self):
128
        accessor = self.accessor("document_version")
129
        value = accessor(self)
130
        if not value:
131
            return ""
132
        return u(value).encode("utf-8")
133
134
    @security.protected(permissions.ModifyPortalContent)
135
    def setDocumentVersion(self, value):
136
        mutator = self.mutator("document_version")
137
        mutator(self, u(value))
138
139
    @security.protected(permissions.View)
140
    def getDocumentLocation(self):
141
        accessor = self.accessor("document_location")
142
        value = accessor(self)
143
        if not value:
144
            return ""
145
        return u(value).encode("utf-8")
146
147
    @security.protected(permissions.ModifyPortalContent)
148
    def setDocumentLocation(self, value):
149
        mutator = self.mutator("document_location")
150
        mutator(self, u(value))
151
152
    @security.protected(permissions.View)
153
    def getDocumentType(self):
154
        accessor = self.accessor("document_type")
155
        value = accessor(self)
156
        if not value:
157
            return ""
158
        return u(value).encode("utf-8")
159
160
    @security.protected(permissions.ModifyPortalContent)
161
    def setDocumentType(self, value):
162
        mutator = self.mutator("document_type")
163
        mutator(self, u(value))
164
165
    # BBB: AT schema field properties for backward compatibility
166
    DocumentID = property(getDocumentID, setDocumentID)
167
    File = property(getFile, setFile)
168
    DocumentVersion = property(getDocumentVersion, setDocumentVersion)
169
    DocumentLocation = property(getDocumentLocation, setDocumentLocation)
170
    DocumentType = property(getDocumentType, setDocumentType)
171