8

Merge pull request #8 from LabD/feature/boolean-segment-status

Feature/boolean segment status
This commit is contained in:
Boris Besemer
2016-11-28 11:45:50 +01:00
committed by GitHub
2 changed files with 32 additions and 7 deletions

View File

@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.3 on 2016-11-21 10:48
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('personalisation', '0029_auto_20161118_1601'),
]
operations = [
migrations.AddField(
model_name='personalisablepage',
name='is_segmented',
field=models.BooleanField(default=False),
),
]

View File

@@ -210,7 +210,6 @@ pre_save.connect(check_status_change, sender=Segment)
class AdminPersonalisablePageForm(WagtailAdminPageForm):
def __init__(self, *args, **kwargs):
super(AdminPersonalisablePageForm, self).__init__(*args, **kwargs)
self.current_segment = Segment.objects.first() # TODO: Filter for the current segment
def save(self, commit=True):
page = super(AdminPersonalisablePageForm, self).save(commit=False)
@@ -225,14 +224,19 @@ class AdminPersonalisablePageForm(WagtailAdminPageForm):
'segment': segment,
'live': False,
'canonical_page': page,
'is_segmented': True,
}
# TODO: Implement logic to change segment when there's already one set instead of copying
new_page = page.copy(update_attrs=update_attrs, copy_revisions=False)
return new_page
page.save()
if page.is_segmented:
slug = "{}-{}".format(page.canonical_page.slug, segment.encoded_name())
title = "{} ({})".format(page.canonical_page.title, segment.name)
page.slug = slug
page.title = title
page.save()
return page
else:
new_page = page.copy(update_attrs=update_attrs, copy_revisions=False)
return new_page
return page
@@ -246,6 +250,7 @@ class PersonalisablePage(Page):
Segment, related_name='segments', on_delete=models.PROTECT,
blank=True, null=True
)
is_segmented = models.BooleanField(default=False)
variation_panels = [
MultiFieldPanel([