Passed
Push — 2.x ( 5f99f1...f3b920 )
by Jordi
05:20
created

Setup.setSiteLogo()   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 2
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
    ###
82
    # Fieldsets
83
    ###
84
85
    model.fieldset(
86
        "notifications",
87
        label=_(u"Notifications"),
88
        fields=[
89
            "email_body_sample_publication",
90
        ]
91
    )
92
93
    model.fieldset(
94
        "appearance",
95
        label=_(u"Appearance"),
96
        fields=[
97
            "site_logo",
98
            "site_logo_css",
99
        ]
100
    )
101
102
103
@implementer(ISetup, ISetupSchema, IHideActionsMenu)
104
class Setup(Container):
105
    """SENAITE Setup Folder
106
    """
107
    security = ClassSecurityInfo()
108
109
    @security.protected(permissions.View)
110
    def getEmailBodySamplePublication(self):
111
        """Returns the transformed email body text for publication emails
112
        """
113
        accessor = self.accessor("email_body_sample_publication")
114
        value = accessor(self)
115
        if IRichTextValue.providedBy(value):
116
            # Transforms the raw value to the output mimetype
117
            value = value.output_relative_to(self)
118
        if not value:
119
            # Always fallback to default value
120
            value = default_email_body_sample_publication(self)
121
        return value
122
123
    @security.protected(permissions.ModifyPortalContent)
124
    def setEmailBodySamplePublication(self, value):
125
        """Set email body text for publication emails
126
        """
127
        mutator = self.mutator("email_body_sample_publication")
128
        return mutator(self, value)
129
130
    @security.protected(permissions.View)
131
    def getEnableGlobalAuditlog(self):
132
        """Returns if the global Auditlog is enabled
133
        """
134
        accessor = self.accessor("enable_global_auditlog")
135
        return accessor(self)
136
137
    @security.protected(permissions.ModifyPortalContent)
138
    def setEnableGlobalAuditlog(self, value):
139
        """Enable/Disable global Auditlogging
140
        """
141
        if value is False:
142
            # clear the auditlog catalog
143
            catalog = api.get_tool(AUDITLOG_CATALOG)
144
            catalog.manage_catalogClear()
145
        mutator = self.mutator("enable_global_auditlog")
146
        return mutator(self, value)
147
148
    @security.protected(permissions.View)
149
    def getSiteLogo(self):
150
        """Returns the global site logo
151
        """
152
        accessor = self.accessor("site_logo")
153
        return accessor(self)
154
155
    @security.protected(permissions.ModifyPortalContent)
156
    def setSiteLogo(self, value):
157
        """Set the site logo
158
        """
159
        mutator = self.mutator("site_logo")
160
        return mutator(self, value)
161
162
    @security.protected(permissions.View)
163
    def getSiteLogoCSS(self):
164
        """Returns the global site logo
165
        """
166
        accessor = self.accessor("site_logo_css")
167
        return accessor(self)
168
169
    @security.protected(permissions.ModifyPortalContent)
170
    def setSiteLogoCSS(self, value):
171
        """Set the site logo
172
        """
173
        mutator = self.mutator("site_logo_css")
174
        return mutator(self, value)