Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' into test_improvements

Conflicts:
	cms/tests/page.py
  • Loading branch information...
commit feac5d9fc61cfa9400ae2d4936bd8b8032c3c631 2 parents 56a235d + 69c464e
@ojii ojii authored
View
5 cms/models/metaclasses.py
@@ -9,7 +9,10 @@ class PageMetaClass(ModelBase):
def __new__(cls, name, bases, attrs):
super_new = super(PageMetaClass, cls).__new__
if not settings.CMS_MODERATOR:
- return super_new(cls, name, bases, attrs)
+ attrs = install_mptt(cls, name, bases, attrs)
+ new_class = super_new(cls, name, bases, attrs)
+ finish_mptt(new_class)
+ return new_class
if 'objects' in attrs:
if not isinstance(attrs['objects'], PublisherManager):
View
18 cms/models/pagemodel.py
@@ -420,6 +420,7 @@ def publish(self):
if not published:
# was not published, escape
+ transaction.commit()
return
# clean moderation log
@@ -1081,6 +1082,23 @@ def _publisher_save_public(self, obj):
# or none structural change, just save
obj.save()
return obj
+
+ def rescan_placeholders(self):
+ """
+ Rescan and if necessary create placeholders in the current template.
+ """
+ # inline import to prevent circular imports
+ from cms.utils.plugins import get_placeholders
+ placeholders = get_placeholders(self.get_template())
+ found = {}
+ for placeholder in self.placeholders.all():
+ if placeholder.slot in placeholders:
+ found[placeholder.slot] = placeholder
+ for placeholder_name in placeholders:
+ if not placeholder_name in found:
+ placeholder = Placeholder.objects.create(slot=placeholder_name)
+ self.placeholders.add(placeholder)
+ found[placeholder_name] = placeholder
def _reversion():
if 'publisher' in settings.INSTALLED_APPS:
View
12 cms/signals.py
@@ -198,17 +198,7 @@ def post_save_page(instance, raw, created, **kwargs):
page_changed(instance, old_page)
def update_placeholders(instance, **kwargs):
- from cms.utils.plugins import get_placeholders
- placeholders = get_placeholders(instance.get_template())
- found = {}
- for placeholder in instance.placeholders.all():
- if placeholder.slot in placeholders:
- found[placeholder.slot] = placeholder
- for placeholder_name in placeholders:
- if not placeholder_name in found:
- placeholder = Placeholder.objects.create(slot=placeholder_name)
- instance.placeholders.add(placeholder)
- found[placeholder_name] = placeholder
+ instance.rescan_placeholders()
def invalidate_menu_cache(instance, **kwargs):
menu_pool.clear(instance.site_id)
View
30 cms/tests/page.py
@@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import with_statement
from cms.models import Page, Title
+from cms.models.placeholdermodel import Placeholder
+from cms.models.pluginmodel import CMSPlugin
+from cms.plugins.text.models import Text
from cms.sitemaps import CMSSitemap
from cms.tests.base import CMSTestCase, URL_CMS_PAGE, URL_CMS_PAGE_ADD, \
URL_CMS_PAGE_CHANGE
@@ -306,3 +309,30 @@ def test_15_templates(self):
parent.save()
self.assertEqual(parent.template, settings.CMS_TEMPLATE_INHERITANCE_MAGIC)
self.assertEqual(parent.get_template(), settings.CMS_TEMPLATES[0][0])
+
+ def test_16_delete_with_plugins(self):
+ """
+ Check that plugins and placeholders get correctly deleted when we delete
+ a page!
+ """
+ page = self.new_create_page()
+ page.rescan_placeholders() # create placeholders
+ placeholder = page.placeholders.all()[0]
+ plugin_base = CMSPlugin(
+ plugin_type='TextPlugin',
+ placeholder=placeholder,
+ position=1,
+ language=settings.LANGUAGES[0][0]
+ )
+ plugin_base.insert_at(None, position='last-child', commit=False)
+
+ plugin = Text(body='')
+ plugin_base.set_base_attr(plugin)
+ plugin.save()
+ self.assertEqual(CMSPlugin.objects.count(), 1)
+ self.assertEqual(Text.objects.count(), 1)
+ self.assertTrue(Placeholder.objects.count() > 0)
+ page.delete()
+ self.assertEqual(CMSPlugin.objects.count(), 0)
+ self.assertEqual(Text.objects.count(), 0)
+ self.assertEqual(Placeholder.objects.count(), 0)
View
6 cms/tests/plugins.py
@@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
from cms.exceptions import PluginAlreadyRegistered, PluginNotRegistered
-from cms.models import Page, Title, Placeholder
+from cms.models import Page, Placeholder
from cms.models.pluginmodel import CMSPlugin
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
-from cms.plugins.link.models import Link
from cms.plugins.text.models import Text
from cms.plugins.text.utils import plugin_tags_to_id_list, plugin_tags_to_admin_html
from cms.plugins.googlemap.models import GoogleMap
@@ -17,8 +16,7 @@
from django.conf import settings
from django.contrib.auth.models import User
-from django.http import HttpRequest
-from django.template import TemplateDoesNotExist, RequestContext
+from django.template import RequestContext
from django.forms.widgets import Media
from django.core.files.uploadedfile import SimpleUploadedFile
Please sign in to comment.
Something went wrong with that request. Please try again.