Skip to content

Commit

Permalink
blacked
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk committed Apr 24, 2024
1 parent 46a384f commit 49a526d
Show file tree
Hide file tree
Showing 24 changed files with 58 additions and 176 deletions.
24 changes: 6 additions & 18 deletions src/rer/newsletter/adapter/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,10 @@ def _getDate(self):
def _getMessage(self, message, footer):
logger.debug("getMessage %s %s", self.context.title, message.title)
content = IShippable(message).message_content
message_template = self.context.restrictedTraverse(
"@@messagepreview_view"
)
message_template = self.context.restrictedTraverse("@@messagepreview_view")
parameters = {
"css": self.context.css_style,
"message_header": self.context.header
if self.context.header
else "",
"message_header": self.context.header if self.context.header else "",
"message_subheader": f"""
<tr>
<td align="left" colspan="2">
Expand All @@ -90,9 +86,7 @@ def _getMessage(self, message, footer):
</div>
</td>
</tr>""",
"message_footer": self.context.footer
if self.context.footer
else "",
"message_footer": self.context.footer if self.context.footer else "",
"message_content": f"""
<tr>
<td align="left" colspan="2">
Expand Down Expand Up @@ -142,9 +136,7 @@ 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
Expand All @@ -169,9 +161,7 @@ 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 @@ -217,9 +207,7 @@ 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
16 changes: 4 additions & 12 deletions src/rer/newsletter/adapter/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ def channel_subscriptions(self):

@property
def active_subscriptions(self):
return len(
[x for x in self.channel_subscriptions.values() if x["is_active"]]
)
return len([x for x in self.channel_subscriptions.values() if x["is_active"]])

def subscribe(self, mail):
subscriptions = self.channel_subscriptions
Expand All @@ -93,9 +91,7 @@ def subscribe(self, mail):
"email": mail,
"is_active": False,
"token": uuid_activation,
"creation_date": datetime.today().strftime(
"%d/%m/%Y %H:%M:%S"
),
"creation_date": datetime.today().strftime("%d/%m/%Y %H:%M:%S"),
}

transaction.commit()
Expand Down Expand Up @@ -187,9 +183,7 @@ def addUser(self, mail):
"email": mail,
"is_active": True,
"token": six.text_type(uuid.uuid4()),
"creation_date": datetime.today().strftime(
"%d/%m/%Y %H:%M:%S"
),
"creation_date": datetime.today().strftime("%d/%m/%Y %H:%M:%S"),
}

transaction.commit()
Expand Down Expand Up @@ -242,9 +236,7 @@ def importUsersList(self, usersList):
"email": user,
"is_active": True,
"token": six.text_type(uuid.uuid4()),
"creation_date": datetime.today().strftime(
"%d/%m/%Y %H:%M:%S"
),
"creation_date": datetime.today().strftime("%d/%m/%Y %H:%M:%S"),
}
else:
logger.info("INVALID_EMAIL: %s", user)
Expand Down
4 changes: 1 addition & 3 deletions src/rer/newsletter/browser/channel/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ def handleAdd(self, action):
)
)
status = "Problems...{status}".format(status=status)
api.portal.show_message(
message=status, request=self.request, type="error"
)
api.portal.show_message(message=status, request=self.request, type="error")


class AddView(add.DefaultAddView):
Expand Down
4 changes: 1 addition & 3 deletions src/rer/newsletter/browser/channel/channelhistory.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ def deleteMessageFromHistory(self):
message_history = self.request.get("message_history")

# recupero tutti i messaggi del canale
messages = api.content.find(
context=self.context, portal_type="Message"
)
messages = api.content.find(context=self.context, portal_type="Message")
for message in messages:
annotations = IAnnotations(self.context)
if KEY in list(annotations.keys()):
Expand Down
4 changes: 1 addition & 3 deletions src/rer/newsletter/browser/channel/channelview.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ def getState(self, message):

def getMessageList(self):
if self.context.portal_type == "Channel":
brainsList = api.content.find(
context=self.context, portal_type="Message"
)
brainsList = api.content.find(context=self.context, portal_type="Message")

messageList = []
for brain in brainsList:
Expand Down
12 changes: 3 additions & 9 deletions src/rer/newsletter/browser/channel/deleteexpiredusers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ def update_annotations(self, brain):
None,
)

adapter = getMultiAdapter(
(channel, self.request), IChannelSubscriptions
)
adapter = getMultiAdapter((channel, self.request), IChannelSubscriptions)
keys = [x for x in adapter.channel_subscriptions.keys()]
for key in keys:
subscription = adapter.channel_subscriptions[key]
Expand All @@ -49,14 +47,10 @@ def __call__(self):
logger.info("START:Remove expired user from channels")

pc = getToolByName(self.context, "portal_catalog") # noqa
channels_brain = pc.unrestrictedSearchResults(
{"portal_type": "Channel"}
)
channels_brain = pc.unrestrictedSearchResults({"portal_type": "Channel"})

list(map(lambda x: self.update_annotations(x), channels_brain))
logger.info(
"DONE:Remove {0} expired user from channels".format(
self.user_removed
)
"DONE:Remove {0} expired user from channels".format(self.user_removed)
)
return True
12 changes: 3 additions & 9 deletions src/rer/newsletter/browser/channel/manageusers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ def deleteUser(self):

email = self.request["email"]

channel = getMultiAdapter(
(self.context, self.request), IChannelSubscriptions
)
channel = getMultiAdapter((self.context, self.request), IChannelSubscriptions)
status = channel.deleteUser(email)

response = {}
Expand All @@ -59,9 +57,7 @@ def exportUsersListAsFile(self):
status = UNHANDLED
channel = self.context.id_channel

channel = getMultiAdapter(
(self.context, self.request), IChannelSubscriptions
)
channel = getMultiAdapter((self.context, self.request), IChannelSubscriptions)
userList, status = channel.exportUsersList()

if status == OK:
Expand Down Expand Up @@ -97,9 +93,7 @@ def exportUsersListAsJson(self):
status = UNHANDLED
channel = self.context.id_channel

channel = getMultiAdapter(
(self.context, self.request), IChannelSubscriptions
)
channel = getMultiAdapter((self.context, self.request), IChannelSubscriptions)
userList, status = channel.exportUsersList()

if status == OK:
Expand Down
8 changes: 2 additions & 6 deletions src/rer/newsletter/browser/channel/subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ def handleSave(self, action):
url += "&_authenticator=" + token
url += "&action=subscribe"

mail_template = self.context.restrictedTraverse(
"@@activeuser_template"
)
mail_template = self.context.restrictedTraverse("@@activeuser_template")

parameters = {
"title": self.context.title,
Expand All @@ -102,9 +100,7 @@ def handleSave(self, action):
mail_text = mail_template(**parameters)

portal = api.portal.get()
mail_text = portal.portal_transforms.convertTo(
"text/mail", mail_text
)
mail_text = portal.portal_transforms.convertTo("text/mail", mail_text)
sender = compose_sender(channel=self.context)

channel_title = self.context.title
Expand Down
12 changes: 3 additions & 9 deletions src/rer/newsletter/browser/channel/unsubscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ def handleSave(self, action):

email = data.get("email", None)

channel = getMultiAdapter(
(self.context, self.request), IChannelSubscriptions
)
channel = getMultiAdapter((self.context, self.request), IChannelSubscriptions)

status, secret = channel.unsubscribe(email)

Expand All @@ -79,9 +77,7 @@ def handleSave(self, action):
"unsubscribe_generic",
default="Unable to perform unsubscription. Please contact site administrators.", # noqa
)
api.portal.show_message(
message=msg, request=self.request, type="error"
)
api.portal.show_message(message=msg, request=self.request, type="error")
return

# creo il token CSRF
Expand All @@ -93,9 +89,7 @@ def handleSave(self, action):
url += "&_authenticator=" + token
url += "&action=unsubscribe"

mail_template = self.context.restrictedTraverse(
"@@deleteuser_template"
)
mail_template = self.context.restrictedTraverse("@@deleteuser_template")

parameters = {
"header": self.context.header,
Expand Down
8 changes: 2 additions & 6 deletions src/rer/newsletter/browser/channel/users/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,12 @@ def handleSave(self, action):
channel = self.context.id_channel
mail = data["email"]

channel = getMultiAdapter(
(self.context, self.request), IChannelSubscriptions
)
channel = getMultiAdapter((self.context, self.request), IChannelSubscriptions)
status = channel.addUser(mail)

if status == SUBSCRIBED:
status = _("generic_add_message_success", default="User Added.")
api.portal.show_message(
message=status, request=self.request, type="info"
)
api.portal.show_message(message=status, request=self.request, type="info")
else:
logger.exception("unhandled error add user")
api.portal.show_message(
Expand Down
12 changes: 3 additions & 9 deletions src/rer/newsletter/browser/channel/users/confirm_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def render(self):
return self.index()

def _sendGenericMessage(self, template, receiver, message, message_title):
mail_template = self.context.restrictedTraverse(
"@@{0}".format(template)
)
mail_template = self.context.restrictedTraverse("@@{0}".format(template))

parameters = {
"header": self.context.header,
Expand Down Expand Up @@ -59,9 +57,7 @@ def __call__(self):
action = self.request.get("action")

response = None
channel = getMultiAdapter(
(self.context, self.request), IChannelSubscriptions
)
channel = getMultiAdapter((self.context, self.request), IChannelSubscriptions)

if action == "subscribe":
response, user = channel.activateUser(secret=secret)
Expand Down Expand Up @@ -92,9 +88,7 @@ def __call__(self):
)

if response == OK:
api.portal.show_message(
message=status, request=self.request, type="info"
)
api.portal.show_message(message=status, request=self.request, type="info")
else:
logger.error(
'Unable to unsubscribe user with token "{token}" on channel {channel}.'.format( # noqa
Expand Down
20 changes: 5 additions & 15 deletions src/rer/newsletter/browser/channel/users/usersimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ class IUsersImport(Interface):
# se questo e ceccato allora i dati non vengono inseriti
emptyList = schema.Bool(
title=_("title_empty_list", default="Empties users list"),
description=_(
"description_empty_list", default="Empties channel users list"
),
description=_("description_empty_list", default="Empties channel users list"),
required=False,
)

Expand Down Expand Up @@ -74,9 +72,7 @@ class IUsersImport(Interface):

separator = schema.TextLine(
title=_("title_separator", default="CSV separator"),
description=_(
"description_separator", default=_("Separator of CSV file")
),
description=_("description_separator", default=_("Separator of CSV file")),
default=",",
required=True,
constraint=check_separator,
Expand Down Expand Up @@ -151,9 +147,7 @@ def handleSave(self, action):
self.status = self.formErrorsMessage
return

channel = getMultiAdapter(
(self.context, self.request), IChannelSubscriptions
)
channel = getMultiAdapter((self.context, self.request), IChannelSubscriptions)

# devo svuotare la lista di utenti del channel
if data["emptyList"]:
Expand All @@ -162,9 +156,7 @@ def handleSave(self, action):
csv_file = data["userListFile"].data
# esporto la lista di utenti dal file
try:
usersList = self.processCSV(
csv_file, data["headerLine"], data["separator"]
)
usersList = self.processCSV(csv_file, data["headerLine"], data["separator"])
except IndexError:
api.portal.show_message(
message=_(
Expand Down Expand Up @@ -194,6 +186,4 @@ def handleSave(self, action):
"generic_subscribe_message_success",
default="User Subscribed",
)
api.portal.show_message(
message=status, request=self.request, type="info"
)
api.portal.show_message(message=status, request=self.request, type="info")
12 changes: 3 additions & 9 deletions src/rer/newsletter/browser/message/sendingtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ def _getDate(self):

def _getMessage(self, channel, message, footer):
content = IShippable(message).message_content
message_template = self.context.restrictedTraverse(
"@@messagepreview_view"
)
message_template = self.context.restrictedTraverse("@@messagepreview_view")
parameters = {
"css": channel.css_style,
"message_header": channel.header if channel.header else "",
Expand Down Expand Up @@ -114,15 +112,11 @@ def handleSave(self, action):
"enabled": ns_obj.standard_unsubscribe,
}
unsubscribe_footer_text = unsubscribe_footer_template(**parameters)
body = self._getMessage(
ns_obj, message_obj, unsubscribe_footer_text
)
body = self._getMessage(ns_obj, message_obj, unsubscribe_footer_text)

sender = compose_sender(channel=ns_obj)

nl_subject = (
" - " + ns_obj.subject_email if ns_obj.subject_email else ""
)
nl_subject = " - " + ns_obj.subject_email if ns_obj.subject_email else ""

subject = "Messaggio di prova - " + message_obj.title + nl_subject
# per mandare la mail non passo per l'utility
Expand Down
Loading

0 comments on commit 49a526d

Please sign in to comment.