diff --git a/sandbox/exampledata/personalisation.json b/sandbox/exampledata/personalisation.json index 93205e5..8565ddc 100644 --- a/sandbox/exampledata/personalisation.json +++ b/sandbox/exampledata/personalisation.json @@ -25,7 +25,7 @@ "enable_date": "2017-06-02T10:58:39.389Z", "disable_date": "2017-06-02T10:34:51.722Z", "visit_count": 0, - "status": "enabled", + "enabled": true, "persistent": false, "match_any": false } @@ -39,7 +39,7 @@ "enable_date": "2017-06-02T10:57:44.497Z", "disable_date": "2017-06-02T10:57:39.984Z", "visit_count": 1, - "status": "enabled", + "enabled": true, "persistent": false, "match_any": false } diff --git a/src/wagtail_personalisation/migrations/0013_auto_20170609_1321.py b/src/wagtail_personalisation/migrations/0013_auto_20170609_1321.py new file mode 100644 index 0000000..8377d02 --- /dev/null +++ b/src/wagtail_personalisation/migrations/0013_auto_20170609_1321.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.2 on 2017-06-09 13:21 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('wagtail_personalisation', '0012_remove_personalisablepagemetadata_is_segmented'), + ] + + operations = [ + migrations.RemoveField( + model_name='segment', + name='status', + ), + migrations.AddField( + model_name='segment', + name='enabled', + field=models.BooleanField(default=True, help_text='Should the segment be active?'), + ), + ] diff --git a/src/wagtail_personalisation/models.py b/src/wagtail_personalisation/models.py index ec0c83f..3fce625 100644 --- a/src/wagtail_personalisation/models.py +++ b/src/wagtail_personalisation/models.py @@ -22,20 +22,12 @@ from .forms import SegmentAdminForm class SegmentQuerySet(models.QuerySet): def enabled(self): - return self.filter(status=self.model.STATUS_ENABLED) + return self.filter(enabled=True) @python_2_unicode_compatible class Segment(ClusterableModel): """The segment model.""" - STATUS_ENABLED = 'enabled' - STATUS_DISABLED = 'disabled' - - STATUS_CHOICES = ( - (STATUS_ENABLED, _('Enabled')), - (STATUS_DISABLED, _('Disabled')), - ) - TYPE_DYNAMIC = 'dynamic' TYPE_STATIC = 'static' @@ -50,8 +42,8 @@ class Segment(ClusterableModel): enable_date = models.DateTimeField(null=True, editable=False) disable_date = models.DateTimeField(null=True, editable=False) visit_count = models.PositiveIntegerField(default=0, editable=False) - status = models.CharField( - max_length=20, choices=STATUS_CHOICES, default=STATUS_ENABLED) + enabled = models.BooleanField( + default=True, help_text=_("Should the segment be active?")) persistent = models.BooleanField( default=False, help_text=_("Should the segment persist between visits?")) match_any = models.BooleanField( @@ -111,7 +103,7 @@ class Segment(ClusterableModel): MultiFieldPanel([ FieldPanel('name', classname="title"), FieldRowPanel([ - FieldPanel('status'), + FieldPanel('enabled'), FieldPanel('persistent'), ]), FieldPanel('match_any'), @@ -178,9 +170,9 @@ class Segment(ClusterableModel): return segment_rules def toggle(self, save=True): - self.status = ( - self.STATUS_ENABLED if self.status == self.STATUS_DISABLED - else self.STATUS_DISABLED) + self.enabled = ( + True if self.enabled == False + else False) if save: self.save() diff --git a/src/wagtail_personalisation/receivers.py b/src/wagtail_personalisation/receivers.py index 722f09d..e5c7fad 100644 --- a/src/wagtail_personalisation/receivers.py +++ b/src/wagtail_personalisation/receivers.py @@ -7,16 +7,16 @@ 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 + original_status = sender.objects.get(pk=instance.id).enabled except sender.DoesNotExist: - original_status = "" + original_status = None - if original_status != instance.status: - if instance.status == instance.STATUS_ENABLED: + if original_status != instance.enabled: + if instance.enabled == True: instance.enable_date = timezone.now() instance.visit_count = 0 return instance - if instance.status == instance.STATUS_DISABLED: + if instance.enabled == False: instance.disable_date = timezone.now() diff --git a/src/wagtail_personalisation/templates/modeladmin/wagtail_personalisation/segment/dashboard.html b/src/wagtail_personalisation/templates/modeladmin/wagtail_personalisation/segment/dashboard.html index 0e24ba1..547e14b 100644 --- a/src/wagtail_personalisation/templates/modeladmin/wagtail_personalisation/segment/dashboard.html +++ b/src/wagtail_personalisation/templates/modeladmin/wagtail_personalisation/segment/dashboard.html @@ -22,7 +22,7 @@