Puts the receivers in a seperate file and adds appconfig
This commit is contained in:
committed by
Michael van Tellingen
parent
9a7d41284e
commit
55da67523f
@ -0,0 +1 @@
|
||||
default_app_config = 'wagtail_personalisation.config.WagtailPersonalisationConfig'
|
||||
|
13
src/wagtail_personalisation/config.py
Normal file
13
src/wagtail_personalisation/config.py
Normal file
@ -0,0 +1,13 @@
|
||||
from django.apps import AppConfig
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
class WagtailPersonalisationConfig(AppConfig):
|
||||
label = 'wagtail_personalisation'
|
||||
name = 'wagtail_personalisation'
|
||||
verbose_name = _('Wagtail Personalisation')
|
||||
|
||||
def ready(self):
|
||||
from wagtail_personalisation import receivers
|
||||
|
||||
receivers.register()
|
@ -1,9 +1,7 @@
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.db import models
|
||||
from django.db.models.signals import pre_save
|
||||
from django.template.defaultfilters import slugify
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
@ -76,25 +74,6 @@ class Segment(ClusterableModel):
|
||||
return segment_rules
|
||||
|
||||
|
||||
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()
|
||||
|
||||
|
||||
pre_save.connect(check_status_change, sender=Segment)
|
||||
|
||||
|
||||
class PersonalisablePage(Page):
|
||||
"""The personalisable page model. Allows creation of variants with linked
|
||||
segments.
|
||||
|
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