]> git.parisson.com Git - telemeta.git/commitdiff
add a command exporting field with their locales to XLS
authorGuillaume Pellerin <yomguy@parisson.com>
Fri, 5 Dec 2014 19:01:03 +0000 (20:01 +0100)
committerGuillaume Pellerin <yomguy@parisson.com>
Fri, 5 Dec 2014 19:01:03 +0000 (20:01 +0100)
telemeta/management/commands/telemeta-export-fields.py [new file with mode: 0644]

diff --git a/telemeta/management/commands/telemeta-export-fields.py b/telemeta/management/commands/telemeta-export-fields.py
new file mode 100644 (file)
index 0000000..da24f69
--- /dev/null
@@ -0,0 +1,45 @@
+from optparse import make_option
+from django.conf import settings
+from django.core.management.base import BaseCommand, CommandError
+from django.contrib.auth.models import User
+from django.template.defaultfilters import slugify
+from django.utils import translation
+from telemeta.models import *
+from telemeta.util.unaccent import unaccent
+import logging
+import codecs
+from xlwt import Workbook
+
+class Command(BaseCommand):
+    help = "Export media fields to a XLS file (see an example in example/data/"
+    args = "path"
+    first_row = 1
+    admin_email = 'webmaster@parisson.com'
+    language_codes = ['en_US', 'fr_FR', 'de_DE']
+    models = [MediaFonds, MediaCorpus, MediaCollection, MediaItem]
+
+    def handle(self, *args, **options):
+        self.file = args[0]
+        self.book = Workbook()
+        for model in self.models:
+            self.sheet = self.book.add_sheet(model.element_type)
+            self.sheet.write(0, 0, 'Field')
+            self.sheet.col(0).width = 256*32
+
+            k = 1
+            for language_code in self.language_codes:
+                self.sheet.write(0, k, language_code)
+                self.sheet.col(k).width = 256*32
+                k += 1
+
+            i = 1
+            for field in model._meta.fields:
+                self.sheet.write(i, 0, field.attname)
+                j = 1
+                for language_code in self.language_codes:
+                    translation.activate(language_code)
+                    self.sheet.write(i, j, unicode(field.verbose_name.lower()))
+                    j += 1
+                i += 1
+
+        self.book.save(self.file)