Passed
Push — 2.x ( 171335...eef595 )
by Ramon
05:32
created

Setup.getCategorizeSampleAnalyses()   A

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nop 1
1
# -*- coding: utf-8 -*-
2
3
from AccessControl import ClassSecurityInfo
4
from bika.lims import api
5
from plone.app.textfield import IRichTextValue
6
from plone.app.textfield.widget import RichTextFieldWidget  # TBD: port to core
7
from plone.autoform import directives
8
from plone.formwidget.namedfile.widget import NamedFileFieldWidget
9
from plone.supermodel import model
10
from Products.CMFCore import permissions
11
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
12
from senaite.core.catalog import AUDITLOG_CATALOG
13
from senaite.core.content.base import Container
14
from senaite.core.interfaces import IHideActionsMenu
15
from senaite.core.interfaces import ISetup
16
from senaite.core.schema import RichTextField
17
from senaite.impress import senaiteMessageFactory as _
18
from zope import schema
19
from zope.interface import implementer
20
from zope.interface import provider
21
from zope.schema.interfaces import IContextAwareDefaultFactory
22
23
24
@provider(IContextAwareDefaultFactory)
25
def default_email_body_sample_publication(context):
26
    """Returns the default body text for publication emails
27
    """
28
    view = api.get_view("senaite_view", context=api.get_setup())
29
    if view is None:
30
        # Test fixture
31
        return u""
32
    tpl = ViewPageTemplateFile(
33
        "../browser/setup/templates/email_body_sample_publication.pt")
34
    return tpl(view)
35
36
37
class ISetupSchema(model.Schema):
38
    """Schema and marker interface
39
    """
40
41
    directives.widget("email_body_sample_publication", RichTextFieldWidget)
42
    email_body_sample_publication = RichTextField(
43
        title=_(u"Publication Email Text"),
44
        description=_(
45
            "The default text that is used for the publication email."),
46
        defaultFactory=default_email_body_sample_publication,
47
        required=False,
48
    )
49
50
    enable_global_auditlog = schema.Bool(
51
        title=_(u"Enable global Auditlog"),
52
        description=_(
53
            "The global Auditlog shows all modifications of the system. "
54
            "When enabled, all entities will be indexed in a separate "
55
            "catalog. This will increase the time when objects are "
56
            "created or modified."
57
        ),
58
        default=False,
59
    )
60
61
    # NOTE:
62
    # We use the `NamedFileFieldWidget` instead of `NamedImageFieldWidget`
63
    # by purpose! Using the latter rises this PIL error (appears only in log):
64
    # IOError: cannot identify image file <cStringIO.StringI object at ...>
65
    directives.widget("site_logo", NamedFileFieldWidget)
66
    site_logo = schema.Bytes(
67
        title=_(u"Site Logo"),
68
        description=_(u"This shows a custom logo on your SENAITE site."),
69
        required=False,
70
    )
71
72
    site_logo_css = schema.ASCII(
73
        title=_(u"Site Logo CSS"),
74
        description=_(
75
            u"Add custom CSS rules for the Logo, "
76
            u"e.g. height:15px; width:150px;"
77
        ),
78
        required=False,
79
    )
80
81
    immediate_results_entry = schema.Bool(
82
        title=_(u"Immediate results entry"),
83
        description=_(
84
            "description_senaitesetup_immediateresultsentry",
85
            default=u"Allow the user to directly enter results after sample "
86
            "creation, e.g. to enter field results immediately, or lab "
87
            "results, when the automatic sample reception is activated."
88
        ),
89
    )
90
91
    categorize_sample_analyses = schema.Bool(
92
        title=_("title_senaitesetup_categorizesampleanalyses",
93
                default=u"Categorize sample analyses"),
94
        description=_(
95
            "description_senaitesetup_categorizesampleanalyses",
96
            default=u"Group analyses by category for samples"
97
        ),
98
        default=False,
99
    )
100
101
    ###
102
    # Fieldsets
103
    ###
104
    model.fieldset(
105
        "analyses",
106
        label=_("label_senaitesetup_fieldset_analyses", default=u"Analyses"),
107
        fields=[
108
            "immediate_results_entry",
109
            "categorize_sample_analyses",
110
        ]
111
    )
112
113
    model.fieldset(
114
        "notifications",
115
        label=_(u"Notifications"),
116
        fields=[
117
            "email_body_sample_publication",
118
        ]
119
    )
120
121
    model.fieldset(
122
        "appearance",
123
        label=_(u"Appearance"),
124
        fields=[
125
            "site_logo",
126
            "site_logo_css",
127
        ]
128
    )
129
130
131
@implementer(ISetup, ISetupSchema, IHideActionsMenu)
132
class Setup(Container):
133
    """SENAITE Setup Folder
134
    """
135
    security = ClassSecurityInfo()
136
137
    @security.protected(permissions.View)
138
    def getEmailBodySamplePublication(self):
139
        """Returns the transformed email body text for publication emails
140
        """
141
        accessor = self.accessor("email_body_sample_publication")
142
        value = accessor(self)
143
        if IRichTextValue.providedBy(value):
144
            # Transforms the raw value to the output mimetype
145
            value = value.output_relative_to(self)
146
        if not value:
147
            # Always fallback to default value
148
            value = default_email_body_sample_publication(self)
149
        return value
150
151
    @security.protected(permissions.ModifyPortalContent)
152
    def setEmailBodySamplePublication(self, value):
153
        """Set email body text for publication emails
154
        """
155
        mutator = self.mutator("email_body_sample_publication")
156
        return mutator(self, value)
157
158
    @security.protected(permissions.View)
159
    def getEnableGlobalAuditlog(self):
160
        """Returns if the global Auditlog is enabled
161
        """
162
        accessor = self.accessor("enable_global_auditlog")
163
        return accessor(self)
164
165
    @security.protected(permissions.ModifyPortalContent)
166
    def setEnableGlobalAuditlog(self, value):
167
        """Enable/Disable global Auditlogging
168
        """
169
        if value is False:
170
            # clear the auditlog catalog
171
            catalog = api.get_tool(AUDITLOG_CATALOG)
172
            catalog.manage_catalogClear()
173
        mutator = self.mutator("enable_global_auditlog")
174
        return mutator(self, value)
175
176
    @security.protected(permissions.View)
177
    def getSiteLogo(self):
178
        """Returns the global site logo
179
        """
180
        accessor = self.accessor("site_logo")
181
        return accessor(self)
182
183
    @security.protected(permissions.ModifyPortalContent)
184
    def setSiteLogo(self, value):
185
        """Set the site logo
186
        """
187
        mutator = self.mutator("site_logo")
188
        return mutator(self, value)
189
190
    @security.protected(permissions.View)
191
    def getSiteLogoCSS(self):
192
        """Returns the global site logo
193
        """
194
        accessor = self.accessor("site_logo_css")
195
        return accessor(self)
196
197
    @security.protected(permissions.ModifyPortalContent)
198
    def setSiteLogoCSS(self, value):
199
        """Set the site logo
200
        """
201
        mutator = self.mutator("site_logo_css")
202
        return mutator(self, value)
203
204
    @security.protected(permissions.View)
205
    def getImmediateResultsEntry(self):
206
        """Returns if immediate results entry is enabled or not
207
        """
208
        accessor = self.accessor("immediate_results_entry")
209
        return accessor(self)
210
211
    @security.protected(permissions.ModifyPortalContent)
212
    def setImmediateResultsEntry(self, value):
213
        """Enable/Disable global Auditlogging
214
        """
215
        mutator = self.mutator("immediate_results_entry")
216
        return mutator(self, value)
217
218
    @security.protected(permissions.View)
219
    def getCategorizeSampleAnalyses(self):
220
        """Returns if analyses should be grouped by category for samples
221
        """
222
        accessor = self.accessor("categorize_sample_analyses")
223
        return accessor(self)
224
225
    @security.protected(permissions.ModifyPortalContent)
226
    def setCategorizeSampleAnalyses(self, value):
227
        """Enable/Disable grouping of analyses by category for samples
228
        """
229
        mutator = self.mutator("categorize_sample_analyses")
230
        return mutator(self, value)
231