Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

management command lang_copy #971

Closed
wants to merge 2 commits into from

3 participants

robin Tissot Patrick Lauber Iacopo Spalletti
robin Tissot

added the management command lang_copy to copy the whole content from one lang to another

Patrick Lauber
Collaborator

A test would be nice.

Iacopo Spalletti yakky referenced this pull request
Merged

Add copy-lang command #2191

Iacopo Spalletti
Collaborator

The above PR integrates this and updates it

Patrick Lauber digi604 closed this in #2191
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 30, 2011
  1. added the management command lang_copy to copy the whole content from…

    robint authored
    … one lang to another
Commits on Sep 1, 2011
This page is out of date. Refresh to see the latest.
Showing with 61 additions and 0 deletions.
  1. +61 −0 cms/management/commands/lang_copy.py
61 cms/management/commands/lang_copy.py
View
@@ -0,0 +1,61 @@
+from copy import deepcopy
+from optparse import make_option
+
+from django.conf import settings
+from django.core.management.base import BaseCommand, CommandError
+
+from cms.models.pluginmodel import CMSPlugin
+from cms.models.titlemodels import Title
+
+class Command(BaseCommand):
+ args = '<language_from language_to>'
+ help = 'dupplicate the cms content from one lang to another (to boot a new lang)'
+
+ option_list = BaseCommand.option_list + (
+ make_option('--skipattrs', action='store_true', dest='skipattrs', default=False,
+ help='Tells django-cms to NOT copy page attributes (like title, slug, id, plugin app, etc..). '),
+ )
+
+ def handle(self, *args, **kwargs):
+ verbosity = kwargs.get('verbosity', 1)
+ skip_attributes = kwargs.get('skipattrs', False)
+
+ #test both langs
+ try:
+ assert len(args) == 2
+
+ from_lang = args[0]
+ to_lang = args[1]
+
+ assert from_lang != to_lang
+ except AssertionError:
+ print 'available LANGUAGES :'+str(settings.LANGUAGES)
+ raise CommandError("Error: bad arguments -- Usage: manage.py lang_copy en de")
+
+ try:
+ assert list(k for k,v in settings.LANGUAGES if k == from_lang)
+ assert list(k for k,v in settings.LANGUAGES if k == to_lang)
+ except AssertionError:
+ raise CommandError("Both languages have to be present in settings.LANGUAGES")
+
+ for plugin in CMSPlugin.objects.filter(language=from_lang):
+ #copying content of the page
+ if not CMSPlugin.objects.filter(language=to_lang, placeholder=plugin.placeholder, position=plugin.position).exists():
+ if verbosity == "2":
+ print 'copying plugin from '+str(plugin)
+ plugin.copy_plugin(plugin.placeholder, to_lang, [])
+
+ if not skip_attributes:
+ #copying attributes of the page
+ for title in Title.objects.filter(language=from_lang):
+ if not Title.objects.filter(page=title.page, language=to_lang).exists():
+ if verbosity == "2":
+ print 'copying title from '+str(title)
+ title.id = None
+ title.language = to_lang
+ title.save()
+ elif verbosity == '2':
+ print 'skipping attributes'
+
+ if verbosity == '2':
+ print 'DONE'
Something went wrong with that request. Please try again.