7

remove all references or uses of old PersonalisablePage model

This commit is contained in:
Paul J Stevens
2017-05-31 12:52:52 +02:00
committed by Michael van Tellingen
parent 49062d36b4
commit 4e61ff0d08
6 changed files with 36 additions and 31 deletions

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2017-05-24 15:27 # Generated by Django 1.11.1 on 2017-05-31 10:20
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models from django.db import migrations, models
@ -11,18 +11,22 @@ class Migration(migrations.Migration):
initial = True initial = True
dependencies = [ dependencies = [
('wagtail_personalisation', '0008_devicerule'), ('wagtail_personalisation', '0009_auto_20170531_0428'),
('wagtailcore', '0033_remove_golive_expiry_help_text'),
] ]
operations = [ operations = [
migrations.CreateModel( migrations.CreateModel(
name='HomePage', name='HomePage',
fields=[ fields=[
('personalisablepage_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtail_personalisation.PersonalisablePage')), ('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
('is_segmented', models.BooleanField(default=False)),
('canonical_page', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='variations', to='home.HomePage')),
('segment', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='segments', to='wagtail_personalisation.Segment')),
], ],
options={ options={
'abstract': False, 'abstract': False,
}, },
bases=('wagtail_personalisation.personalisablepage',), bases=('wagtailcore.page', models.Model),
), ),
] ]

View File

@ -1,7 +1,9 @@
from __future__ import absolute_import, unicode_literals from __future__ import absolute_import, unicode_literals
from wagtail_personalisation.models import PersonalisablePage from wagtail.wagtailcore.models import Page
from wagtail_personalisation.models import AbstractPersonalisablePage
class HomePage(PersonalisablePage): class HomePage(AbstractPersonalisablePage, Page):
pass pass

View File

@ -33,10 +33,6 @@ EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
'sandbox.apps.home',
'sandbox.apps.search',
'sandbox.apps.user',
'wagtail.wagtailforms', 'wagtail.wagtailforms',
'wagtail.wagtailredirects', 'wagtail.wagtailredirects',
'wagtail.wagtailembeds', 'wagtail.wagtailembeds',
@ -63,6 +59,10 @@ INSTALLED_APPS = [
'wagtail_personalisation', 'wagtail_personalisation',
'sandbox.apps.home',
'sandbox.apps.search',
'sandbox.apps.user',
] ]
MIDDLEWARE = [ MIDDLEWARE = [

View File

@ -113,14 +113,6 @@ class AbstractPersonalisablePage(models.Model):
def __str__(self): def __str__(self):
return "{}".format(self.title) return "{}".format(self.title)
@classmethod
def get_model(cls):
try:
cls.__subclasses__()[0]
except IndexError:
raise Exception("Unable to find non-abstract subclass for %s" %
cls.__name)
@cached_property @cached_property
def has_variations(self): def has_variations(self):
"""Return a boolean indicating whether or not the personalisable page """Return a boolean indicating whether or not the personalisable page

View File

@ -9,6 +9,7 @@ from django.utils.translation import ugettext_lazy as _
from wagtail.wagtailadmin.site_summary import SummaryItem from wagtail.wagtailadmin.site_summary import SummaryItem
from wagtail.wagtailadmin.widgets import Button, ButtonWithDropdownFromHook from wagtail.wagtailadmin.widgets import Button, ButtonWithDropdownFromHook
from wagtail.wagtailcore import hooks from wagtail.wagtailcore import hooks
from wagtail.wagtailcore.models import Page
from wagtail_personalisation import admin_urls from wagtail_personalisation import admin_urls
from wagtail_personalisation.adapters import get_segment_adapter from wagtail_personalisation.adapters import get_segment_adapter
@ -107,7 +108,10 @@ def _check_for_variations(segments, page):
:rtype: wagtail_personalisation.models.PersonalisablePage or None :rtype: wagtail_personalisation.models.PersonalisablePage or None
""" """
model = AbstractPersonalisablePage.get_model() try:
model = AbstractPersonalisablePage.__subclasses__()[0]
except IndexError:
return
for segment in segments: for segment in segments:
page_class = page.__class__ page_class = page.__class__
if any(item == model for item in page_class.__bases__): if any(item == model for item in page_class.__bases__):
@ -127,15 +131,14 @@ def page_listing_variant_buttons(page, page_perms, is_parent=False):
the page (if any) and a 'Create a new variant' button. the page (if any) and a 'Create a new variant' button.
""" """
model = AbstractPersonalisablePage.get_model()
if model:
personalisable_page = model.objects.filter(pk=page.pk)
else:
personalisable_page = page
segments = Segment.objects.all()
if personalisable_page and len(segments) > 0 and not ( pages = Page.objects.filter(pk=page.pk)
any(item.segment for item in personalisable_page)): segments = Segment.objects.all()
if pages:
pages = [x.specific_class() for x in pages]
if pages and len(segments) > 0 and not (
any(item.segment for item in pages)):
yield ButtonWithDropdownFromHook( yield ButtonWithDropdownFromHook(
_('Variants'), _('Variants'),
hook_name='register_page_listing_variant_buttons', hook_name='register_page_listing_variant_buttons',
@ -152,7 +155,10 @@ def page_listing_more_buttons(page, page_perms, is_parent=False):
create a new variant for the selected segment. create a new variant for the selected segment.
""" """
model = AbstractPersonalisablePage.get_model() try:
model = AbstractPersonalisablePage.__subclasses__()[0]
except IndexError:
return
segments = Segment.objects.all() segments = Segment.objects.all()
available_segments = [ available_segments = [
item for item in segments item for item in segments

View File

@ -3,15 +3,16 @@ from __future__ import absolute_import, unicode_literals
from django.db import models from django.db import models
from wagtail.wagtailadmin.edit_handlers import FieldPanel from wagtail.wagtailadmin.edit_handlers import FieldPanel
from wagtail.wagtailcore.fields import RichTextField from wagtail.wagtailcore.fields import RichTextField
from wagtail.wagtailcore.models import Page
from wagtail_personalisation.models import PersonalisablePage from wagtail_personalisation.models import AbstractPersonalisablePage
class HomePage(PersonalisablePage): class HomePage(AbstractPersonalisablePage, Page):
subtitle = models.CharField(max_length=255) subtitle = models.CharField(max_length=255)
body = RichTextField(blank=True, default='') body = RichTextField(blank=True, default='')
content_panels = PersonalisablePage.content_panels + [ content_panels = Page.content_panels + [
FieldPanel('subtitle'), FieldPanel('subtitle'),
FieldPanel('body'), FieldPanel('body'),
] ]