Permalink
Browse files

added the management command lang_copy to copy the whole content from…

… one lang to another
  • Loading branch information...
1 parent aaa32ec commit e6b276643bbc6ad72033b081b9117d7e867224bf robint committed Aug 30, 2011
Showing with 31 additions and 0 deletions.
  1. +31 −0 cms/management/commands/lang_copy.py
@@ -0,0 +1,31 @@
+from copy import deepcopy
+
+from django.conf import settings
+from django.core.management.base import BaseCommand, CommandError
+from cms.models.pluginmodel import CMSPlugin
+
+class Command(BaseCommand):
+ args = '<language_code language_code>'
+ help = 'dupplicate the cms content from one lang to another'
+
+ def handle(self, *args, **kwargs):
+ from_lang = args[0]
+ to_lang = args[1]
+ #test both langs
+ try:
+ assert len(args) == 2
+ 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):
+ if not CMSPlugin.objects.filter(language=to_lang, placeholder=plugin.placeholder, position=plugin.position).exists():
+ plugin.copy_plugin(plugin.placeholder, to_lang, [])
+ print 'DONE'

0 comments on commit e6b2766

Please sign in to comment.