|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
|
|
3
|
|
|
from AccessControl import ClassSecurityInfo |
|
4
|
|
|
from bika.lims import api |
|
5
|
|
|
from plone.autoform import directives |
|
6
|
|
|
from plone.supermodel import model |
|
7
|
|
|
from plone.app.textfield.widget import RichTextFieldWidget # TBD: port to core |
|
8
|
|
|
from plone.app.textfield import IRichTextValue |
|
9
|
|
|
from Products.CMFCore import permissions |
|
10
|
|
|
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile |
|
11
|
|
|
from senaite.core.content.base import Container |
|
12
|
|
|
from senaite.core.interfaces import IHideActionsMenu |
|
13
|
|
|
from senaite.core.interfaces import ISetup |
|
14
|
|
|
from senaite.core.schema import RichTextField |
|
15
|
|
|
from senaite.impress import senaiteMessageFactory as _ |
|
16
|
|
|
from zope.interface import implementer |
|
17
|
|
|
from zope.interface import provider |
|
18
|
|
|
from zope.schema.interfaces import IContextAwareDefaultFactory |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
@provider(IContextAwareDefaultFactory) |
|
22
|
|
|
def default_email_body_sample_publication(context): |
|
23
|
|
|
"""Returns the default body text for publication emails |
|
24
|
|
|
""" |
|
25
|
|
|
view = api.get_view("senaite_view", context=api.get_setup()) |
|
26
|
|
|
if view is None: |
|
27
|
|
|
# Test fixture |
|
28
|
|
|
return u"" |
|
29
|
|
|
tpl = ViewPageTemplateFile( |
|
30
|
|
|
"../browser/setup/templates/email_body_sample_publication.pt") |
|
31
|
|
|
return tpl(view) |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
class ISetupSchema(model.Schema): |
|
35
|
|
|
"""Schema and marker interface |
|
36
|
|
|
""" |
|
37
|
|
|
|
|
38
|
|
|
directives.widget("email_body_sample_publication", RichTextFieldWidget) |
|
39
|
|
|
email_body_sample_publication = RichTextField( |
|
40
|
|
|
title=_(u"Publication Email Text"), |
|
41
|
|
|
description=_( |
|
42
|
|
|
"The default text that is used for the publication email."), |
|
43
|
|
|
defaultFactory=default_email_body_sample_publication, |
|
44
|
|
|
required=False, |
|
45
|
|
|
) |
|
46
|
|
|
|
|
47
|
|
|
### |
|
48
|
|
|
# Fieldsets |
|
49
|
|
|
### |
|
50
|
|
|
|
|
51
|
|
|
# model.fieldset( |
|
52
|
|
|
# "notifications", |
|
53
|
|
|
# label=_(u"Notifications"), |
|
54
|
|
|
# fields=[ |
|
55
|
|
|
# "email_body_sample_publication", |
|
56
|
|
|
# ] |
|
57
|
|
|
# ) |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
@implementer(ISetup, ISetupSchema, IHideActionsMenu) |
|
61
|
|
|
class Setup(Container): |
|
62
|
|
|
"""SENAITE Setup Folder |
|
63
|
|
|
""" |
|
64
|
|
|
security = ClassSecurityInfo() |
|
65
|
|
|
|
|
66
|
|
|
@security.protected(permissions.View) |
|
67
|
|
|
def getEmailBodySamplePublication(self): |
|
68
|
|
|
"""Returns the transformed email body text for publication emails |
|
69
|
|
|
""" |
|
70
|
|
|
accessor = self.accessor("email_body_sample_publication") |
|
71
|
|
|
value = accessor(self) |
|
72
|
|
|
if IRichTextValue.providedBy(value): |
|
73
|
|
|
# Transforms the raw value to the output mimetype |
|
74
|
|
|
value = value.output_relative_to(self) |
|
75
|
|
|
if not value: |
|
76
|
|
|
# Always fallback to default value |
|
77
|
|
|
value = default_email_body_sample_publication(self) |
|
78
|
|
|
return value |
|
79
|
|
|
|
|
80
|
|
|
@security.protected(permissions.ModifyPortalContent) |
|
81
|
|
|
def setEmailBodySamplePublication(self, value): |
|
82
|
|
|
"""Set email body text for publication emails |
|
83
|
|
|
""" |
|
84
|
|
|
mutator = self.mutator("email_body_sample_publication") |
|
85
|
|
|
return mutator(self, value) |
|
86
|
|
|
|