remove all references or uses of old PersonalisablePage model
This commit is contained in:
committed by
Michael van Tellingen
parent
49062d36b4
commit
4e61ff0d08
@ -1,5 +1,5 @@
|
||||
# -*- 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 django.db import migrations, models
|
||||
@ -11,18 +11,22 @@ class Migration(migrations.Migration):
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('wagtail_personalisation', '0008_devicerule'),
|
||||
('wagtail_personalisation', '0009_auto_20170531_0428'),
|
||||
('wagtailcore', '0033_remove_golive_expiry_help_text'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='HomePage',
|
||||
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={
|
||||
'abstract': False,
|
||||
},
|
||||
bases=('wagtail_personalisation.personalisablepage',),
|
||||
bases=('wagtailcore.page', models.Model),
|
||||
),
|
||||
]
|
||||
|
@ -1,7 +1,9 @@
|
||||
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
|
||||
|
@ -33,10 +33,6 @@ EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'sandbox.apps.home',
|
||||
'sandbox.apps.search',
|
||||
'sandbox.apps.user',
|
||||
|
||||
'wagtail.wagtailforms',
|
||||
'wagtail.wagtailredirects',
|
||||
'wagtail.wagtailembeds',
|
||||
@ -63,6 +59,10 @@ INSTALLED_APPS = [
|
||||
|
||||
'wagtail_personalisation',
|
||||
|
||||
'sandbox.apps.home',
|
||||
'sandbox.apps.search',
|
||||
'sandbox.apps.user',
|
||||
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
@ -113,14 +113,6 @@ class AbstractPersonalisablePage(models.Model):
|
||||
def __str__(self):
|
||||
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
|
||||
def has_variations(self):
|
||||
"""Return a boolean indicating whether or not the personalisable page
|
||||
|
@ -9,6 +9,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from wagtail.wagtailadmin.site_summary import SummaryItem
|
||||
from wagtail.wagtailadmin.widgets import Button, ButtonWithDropdownFromHook
|
||||
from wagtail.wagtailcore import hooks
|
||||
from wagtail.wagtailcore.models import Page
|
||||
|
||||
from wagtail_personalisation import admin_urls
|
||||
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
|
||||
|
||||
"""
|
||||
model = AbstractPersonalisablePage.get_model()
|
||||
try:
|
||||
model = AbstractPersonalisablePage.__subclasses__()[0]
|
||||
except IndexError:
|
||||
return
|
||||
for segment in segments:
|
||||
page_class = page.__class__
|
||||
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.
|
||||
|
||||
"""
|
||||
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 (
|
||||
any(item.segment for item in personalisable_page)):
|
||||
pages = Page.objects.filter(pk=page.pk)
|
||||
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(
|
||||
_('Variants'),
|
||||
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.
|
||||
|
||||
"""
|
||||
model = AbstractPersonalisablePage.get_model()
|
||||
try:
|
||||
model = AbstractPersonalisablePage.__subclasses__()[0]
|
||||
except IndexError:
|
||||
return
|
||||
segments = Segment.objects.all()
|
||||
available_segments = [
|
||||
item for item in segments
|
||||
|
@ -3,15 +3,16 @@ from __future__ import absolute_import, unicode_literals
|
||||
from django.db import models
|
||||
from wagtail.wagtailadmin.edit_handlers import FieldPanel
|
||||
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)
|
||||
body = RichTextField(blank=True, default='')
|
||||
|
||||
content_panels = PersonalisablePage.content_panels + [
|
||||
content_panels = Page.content_panels + [
|
||||
FieldPanel('subtitle'),
|
||||
FieldPanel('body'),
|
||||
]
|
||||
|
Reference in New Issue
Block a user