agendas: notify_checked, loop on booking checks instead of bookings (#82842)

This commit is contained in:
Lauréline Guérin 2023-10-26 10:56:25 +02:00 committed by Lauréline Guérin
parent 737ba6f0bb
commit cff4ce0861
1 changed files with 13 additions and 11 deletions

View File

@ -2182,28 +2182,30 @@ class Event(models.Model):
self.notify_checked()
def notify_checked(self):
for booking in self.booking_set.filter(user_checks__isnull=False).prefetch_related('user_checks'):
if booking.user_check.presence is True and booking.presence_callback_url:
url = booking.presence_callback_url
elif booking.user_check.presence is False and booking.absence_callback_url:
url = booking.absence_callback_url
for user_check in BookingCheck.objects.filter(booking__event=self).select_related('booking'):
if user_check.presence is True and user_check.booking.presence_callback_url:
url = user_check.booking.presence_callback_url
elif user_check.presence is False and user_check.booking.absence_callback_url:
url = user_check.booking.absence_callback_url
else:
continue
payload = {
'user_was_present': booking.user_check.presence,
'user_check_type_slug': booking.user_check.type_slug,
'user_check_type_label': booking.user_check.type_label,
'user_was_present': user_check.presence,
'user_check_type_slug': user_check.type_slug,
'user_check_type_label': user_check.type_label,
}
try:
response = requests_wrapper.post(url, json=payload, remote_service='auto', timeout=15)
if response and not response.ok:
logging.error(
'error (HTTP %s) notifying checked booking (%s)', response.status_code, booking.id
'error (HTTP %s) notifying checked booking (%s)',
response.status_code,
user_check.booking_id,
)
except requests.Timeout:
logging.error('error (timeout) notifying checked booking (%s)', booking.id)
logging.error('error (timeout) notifying checked booking (%s)', user_check.booking_id)
except Exception as e: # noqa pylint: disable=broad-except
logging.error('error (%s) notifying checked booking (%s)', e, booking.id)
logging.error('error (%s) notifying checked booking (%s)', e, user_check.booking_id)
def async_refresh_booking_computed_times(self):
if self.agenda.kind != 'events' or not self.agenda.partial_bookings: