From: Guillaume Pellerin Date: Fri, 5 Dec 2014 19:01:03 +0000 (+0100) Subject: add a command exporting field with their locales to XLS X-Git-Tag: 1.5.0rc2~2 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=646e8cc87b4bb0d032f6f725a0fc2fbc8dfe5a1f;p=telemeta.git add a command exporting field with their locales to XLS --- diff --git a/telemeta/management/commands/telemeta-export-fields.py b/telemeta/management/commands/telemeta-export-fields.py new file mode 100644 index 00000000..da24f69e --- /dev/null +++ b/telemeta/management/commands/telemeta-export-fields.py @@ -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)