Refactored segment model. Implemented 'enable' and 'disable' in overview
This commit is contained in:
@ -4,6 +4,9 @@ from django.conf.urls import url
|
|||||||
|
|
||||||
from personalisation import views
|
from personalisation import views
|
||||||
|
|
||||||
|
app_name = 'segment'
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^segment/(\d+)/$', views.overview, name='overview'),
|
url(r'^segment/(\d+)/$', views.overview, name='overview'),
|
||||||
|
url(r'^segment/(?P<segment_id>[0-9]+)/enable/$', views.enable, name='enable'),
|
||||||
|
url(r'^segment/(?P<segment_id>[0-9]+)/disable/$', views.disable, name='disable'),
|
||||||
]
|
]
|
||||||
|
@ -8,7 +8,7 @@ class SegmentMiddleware(object):
|
|||||||
self.get_response = get_response
|
self.get_response = get_response
|
||||||
|
|
||||||
def __call__(self, request):
|
def __call__(self, request):
|
||||||
segments = Segment.objects.all().filter(status="live")
|
segments = Segment.objects.all().filter(status="enabled")
|
||||||
|
|
||||||
chosen_segments = []
|
chosen_segments = []
|
||||||
|
|
||||||
|
20
src/personalisation/migrations/0008_auto_20161108_1621.py
Normal file
20
src/personalisation/migrations/0008_auto_20161108_1621.py
Normal file
@ -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),
|
||||||
|
),
|
||||||
|
]
|
20
src/personalisation/migrations/0009_auto_20161108_1731.py
Normal file
20
src/personalisation/migrations/0009_auto_20161108_1731.py
Normal file
@ -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),
|
||||||
|
),
|
||||||
|
]
|
@ -19,13 +19,13 @@ class Segment(ClusterableModel):
|
|||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
STATUS_CHOICES = (
|
STATUS_CHOICES = (
|
||||||
('disabled', 'Disabled'),
|
('disabled', 'Disabled'),
|
||||||
('live', 'Live'),
|
('enabled', 'Enabled'),
|
||||||
('completed', 'Completed'),
|
|
||||||
)
|
)
|
||||||
status = models.CharField(max_length=20, choices=STATUS_CHOICES, default="disabled")
|
status = models.CharField(max_length=20, choices=STATUS_CHOICES, default="enabled")
|
||||||
|
|
||||||
panels = [
|
panels = [
|
||||||
FieldPanel('name'),
|
FieldPanel('name'),
|
||||||
|
FieldPanel('status'),
|
||||||
]
|
]
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -22,11 +22,18 @@
|
|||||||
<!-- Replace this function with a class specific one to avoid useless requests. -->
|
<!-- Replace this function with a class specific one to avoid useless requests. -->
|
||||||
{% for segment in object_list %}
|
{% for segment in object_list %}
|
||||||
<div class="block">
|
<div class="block">
|
||||||
<a href="edit/{{ segment.pk }}"><h2>{{ segment }}</h2></a>
|
<a href="inspect/{{ segment.pk }}"><h2>{{ segment }}</h2></a>
|
||||||
|
{% if user_can_create %}
|
||||||
<ul class="block_actions">
|
<ul class="block_actions">
|
||||||
<li><a href="delete/{{ segment.pk }}">delete</a></li>
|
{% if segment.status == "disabled" %}
|
||||||
|
<li><a href="{% url 'segment:enable' segment.pk %}">enable</a></li>
|
||||||
|
{% elif segment.status == "enabled" %}
|
||||||
|
<li><a href="{% url 'segment:disable' segment.pk %}">disable</a></li>
|
||||||
|
{% endif %}
|
||||||
<li><a href="edit/{{ segment.pk }}">configure this</a></li>
|
<li><a href="edit/{{ segment.pk }}">configure this</a></li>
|
||||||
|
<li><a href="delete/{{ segment.pk }}">delete</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
from __future__ import absolute_import, unicode_literals
|
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):
|
def overview(request):
|
||||||
return render(request, 'wagtailadmin/segment.html')
|
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', '/'))
|
@ -23,7 +23,8 @@ class SegmentModelAdmin(ModelAdmin):
|
|||||||
model = Segment
|
model = Segment
|
||||||
menu_icon = 'group'
|
menu_icon = 'group'
|
||||||
add_to_settings_menu = False
|
add_to_settings_menu = False
|
||||||
list_display = ('name')
|
list_display = ('status', 'name')
|
||||||
|
inspect_view_enabled = True
|
||||||
index_view_extra_css = ['personalisation/segment/index.css']
|
index_view_extra_css = ['personalisation/segment/index.css']
|
||||||
form_view_extra_css = ['personalisation/segment/form.css']
|
form_view_extra_css = ['personalisation/segment/form.css']
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user