diff --git a/src/personalisation/admin_urls.py b/src/personalisation/admin_urls.py index ccf42b8..49ac124 100644 --- a/src/personalisation/admin_urls.py +++ b/src/personalisation/admin_urls.py @@ -4,6 +4,9 @@ from django.conf.urls import url from personalisation import views +app_name = 'segment' urlpatterns = [ url(r'^segment/(\d+)/$', views.overview, name='overview'), + url(r'^segment/(?P[0-9]+)/enable/$', views.enable, name='enable'), + url(r'^segment/(?P[0-9]+)/disable/$', views.disable, name='disable'), ] diff --git a/src/personalisation/middleware.py b/src/personalisation/middleware.py index 7604755..69ac0d4 100644 --- a/src/personalisation/middleware.py +++ b/src/personalisation/middleware.py @@ -8,7 +8,7 @@ class SegmentMiddleware(object): self.get_response = get_response def __call__(self, request): - segments = Segment.objects.all().filter(status="live") + segments = Segment.objects.all().filter(status="enabled") chosen_segments = [] diff --git a/src/personalisation/migrations/0008_auto_20161108_1621.py b/src/personalisation/migrations/0008_auto_20161108_1621.py new file mode 100644 index 0000000..6d5376c --- /dev/null +++ b/src/personalisation/migrations/0008_auto_20161108_1621.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2016-11-08 15:21 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('personalisation', '0007_auto_20161108_1610'), + ] + + operations = [ + migrations.AlterField( + model_name='segment', + name='status', + field=models.CharField(choices=[('disabled', 'Disabled'), ('enabled', 'Enabled')], default='disabled', max_length=20), + ), + ] diff --git a/src/personalisation/migrations/0009_auto_20161108_1731.py b/src/personalisation/migrations/0009_auto_20161108_1731.py new file mode 100644 index 0000000..b641a30 --- /dev/null +++ b/src/personalisation/migrations/0009_auto_20161108_1731.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2016-11-08 16:31 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('personalisation', '0008_auto_20161108_1621'), + ] + + operations = [ + migrations.AlterField( + model_name='segment', + name='status', + field=models.CharField(choices=[('disabled', 'Disabled'), ('enabled', 'Enabled')], default='enabled', max_length=20), + ), + ] diff --git a/src/personalisation/models.py b/src/personalisation/models.py index a5e82e0..522198f 100644 --- a/src/personalisation/models.py +++ b/src/personalisation/models.py @@ -19,13 +19,13 @@ class Segment(ClusterableModel): name = models.CharField(max_length=255) STATUS_CHOICES = ( ('disabled', 'Disabled'), - ('live', 'Live'), - ('completed', 'Completed'), + ('enabled', 'Enabled'), ) - status = models.CharField(max_length=20, choices=STATUS_CHOICES, default="disabled") + status = models.CharField(max_length=20, choices=STATUS_CHOICES, default="enabled") panels = [ FieldPanel('name'), + FieldPanel('status'), ] def __str__(self): diff --git a/src/personalisation/templates/modeladmin/personalisation/segment/index.html b/src/personalisation/templates/modeladmin/personalisation/segment/index.html index 572d504..27ce261 100644 --- a/src/personalisation/templates/modeladmin/personalisation/segment/index.html +++ b/src/personalisation/templates/modeladmin/personalisation/segment/index.html @@ -22,11 +22,18 @@ {% for segment in object_list %}
-

{{ segment }}

+

{{ segment }}

+ {% if user_can_create %} + {% endif %}
{% endfor %} {% endif %} diff --git a/src/personalisation/views.py b/src/personalisation/views.py index db8e3a3..a61dd7c 100644 --- a/src/personalisation/views.py +++ b/src/personalisation/views.py @@ -1,6 +1,10 @@ from __future__ import absolute_import, unicode_literals -from django.shortcuts import render +from django.shortcuts import get_object_or_404, render +from django.http import HttpResponseRedirect, HttpResponse +from django.urls import reverse + +from personalisation.models import Segment """ @@ -8,3 +12,17 @@ Segments overview """ def overview(request): return render(request, 'wagtailadmin/segment.html') + +def enable(request, segment_id): + segment = get_object_or_404(Segment, pk=segment_id) + segment.status = 'enabled' + segment.save() + + return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/')) + +def disable(request, segment_id): + segment = get_object_or_404(Segment, pk=segment_id) + segment.status = 'disabled' + segment.save() + + return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/')) \ No newline at end of file diff --git a/src/personalisation/wagtail_hooks.py b/src/personalisation/wagtail_hooks.py index ceb064d..32c7e8f 100644 --- a/src/personalisation/wagtail_hooks.py +++ b/src/personalisation/wagtail_hooks.py @@ -23,7 +23,8 @@ class SegmentModelAdmin(ModelAdmin): model = Segment menu_icon = 'group' add_to_settings_menu = False - list_display = ('name') + list_display = ('status', 'name') + inspect_view_enabled = True index_view_extra_css = ['personalisation/segment/index.css'] form_view_extra_css = ['personalisation/segment/form.css']