8000 Moved placeholders from Page to Title model by Aiky30 · Pull Request #6442 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

Moved placeholders from Page to Title model #6442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jul 12, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10000
Prev Previous commit
Next Next commit
Reduced the failures and errors to 20/20
  • Loading branch information
Andrew Aikman authored and czpython committed Jul 11, 2018
commit ea9bf3b413148acfb77013aefc0b4425a7d91339
9 changes: 8 additions & 1 deletion cms/models/pagemodel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
import copy
from collections import OrderedDict
from logging import getLogger
from os.path import join

Expand Down Expand Up @@ -1598,6 +1597,14 @@ def get_xframe_options(self):
except IndexError:
return None

def _copy_contents(self, target, language):
"""
Copy all the plugins to a new page.
:param target: The page where the new content should be stored
"""
for title in target.title_set.all():
title.copy_placeholders(title, language)


class PageType(Page):

Expand Down
19 changes: 18 additions & 1 deletion cms/models/titlemodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from cms.constants import PUBLISHER_STATE_DIRTY
from cms.models.managers import TitleManager
from cms.models.pagemodel import Page
from cms.utils.conf import get_cms_setting


@python_2_unicode_compatible
Expand Down Expand Up @@ -175,6 +174,24 @@ def get_placeholders(self):
self._placeholder_cache = self.placeholders.all()
return self._placeholder_cache

def copy_placeholders(self, target, language):
"""
Copy all the plugins to a new page.
:param target: The page where the new content should be stored
"""
cleared_placeholders = target._clear_placeholders(language)
cleared_placeholders_by_slot = {pl.slot: pl for pl in cleared_placeholders}

for placeholder in self.get_placeholders():
try:
target_placeholder = cleared_placeholders_by_slot[placeholder.slot]
except KeyError:
target_placeholder = target.placeholders.create(
slot=placeholder.slot,
default_width=placeholder.default_width,
)

placeholder.copy_plugins(target_placeholder, language=language)

class EmptyTitle(object):
"""
Expand Down
4 changes: 2 additions & 2 deletions cms/tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ def test_sekizai_plugin(self):
published=True)

placeholder1 = page1.get_placeholders("en").filter(slot="body")[0]
placeholder2 = page1.placeholders.filter(slot="right-column")[0]
placeholder2 = page1.get_placeholders("en").filter(slot="right-column")[0]
plugin_pool.register_plugin(SekizaiPlugin)
add_plugin(placeholder1, "SekizaiPlugin", 'en')
add_plugin(placeholder2, "TextPlugin", 'en', body="Deutsch")
Expand Down Expand Up @@ -605,7 +605,7 @@ def test_cache_invalidation(self):
published=True)
page1_url = page1.get_absolute_url()

placeholder = page1.placeholders.get(slot="body")
placeholder = page1.get_placeholders("en").get(slot="body")
add_plugin(placeholder, "TextPlugin", 'en', body="First content")
page1.publish('en')
response = self.client.get(page1_url)
Expand Down
2 changes: 1 addition & 1 deletion cms/tests/test_nested_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ def test_copy_page_nested_plugin_moved_parent_plugin(self):
self.assertEqual(len(org_placeholder_two_plugins), 2)
org_placeholder_three_plugins = page_one_ph_three.get_plugins()
self.assertEqual(len(org_placeholder_three_plugins), 0)
self.assertEqual(page_one.placeholders.count(), 3)
self.assertEqual(page_one.get_placeholders("en").count(), 3)

placeholder_count = Placeholder.objects.filter(page__publisher_is_draft=True).count()
self.assertEqual(placeholder_count, 3)
Expand Down
8 changes: 4 additions & 4 deletions cms/tests/test_placeholder.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,14 +725,14 @@ def test_plugins_children_prepopulate(self):

def test_placeholder_pk_thousands_format(self):
page = create_page("page", "nav_playground.html", "en", published=True)
title = page.get_title_obj("en")
for placeholder in page.get_placeholders("en"):
title = placeholder.title
title.placeholders.remove(placeholder)
placeholder.pk += 1000
placeholder.save()
title.placeholders.add(placeholder)
page.reload()
for placeholder in page.placeholders.all():
for placeholder in page.get_placeholders("en"):
add_plugin(placeholder, "TextPlugin", "en", body="body")
with self.settings(USE_THOUSAND_SEPARATOR=True, USE_L10N=True):
# Superuser
Expand All @@ -741,7 +741,7 @@ def test_placeholder_pk_thousands_format(self):
password=getattr(user, get_user_model().USERNAME_FIELD))
endpoint = page.get_absolute_url() + '?' + get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON')
response = self.client.get(endpoint)
for placeholder in page.placeholders.all():
for placeholder in page.get_placeholders("en"):
self.assertContains(
response, '"placeholder_id": "%s"' % placeholder.pk)
self.assertNotContains(
Expand Down Expand Up @@ -798,7 +798,7 @@ def test_placeholder_languages_page(self):
for lang in avail_langs:
add_plugin(placeholder, u"EmptyPlugin", lang)
# reload placeholder from database
placeholder = page.placeholders.get(slot='col_sidebar')
placeholder = page.get_placeholders("en").get(slot='col_sidebar')
# get languages
langs = [lang['code'] for lang in placeholder.get_filled_languages()]
self.assertEqual(avail_langs, set(langs))
Expand Down
12 changes: 6 additions & 6 deletions cms/tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ def test_remove_plugin_after_published(self):
)
# there should be only 1 plugin
self.assertEqual(CMSPlugin.objects.all().count(), 1)
self.assertEqual(CMSPlugin.objects.filter(placeholder__page__publisher_is_draft=True).count(), 1)
self.assertEqual(CMSPlugin.objects.filter(placeholder__title__page__publisher_is_draft=True).count(), 1)

# publish page
response = self.client.post(URL_CMS_PAGE + "%d/en/publish/" % page.pk, {1: 1})
Expand All @@ -723,7 +723,7 @@ def test_remove_plugin_after_published(self):

# there should be no plugins
self.assertEqual(CMSPlugin.objects.all().count(), 1)
self.assertEqual(CMSPlugin.objects.filter(placeholder__page__publisher_is_draft=False).count(), 1)
self.assertEqual(CMSPlugin.objects.filter(placeholder__title__page__publisher_is_draft=False).count(), 1)

def test_remove_plugin_not_associated_to_page(self):
"""
Expand Down Expand Up @@ -1310,15 +1310,15 @@ def test_copy_fk_from_model(self):
)
FKModel.objects.create(fk_field=plugin)
old_public_count = FKModel.objects.filter(
fk_field__placeholder__page__publisher_is_draft=False
fk_field__placeholder__title__page__publisher_is_draft=False
).count()
api.publish_page(
self.page1,
self.super_user,
self.FIRST_LANG
)
new_public_count = FKModel.objects.filter(
fk_field__placeholder__page__publisher_is_draft=False
fk_field__placeholder__title__page__publisher_is_draft=False
).count()
self.assertEqual(
new_public_count,
Expand All @@ -1334,15 +1334,15 @@ def test_copy_m2m_to_model(self):
m2m_target = M2MTargetModel.objects.create()
plugin.m2m_field.add(m2m_target)
old_public_count = M2MTargetModel.objects.filter(
pluginmodelwithm2mtomodel__placeholder__page__publisher_is_draft=False
pluginmodelwithm2mtomodel__placeholder__title__page__publisher_is_draft=False
).count()
api.publish_page(
self.page1,
self.super_user,
self.FIRST_LANG
)
new_public_count = M2MTargetModel.objects.filter(
pluginmodelwithm2mtomodel__placeholder__page__publisher_is_draft=False
pluginmodelwithm2mtomodel__placeholder__title__page__publisher_is_draft=False
).count()
self.assertEqual(
new_public_count,
Expand Down
2 changes: 1 addition & 1 deletion cms/tests/test_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ def test_revert_contents(self):
self.assertEqual(page.get_publisher_state("en"), PUBLISHER_STATE_DEFAULT)

self.assertEqual(CMSPlugin.objects.count(), 4)
plugins = CMSPlugin.objects.filter(placeholder__title=page.get_title_obj("en"))
plugins = CMSPlugin.objects.filter(placeholder=placeholder)
self.assertEqual(plugins.count(), 2)

plugins = [plugin.get_plugin_instance()[0] for plugin in plugins]
Expand Down
0