-
Notifications
You must be signed in to change notification settings - Fork 23
/
issue.py
117 lines (99 loc) · 3.78 KB
/
issue.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# -*- coding: utf-8 -*-
import transaction
from Products.EasyNewsletter import EasyNewsletterMessageFactory as _
from Products.EasyNewsletter.interfaces import IIssueDataFetcher
from Products.Five.browser import BrowserView
from plone import api
from plone.protect import PostOnly
class IssueView(BrowserView):
"""Single Issue View
"""
def refresh_issue(self):
"""Refresh the aggregate body when using collections.
"""
if self.context.getAcquireCriteria():
self.context.loadContent()
self.request.response.redirect(self.context.absolute_url())
def _send_issue_prepare(self):
self.request['enlwf_guard'] = True
api.content.transition(obj=self.context, transition='send')
# commit the transaction so that identical incoming requests, for
# whatever reason, will not trigger another send
transaction.commit()
self.request['enlwf_guard'] = False
def send_issue(self):
"""
sets workflow state to sending and then redirects to step2 with UID as
parameter as simple safety belt.
"""
PostOnly(self.request)
if 'test' in self.request.form: # test must not modify the state
self.context.send()
api.portal.show_message(
message=_("The issue test sending has been initiated."),
request=self.request,
)
return self.request.response.redirect(self.context.absolute_url())
if self.context.is_send_queue_enabled:
self._send_issue_prepare()
self.context.queue_issue_for_sendout()
api.portal.show_message(
message=_(
"The issue sending has been initiated in the background."
),
request=self.request,
)
return self.request.response.redirect(self.context.absolute_url())
# No queuing but direct send
self.send_issue_immediately()
api.portal.show_message(
message=_(
"The issue has been generated and sent to the mail server."
),
request=self.request,
)
return self.request.response.redirect(self.context.absolute_url())
def send_issue_immediately(self):
"""convinience view for cron and similar
never call this from UI - needs a way to protect
currently manager only
"""
self._send_issue_prepare()
self.context.send()
def get_public_body(self):
""" Return the rendered HTML version without placeholders.
"""
issuedatafetcher = IIssueDataFetcher(self.context)
return issuedatafetcher.preview_html()
def copy_as_draft(self):
newsletter = self.context.aq_parent
master_id = self.context.getId()
if master_id.startswith('master_'):
draft_id = master_id.replace('master_', '')
else:
draft_id = master_id
draft_obj = api.content.copy(
source=self.context,
target=newsletter,
safe_id=True,
id=draft_id
)
return self.request.response.redirect(
draft_obj.absolute_url() + '/edit'
)
def copy_as_master(self):
request = self.context.REQUEST
newsletter = self.context.aq_parent
master_id = "master_" + self.context.getId()
master_obj = api.content.copy(
source=self.context,
target=newsletter,
safe_id=True,
id=master_id
)
request['enlwf_guard'] = True
api.content.transition(obj=master_obj, transition='make_master')
request['enlwf_guard'] = False
return self.request.response.redirect(
master_obj.absolute_url() + '/edit'
)