export_templates_variant.py
1.26 KB
# -*- coding: utf-8 -*-
from django.core.management.base import BaseCommand
from common.util import uniprint, json_encode
from tables.models import TableTemplate
from tables.management.commands.export_template import export_template
class Command(BaseCommand):
help = "Exports all templates to JSON."
def add_arguments(self, parser):
parser.add_argument('variant')
def handle(self, *args, **options):
uniprint(json_encode(export_templates(options['variant'])))
def export_templates(variant):
data = []
for tt in TableTemplate.objects.filter(variant_id=variant):
data_row = export_template(tt)
data_row['parts_of_speech'] = list(
tt.parts_of_speech.values_list('symbol', flat=True))
data_row['pattern_types'] = list(
tt.pattern_types.values_list('symbol', 'inflection_type_id'))
data_row['attributes'] = list(
tt.attributes.values_list('name', flat=True))
data_row['attribute_values'] = list(
tt.attribute_values.values_list('value', 'attribute__name'))
data_row['cell_attributes'] = list(
tt.cell_attributes.values_list('name', flat=True))
data_row['takes_gender'] = tt.takes_gender
data.append(data_row)
return data