Skip to content
Snippets Groups Projects
Verified Commit e47608f5 authored by Andreas Ellewsen's avatar Andreas Ellewsen
Browse files

Reduce notification amount for roles

If other fields than one of the date fields was changed, an extra task
would be created, causing duplicate notification on the date. We now
check that the field has changed before making a task.
parent 2db65f96
No related branches found
No related tags found
1 merge request!137Greg 65 notification on start
Pipeline #99958 passed
......@@ -129,19 +129,23 @@ def save_notification_callback(sender, instance, created, *args, **kwargs):
return
# Queue future notifications on start and end date for roles
if isinstance(instance, Role):
if instance.start_date:
if (
"start_date" in instance._changed_fields # pylint: disable=protected-access
and instance.start_date
):
Schedule.objects.create(
func="greg.signals._queue_role_start_notification",
args=f"{instance.id},True",
next_run=date_to_datetime_midnight(instance.start_date),
schedule_type=Schedule.ONCE,
)
Schedule.objects.create(
func="greg.signals._queue_role_end_notification",
args=f"{instance.id},True",
next_run=date_to_datetime_midnight(instance.end_date),
schedule_type=Schedule.ONCE,
)
if "end_date" in instance._changed_fields: # pylint: disable=protected-access
Schedule.objects.create(
func="greg.signals._queue_role_end_notification",
args=f"{instance.id},True",
next_run=date_to_datetime_midnight(instance.end_date),
schedule_type=Schedule.ONCE,
)
meta = _create_metadata(instance)
operation = "add" if created else "update"
_store_notification(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment