Puts the receivers in a seperate file and adds appconfig
This commit is contained in:
committed by
Michael van Tellingen
parent
9a7d41284e
commit
55da67523f
24
src/wagtail_personalisation/receivers.py
Normal file
24
src/wagtail_personalisation/receivers.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from django.db.models.signals import pre_save
|
||||
from django.utils import timezone
|
||||
|
||||
from wagtail_personalisation.models import Segment
|
||||
|
||||
|
||||
def check_status_change(sender, instance, *args, **kwargs):
|
||||
"""Check if the status has changed. Alter dates accordingly."""
|
||||
try:
|
||||
original_status = sender.objects.get(pk=instance.id).status
|
||||
except sender.DoesNotExist:
|
||||
original_status = ""
|
||||
|
||||
if original_status != instance.status:
|
||||
if instance.status == "enabled":
|
||||
instance.enable_date = timezone.now()
|
||||
instance.visit_count = 0
|
||||
return instance
|
||||
if instance.status == "disabled":
|
||||
instance.disable_date = timezone.now()
|
||||
|
||||
|
||||
def register():
|
||||
pre_save.connect(check_status_change, sender=Segment)
|
Reference in New Issue
Block a user