Skip to content

Commit

Permalink
do customizations in mailer only for Prenotazione items
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk committed Jun 28, 2023
1 parent 952dd70 commit ecffa42
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/redturtle/prenotazioni/actions/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ def get_target_obj(self):
"""Get's the target object, i.e. the object that will provide the field
with the email address
"""
event_obj = self.event.object
if event_obj.portal_type != "Prenotazione":
return super().get_target_obj()
target = self.element.target
if target == "object":
obj = self.context
elif target == "parent":
obj = self.event.object.aq_parent
# NEEDED JUST FOR PRENOTAZIONI...
return obj
# this is the patch
return event_obj.aq_parent
elif target == "target":
obj = self.event.object
obj = event_obj
else:
raise ValueError(target)
return aq_base(aq_inner(obj))
Expand All @@ -43,6 +45,10 @@ def get_recipients(self):
"""
The recipients of this mail
"""

if self.event.object.portal_type != "Prenotazione":
return super().get_recipients()

# Try to load data from the target object
fieldName = str(self.element.fieldName)
obj = self.get_target_obj()
Expand All @@ -63,10 +69,13 @@ def get_recipients(self):
return list(filter(bool, recipients))

def manage_attachments(self, msg):
booking = self.event.object
action = getattr(self.event, "action", "")
if not (action == "confirm" or IMovedPrenotazione.providedBy(self.event)):
if (
not (action == "confirm" or IMovedPrenotazione.providedBy(self.event))
or booking.portal_type != "Prenotazione"
):
return
booking = self.event.object
cal = IICalendar(booking)
ical = cal.to_ical()
name = f"{booking.getId()}.ics"
Expand Down

0 comments on commit ecffa42

Please sign in to comment.