Пример #1
0
def main():
    for node in VersionNode.objects.all():
        if not '<question' in node.text: continue
        q = qml.make_qml(node)
        question_points(q)
        node.text = qml.xml2string(q.make_xml())
        node.save()

    for node in TranslationNode.objects.all():
        if not '<question' in node.text: continue
        q = qml.make_qml(node)
        question_points(q)
        node.text = qml.xml2string(q.make_xml())
        node.save()
Пример #2
0
def make_backups(backup_folder):
    timestamp = get_time().strftime(TIMESTP_FORMAT)
    for node in VersionNode.objects.all():
        question_id = node.question_id
        version_id = node.version

        node_id = '{t}_q{q}_v{v}'.format(
            t=timestamp,
            q=question_id,
            v=version_id,
        )

        dump_file = os.path.join(backup_folder,
                                 'version_dump_' + node_id + '.json')
        export_file = os.path.join(backup_folder,
                                   'version_export_' + node_id + '.xml')

        with open(dump_file, 'w') as stream:
            serializers.serialize('json', [node],
                                  indent=2,
                                  use_natural_foreign_keys=True,
                                  use_natural_primary_keys=True,
                                  stream=stream)

        if node.text:
            export = qml.unescape_entities(
                qml.xml2string(qml.make_qml(node).make_xml()))
            with open(export_file, 'w') as f:
                f.write(export)
Пример #3
0
def make_backups(backup_folder):
    timestamp = get_time().strftime(TIMESTP_FORMAT)
    for node in TranslationNode.objects.all():
        language_id = node.language_id
        question_id = node.question_id
        delegation_id = node.language.delegation.name

        node_id = '{t}_d{d}_q{q}_l{l}'.format(t=timestamp,
                                              d=delegation_id,
                                              q=question_id,
                                              l=language_id)

        dump_file = os.path.join(backup_folder,
                                 'translation_dump_' + node_id + '.json')
        export_file = os.path.join(backup_folder,
                                   'translation_export_' + node_id + '.xml')

        with open(dump_file, 'w') as stream:
            serializers.serialize('json', [node.language, node],
                                  indent=2,
                                  use_natural_foreign_keys=True,
                                  use_natural_primary_keys=True,
                                  stream=stream)

        if node.text:
            export = qml.unescape_entities(
                qml.xml2string(qml.make_qml(node).make_xml()))
            with open(export_file, 'w') as f:
                f.write(export)
Пример #4
0
def forwards_func(apps, schema_editor):
    db_alias = schema_editor.connection.alias
    for node_name in ['VersionNode', 'TranslationNode']:
        NodeType = apps.get_model("ipho_exam", node_name)
        for node in NodeType.objects.using(db_alias).all():
            if not '<question' in node.text: continue
            q = qml.QMLquestion(node.text)
            question_points(q)
            node.text = qml.xml2string(q.make_xml())
            node.save()