Skip to content

Commit

Permalink
fix async support
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk committed May 24, 2024
1 parent a1930f6 commit 50b0d72
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 44 deletions.
63 changes: 55 additions & 8 deletions src/rer/newsletter/adapter/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _getMessage(self, message, footer):
<tr>
<td align="left" colspan="2">
<div class="newsletterTitle">
<h1>{self.context.title}</h1>
<h1>{message.title}</h1>
</div>
</td>
</tr>""",
Expand Down Expand Up @@ -124,23 +124,66 @@ def set_end_send_infos(self, send_uid, completed=True):
send_info = [x for x in details if x["uid"] == send_uid]
if not send_info:
return SEND_UID_NOT_FOUND
send_info[0]["send_date_end"] = datetime.today().strftime("%d/%m/%Y %H:%M:%S")
send_info[0]["send_date_end"] = datetime.today().strftime(
"%d/%m/%Y %H:%M:%S"
)
send_info[0]["completed"] = completed
send_info[0]["running"] = False
return OK

def prepare_body(self, message):
unsubscribe_footer_template = self.context.restrictedTraverse(
"@@unsubscribe_channel_template"
# unsubscribe_footer_template = self.context.restrictedTraverse(
# "@@unsubscribe_channel_template"
# )
# parameters = {
# "portal_name": get_site_title(),
# "channel_name": self.context.title,
# "unsubscribe_link": self.context.absolute_url(),
# "enabled": self.context.standard_unsubscribe,
# }
# footer = unsubscribe_footer_template(**parameters)
# return self._getMessage(message=message, footer=footer)
unsubscribe_footer_template = api.content.get_view(
name="unsubscribe_channel_template",
context=self.context,
request=self.request,
)
parameters = {
"portal_name": get_site_title(),
"channel_name": self.context.title,
"unsubscribe_link": self.context.absolute_url(),
"enabled": self.context.standard_unsubscribe,
}
footer = unsubscribe_footer_template(**parameters)
return self._getMessage(message=message, footer=footer)

message_template = api.content.get_view(
context=message, name="messagepreview_view", request=self.request
)
parameters = {
"message_subheader": f"""
<tr>
<td align="left" colspan="2">
<div class="newsletterTitle">
<h1>{message.title}</h1>
</div>
</td>
</tr>""",
"message_unsubscribe_default": f"""
<tr>
<td align="left" colspan="2">
<div class="newsletter-unsubscribe">
{unsubscribe_footer_template(**parameters)}
</div>
</td>
</tr>
""",
}

body = message_template(**parameters)
# passo la mail per il transform
portal = api.portal.get()
body = portal.portal_transforms.convertTo("text/mail", body)

return body

def sendMessage(self, message):
"""This is the primary method to send emails for the channel."""
Expand All @@ -149,7 +192,9 @@ def sendMessage(self, message):
subscribers = self.get_annotations_for_channel(key=SUBSCRIBERS_KEY)

nl_subject = (
" - " + self.context.subject_email if self.context.subject_email else ""
" - " + self.context.subject_email
if self.context.subject_email
else ""
)
sender = (
self.context.sender_name
Expand Down Expand Up @@ -195,7 +240,9 @@ def doSend(self, body, subject, subscribers, sender):
def addToHistory(self, message):
"""Add to history that message is sent"""

list_history = [x for x in message.workflow_history.get("message_workflow")]
list_history = [
x for x in message.workflow_history.get("message_workflow")
]
current = api.user.get_current()
entry = dict(
action="Invio",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,19 @@
style="width:100%;border:0;border-spacing:0;color:#000"
>
<span tal:replace="structure header"></span>
<tr>
<td align="left"
colspan="2"
>
<div class="newsletterTitle">
<h1>${title}</h1>
</div>
</td>
</tr>
<tr>
<td align="left"
colspan="2"
>
<p class="message_core">Per confermare la tua richiesta di iscrizione a Newsletter ${title}, &egrave; necessario collegarsi entro 48 ore al seguente link:
<br />
<a href="${activationUrl}">${activationUrl}</a>
<br />
Cordiali saluti
<br />
Redazione del portale ${portal_name}
</p>
<br />
<p>
Cordiali saluti
<br />
Redazione del portale ${portal_name}
</p>
</td>
</tr>
<span tal:replace="structure footer"></span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,6 @@
style="width:100%;border:0;border-spacing:0;color:#000"
>
<span tal:replace="structure header"></span>
<tr>
<td align="left"
colspan="2"
>
<div class="newsletterTitle">
<h1>${channel_name}</h1>
</div>
</td>
</tr>
<tr>
<td align="left"
colspan="2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<style tal:content="style"></style>
<br />
<p class="message_core">
L'invio del messaggio ${message_title}
L'invio del messaggio <b>${message_title}</b>
<tal:subscribers condition="subscribers">a ${subscribers} iscritti</tal:subscribers>
del canale ${channel_name} &egrave; andato a buon fine.
del canale <b>${channel_name}</b> &egrave; andato a buon fine.
</p>
<br />
<span tal:replace="structure footer"></span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@
style="width:100%;border:0;border-spacing:0;color:#000"
>
<span tal:replace="structure header"></span>
<tr>
<td align="left"
colspan="2"
>
<div class="newsletterTitle">
<h1>${title}</h1>
</div>
</td>
</tr>
<tr>
<td align="left"
colspan="2"
Expand Down
8 changes: 6 additions & 2 deletions src/rer/newsletter/queue/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def _sendNotification(self, status, channel, message):
"message_title": message.title,
}
mail_text = message_template(**parameters)
mail_text = portal.portal_transforms.convertTo("text/mail", mail_text)
mail_text = portal.portal_transforms.convertTo(
"text/mail", mail_text
)

# response_email = None
# if channel.response_email:
Expand Down Expand Up @@ -95,7 +97,9 @@ def __call__(self):

status = UNHANDLED
message = self._getMessage()
channel = getMultiAdapter((self._getChannel(), self.request), IChannelSender)
channel = getMultiAdapter(
(self._getChannel(), self.request), IChannelSender
)

unsubscribe_footer_template = message.restrictedTraverse(
"@@unsubscribe_channel_template"
Expand Down

0 comments on commit 50b0d72

Please sign in to comment.