diff options
author | Stephen Finucane <stephen@that.guru> | 2018-10-29 15:15:18 +0000 |
---|---|---|
committer | Stephen Finucane <stephen@that.guru> | 2018-12-22 17:00:34 +0000 |
commit | 087fe500f8d2e7bdad15f2257d7f78a2337cf702 (patch) | |
tree | 398a2ee2ad224cff1cb16b240013bf0ef70eaed0 /patchwork/signals.py | |
parent | 1b9869d814e35c89fdbe904a55d9d0dd512ac333 (diff) | |
download | patchwork-087fe500f8d2e7bdad15f2257d7f78a2337cf702.tar patchwork-087fe500f8d2e7bdad15f2257d7f78a2337cf702.tar.gz |
signals: Fix 'series-completed' event
I'm not sure how I ever intended this to work and there were no tests
verifying things. Fix it now and add tests to prevent it regressing.
Signed-off-by: Stephen Finucane <stephen@that.guru>
Fixes: 76505e91 ("models: Convert Series-Patch relationship to 1:N")
Diffstat (limited to 'patchwork/signals.py')
-rw-r--r-- | patchwork/signals.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/patchwork/signals.py b/patchwork/signals.py index 536b177..666199b 100644 --- a/patchwork/signals.py +++ b/patchwork/signals.py @@ -210,8 +210,8 @@ def create_series_created_event(sender, instance, created, raw, **kwargs): create_event(instance) -@receiver(post_save, sender=Patch) -def create_series_completed_event(sender, instance, created, raw, **kwargs): +@receiver(pre_save, sender=Patch) +def create_series_completed_event(sender, instance, raw, **kwargs): # NOTE(stephenfin): It's actually possible for this event to be fired # multiple times for a given series. To trigger this case, you would need @@ -225,9 +225,20 @@ def create_series_completed_event(sender, instance, created, raw, **kwargs): project=series.project, series=series) - # don't trigger for items loaded from fixtures or existing items - if raw or not created: + # don't trigger for items loaded from fixtures, new items or items that + # (still) don't have a series + if raw or not instance.pk or not instance.series: + return + + orig_patch = Patch.objects.get(pk=instance.pk) + + # we don't currently allow users to change a series (though this might + # change in the future) meaning if the patch already had a series, there's + # nothing to notify about + if orig_patch.series: return - if instance.series and instance.series.received_all: + # we can't use "series.received_all" here since we haven't actually saved + # the instance yet so we duplicate that logic here but with an offset + if (instance.series.received_total + 1) >= instance.series.total: create_event(instance.series) |