adds copy page logic
This commit is contained in:
@@ -10,6 +10,7 @@ from django.template.defaultfilters import slugify
|
|||||||
from django.utils.encoding import python_2_unicode_compatible
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
from django.shortcuts import redirect
|
||||||
from modelcluster.fields import ParentalKey
|
from modelcluster.fields import ParentalKey
|
||||||
from modelcluster.models import ClusterableModel
|
from modelcluster.models import ClusterableModel
|
||||||
from polymorphic.models import PolymorphicModel
|
from polymorphic.models import PolymorphicModel
|
||||||
@@ -208,20 +209,24 @@ class AdminPersonalisablePageForm(WagtailAdminPageForm):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(AdminPersonalisablePageForm, self).__init__(*args, **kwargs)
|
super(AdminPersonalisablePageForm, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
canonical_page_text = _("None")
|
def save(self, commit=True):
|
||||||
if self.instance.canonical_page:
|
page = super(AdminPersonalisablePageForm, self).save(commit=False)
|
||||||
canonical_page_text = self.instance.canonical_page.title
|
|
||||||
self.fields['canonical_page'].widget = ReadOnlyWidget(
|
|
||||||
text_display=canonical_page_text)
|
|
||||||
|
|
||||||
segment_display = Segment.objects.filter(
|
segment = page.segment
|
||||||
pk=self.initial['segment']).first()
|
slug = "{}-{}".format(page.slug, segment.encoded_name())
|
||||||
|
title = "{} ({})".format(page.title, segment.name)
|
||||||
|
update_attrs = {
|
||||||
|
'title': title,
|
||||||
|
'slug': slug,
|
||||||
|
'segment': segment,
|
||||||
|
'live': False,
|
||||||
|
'canonical_page': page,
|
||||||
|
}
|
||||||
|
|
||||||
if self.instance.is_canonical and segment_display:
|
# TODO: Implement logic to change segment when there's already one set instead of copying
|
||||||
segment_display = "{} - {}".format(segment_display, "canonical")
|
new_page = page.copy(update_attrs=update_attrs, copy_revisions=False)
|
||||||
|
|
||||||
self.fields['segment'].widget = ReadOnlyWidget(
|
return new_page
|
||||||
text_display=segment_display if segment_display else _("No segment"))
|
|
||||||
|
|
||||||
|
|
||||||
class PersonalisablePage(Page):
|
class PersonalisablePage(Page):
|
||||||
|
Reference in New Issue
Block a user