Skip to content

Commit

Permalink
Add logics
Browse files Browse the repository at this point in the history
  • Loading branch information
folix-01 committed May 21, 2024
1 parent ccf61d9 commit 70f0ed9
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ def notify_on_refuse_appio_message_default_factory(context):
)


@provider(IContextAwareDefaultFactory)
def notify_on_cancel_appio_subject_default_factory(context):
return api.portal.translate(
_(
"notify_on_cancel_appio_subject_default_value",
"[${prenotazioni_folder_title}] Booking canceled for ${title}",
)
)


@provider(IContextAwareDefaultFactory)
def notify_on_cancel_appio_message_default_factory(context):
return api.portal.translate(
_(
"notify_on_cancel_appio_message_default_value",
"The booking ${booking_type} of ${booking_date} at ${booking_time} was canceled.",
)
)


@provider(IContextAwareDefaultFactory)
def notify_as_reminder_appio_subject_default_factory(context):
return api.portal.translate(
Expand Down Expand Up @@ -223,6 +243,30 @@ class INotificationAppIO(model.Schema):
defaultFactory=notify_on_refuse_appio_message_default_factory,
required=False,
)
notify_on_cancel_appio_subject = schema.Text(
title=_(
"notify_on_cancel_subject",
default="[Cancel] subject",
),
description=_(
"notify_on_cancel_subject_help",
default="The message subject when a booking has been canceled.",
),
defaultFactory=notify_on_cancel_appio_subject_default_factory,
required=False,
)
notify_on_cancel_appio_message = schema.Text(
title=_(
"notify_on_cancel_message",
default="[Cancel] message",
),
description=_(
"notify_on_cancel_message_help",
default="The message text when a booking has been canceled.",
),
defaultFactory=notify_on_cancel_appio_message_default_factory,
required=False,
)
notify_as_reminder_appio_subject = schema.Text(
title=_(
"notify_as_reminder_subject",
Expand Down Expand Up @@ -268,6 +312,8 @@ class INotificationAppIO(model.Schema):
"notify_on_move_appio_message",
"notify_on_refuse_appio_subject",
"notify_on_refuse_appio_message",
"notify_on_cancel_appio_subject",
"notify_on_cancel_appio_message",
"notify_as_reminder_appio_subject",
"notify_as_reminder_appio_message",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def __init__(self, message_adapter, booking, request) -> None:
self.request = request

def send(self) -> bool:
import pdb

pdb.set_trace()
from .. import write_message_to_object_history

supervisor = getUtility(IBookingNotificatorSupervisorUtility)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ def notify_on_refuse_message_default_factory(context):
)


@provider(IContextAwareDefaultFactory)
def notify_on_cancel_subject_default_factory(context):
return api.portal.translate(
_(
"notify_on_cancel_subject_default_value",
"[${prenotazioni_folder_title}] Booking canceled for ${title}",
)
)


@provider(IContextAwareDefaultFactory)
def notify_on_cancel_message_default_factory(context):
return api.portal.translate(
_(
"notify_on_cancel_message_default_value",
"The booking ${booking_type} of ${booking_date} at ${booking_time} was canceled.",
)
)


@provider(IContextAwareDefaultFactory)
def notify_as_reminder_subject_default_factory(context):
return api.portal.translate(
Expand Down Expand Up @@ -232,6 +252,30 @@ class INotificationEmail(model.Schema):
defaultFactory=notify_on_refuse_message_default_factory,
required=False,
)
notify_on_cancel_subject = schema.TextLine(
title=_(
"notify_on_cancel_subject",
default="[Cancel] subject",
),
description=_(
"notify_on_cancel_subject_help",
default="The message subject when a booking has been canceled.",
),
defaultFactory=notify_on_cancel_subject_default_factory,
required=False,
)
notify_on_cancel_message = schema.Text(
title=_(
"notify_on_cancel_message",
default="[Cancel] message",
),
description=_(
"notify_on_cancel_message_help",
default="The message text when a booking has been canceled.",
),
defaultFactory=notify_on_cancel_message_default_factory,
required=False,
)
notify_as_reminder_subject = schema.TextLine(
title=_(
"notify_as_reminder_subject",
Expand Down Expand Up @@ -278,6 +322,8 @@ class INotificationEmail(model.Schema):
"notify_on_move_message",
"notify_on_refuse_subject",
"notify_on_refuse_message",
"notify_on_cancel_subject",
"notify_on_cancel_message",
"notify_as_reminder_subject",
"notify_as_reminder_message",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def send(self, force=False):
If True, the message will be sent even if the email is not allowed
(ie. for operator notifications)
"""
import pdb

pdb.set_trace()
message = self.message_adapter.message

if force or getUtility(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@
redturtle.prenotazioni.interfaces.IBookingReminderEvent"
handler=".events.send_booking_reminder"
/>
<subscriber
for="redturtle.prenotazioni.content.prenotazione.IPrenotazione
zope.lifecycleevent.IObjectRemovedEvent"
handler=".events.send_booking_removed"
/>
<subscriber
for="redturtle.prenotazioni.content.prenotazione.IPrenotazione
Products.DCWorkflow.interfaces.IAfterTransitionEvent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ def notify_on_refuse_sms_message_default_factory(context):
)


@provider(IContextAwareDefaultFactory)
def notify_on_cancel_sms_message_default_factory(context):
return api.portal.translate(
_(
"notify_on_cancel_sms_message_default_value",
"[${prenotazioni_folder_title}]: The booking ${booking_type} of ${booking_date} at ${booking_time} was canceled.",
)
)


@provider(IContextAwareDefaultFactory)
def notify_as_reminder_sms_message_default_factory(context):
return api.portal.translate(
Expand Down Expand Up @@ -122,6 +132,18 @@ class INotificationSMS(model.Schema):
defaultFactory=notify_on_refuse_sms_message_default_factory,
required=False,
)
notify_on_cancel_sms_message = schema.Text(
title=_(
"notify_on_cancel_message",
default="[Cancel] message",
),
description=_(
"notify_on_cancel_message_help",
default="The message text when a booking has been canceled.",
),
defaultFactory=notify_on_cancel_sms_message_default_factory,
required=False,
)
notify_as_reminder_sms_message = schema.Text(
title=_(
"notify_as_reminder_message",
Expand Down Expand Up @@ -151,6 +173,7 @@ class INotificationSMS(model.Schema):
"notify_on_confirm_sms_message",
"notify_on_move_sms_message",
"notify_on_refuse_sms_message",
"notify_on_cancel_sms_message",
"notify_as_reminder_sms_message",
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ def __init__(self, message_adapter, booking, request) -> None:
self.request = request

def send(self):
import pdb

pdb.set_trace()
if self.is_notification_allowed():
# dont foget to write the history log about sending
# self.write_message_to_booking_history(self.booking, self.message_adapter.message_history)
Expand Down
12 changes: 11 additions & 1 deletion src/redturtle/prenotazioni/content/prenotazioni_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,15 @@ def data_validation(data):
default=False,
required=False,
)
notify_on_cancel = schema.Bool(
title=_("notify_on_cancel", default="Notify when canceled."),
description=_(
"notify_on_cancel_help",
default="Notify via mail the user when his booking has been canceled.",
),
default=False,
required=False,
)
max_bookings_allowed = schema.Int(
title=_(
"max_bookings_allowed_label",
Expand Down Expand Up @@ -540,6 +549,7 @@ def data_validation(data):
"notify_on_confirm",
"notify_on_move",
"notify_on_refuse",
"notify_on_cancel",
],
)

Expand Down Expand Up @@ -582,7 +592,7 @@ def get_booking_types(self) -> Generator[PrenotazioneType, None, None]:
def get_notification_flags(self):
return {
action: getattr(self, f"notify_on_{action}", False)
for action in ("confirm", "submit", "refuse")
for action in ("confirm", "submit", "refuse", "cancel")
}

# BBB: compatibility with old code (booking_types was a List of IBookingTypeRow)
Expand Down

0 comments on commit 70f0ed9

Please sign in to comment.