-
Notifications
You must be signed in to change notification settings - Fork 23
/
issue.py
120 lines (102 loc) · 3.97 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
118
119
120
# -*- coding: utf-8 -*-
from BeautifulSoup import BeautifulSoup
from Products.EasyNewsletter import EasyNewsletterMessageFactory as _
from Products.EasyNewsletter.config import PLACEHOLDERS
from Products.EasyNewsletter.utils import addTokenToUrl
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')
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(
addTokenToUrl(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(
addTokenToUrl(self.context.absolute_url())
)
self.send_issue_immediately()
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.
"""
if "_authenticator" not in self.request:
authenticator = self.context.restrictedTraverse("@@authenticator")
self.request['_authenticator'] = authenticator.token()
html = self.context._render_output_html()
for placeholder in PLACEHOLDERS:
html = html.replace('[[' + placeholder + ']]', '')
soup = BeautifulSoup(html)
for node in soup.findAll('div', {'class': 'mailonly'}):
node.extract()
return soup.renderContents()
def copy_as_draft(self):
newsletter = self.context.aq_parent
master_id = self.context.getId()
if master_id.startswith('master_'):
draft_id = master_id[len('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(
addTokenToUrl(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(
addTokenToUrl(master_obj.absolute_url() + '/edit')
)