Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #632 (copy_plugin_to copying all plugins to a single language i…

…nstead of the language of the src plugin)
  • Loading branch information...
commit b5316982bc5dfd331743f7d2ddce3018b9f5137b 1 parent 051d990
@ojii ojii authored
View
3  cms/models/pagemodel.py
@@ -260,8 +260,7 @@ def copy_page(self, target, site, position='first-child', copy_permissions=True,
ph.save()
page.placeholders.add(ph)
if plugins:
- language = plugins[0].language
- copy_plugins_to(plugins, ph, language)
+ copy_plugins_to(plugins, ph)
# invalidate the menu for this site
menu_pool.clear(site_id=site.pk)
View
49 cms/tests/base.py
@@ -159,20 +159,25 @@ def create_page(self, parent_page=None, user=None, position="last-child",
if settings.CMS_MODERATOR and user:
page.pagemoderator_set.create(user=user)
- title_data = {
- 'title': 'test page %d' % self.counter,
- 'slug': 'test-page-%d' % self.counter,
- 'language': language,
- 'page': page,
- }
+ if not title:
+ title = 'test page %d' % self.counter
+ slug = 'test-page-%d' % self.counter
+ else:
+ slug = slugify(title)
self.counter = self.counter + 1
- if title:
- title_data['title'] = title
- title_data['slug'] = slugify(title)
- Title.objects.create(**title_data)
+ self.create_title(title=title, slug=slug, language=language, page=page)
del _thread_locals.user
return page
+
+ def create_title(self, title, slug, language, page, **extra):
+ return Title.objects.create(
+ title=title,
+ slug=slug,
+ language=language,
+ page=page,
+ **extra
+ )
def copy_page(self, page, target_page):
from cms.utils.page import get_available_slug
@@ -203,7 +208,10 @@ def reload_page(self, page):
"""
Returns a fresh instance of the page from the database
"""
- return Page.objects.get(pk=page.pk)
+ return self.reload(page)
+
+ def reload(self, obj):
+ return obj.__class__.objects.get(pk=obj.pk)
def get_pages_root(self):
return urllib.unquote(reverse("pages-root"))
@@ -276,13 +284,17 @@ def create_page_user(self, username, password=None,
'can_change_pagepermission': can_change_pagepermission,
'can_delete_pagepermission': can_delete_pagepermission,
}
+ if hasattr(self, 'user'):
+ created_by = self.user
+ else:
+ created_by = User.objects.create_superuser('superuser', 'superuser@django-cms.org', 'superuser')
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
user = User.objects.create_user(username, 'username@django-cms.org', password)
user.is_staff = True
user.is_active = True
- page_user = PageUser(created_by=self.user)
+ page_user = PageUser(created_by=created_by)
for field in [f.name for f in User._meta.local_fields]:
setattr(page_user, field, getattr(user, field))
user.save()
@@ -319,15 +331,20 @@ def assign_user_to_page(self, page, user, grant_on=ACCESS_PAGE_AND_DESCENDANTS,
page_permission.save()
return page_permission
- def add_plugin(self, user, page=None):
- if not page:
+ def add_plugin(self, user=None, page=None, placeholder=None, language='en'):
+ if placeholder:
+ page = placeholder.page_set.all()[0]
+ elif page:
+ placeholder = page.placeholders.get(slot__iexact='Right-Column')
+ else:
page = self.slave_page
- placeholder = page.placeholders.get(slot__iexact='Right-Column')
+ placeholder = page.placeholders.get(slot__iexact='Right-Column')
+
plugin_base = CMSPlugin(
plugin_type='TextPlugin',
placeholder=placeholder,
position=1,
- language='en'
+ language=language
)
plugin_base.insert_at(None, position='last-child', commit=False)
View
29 cms/tests/multilingual.py
@@ -1,10 +1,11 @@
from cms.middleware.multilingual import patch_response
+from cms.tests.base import CMSTestCase
+from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
-from django.test.testcases import TestCase
import urllib
-class MultilingualTestCase(TestCase):
+class MultilingualTestCase(CMSTestCase):
def test_01_multilingual_url_middleware(self):
"""
Test the Multilingual URL Middleware correctly handles the various ways
@@ -37,4 +38,26 @@ def test_01_multilingual_url_middleware(self):
content = '<form action="/url/">'
output = patch_response(content, pages_root, language)
expected = '<form action="/en/url/">'
- self.assertEqual(output, expected)
+ self.assertEqual(output, expected)
+
+ def test_02_multilingual_page(self):
+ page = self.create_page()
+ self.create_title(
+ page=page,
+ title=page.get_title(),
+ slug=page.get_slug(),
+ language='de'
+ )
+ page.rescan_placeholders()
+ page = self.reload(page)
+ placeholder = page.placeholders.all()[0]
+ self.add_plugin(placeholder=placeholder, language='de')
+ self.add_plugin(placeholder=placeholder, language='en')
+ self.assertEqual(placeholder.cmsplugin_set.filter(language='de').count(), 1)
+ self.assertEqual(placeholder.cmsplugin_set.filter(language='en').count(), 1)
+ user = User.objects.create_superuser('super', 'super@django-cms.org', 'super')
+ page = self.publish_page(page, approve=True, user=user)
+ public = page.publisher_public
+ placeholder = public.placeholders.all()[0]
+ self.assertEqual(placeholder.cmsplugin_set.filter(language='de').count(), 1)
+ self.assertEqual(placeholder.cmsplugin_set.filter(language='en').count(), 1)
View
8 cms/utils/copy_plugins.py
@@ -1,12 +1,16 @@
-def copy_plugins_to(plugin_list, to_placeholder, to_language):
+def copy_plugins_to(plugin_list, to_placeholder, to_language = None):
"""
Copies a list of plugins to a placeholder to a language.
"""
ptree = []
plugins_ziplist = []
for old_plugin in plugin_list:
+ if to_language:
+ plugin_language = to_language
+ else:
+ plugin_language = old_plugin.language
# do the simple copying
- new_plugin = old_plugin.copy_plugin(to_placeholder, to_language, ptree)
+ new_plugin = old_plugin.copy_plugin(to_placeholder, plugin_language, ptree)
plugins_ziplist.append((new_plugin, old_plugin))
# this magic is needed for advanced plugins like Text Plugins that can have
# nested plugins and need to update their content based on the new plugins.
Please sign in to comment.
Something went wrong with that request. Please try again.