@@ -0,0 +1,1958 @@
+# -*- coding: utf-8 -*-%0A# Generated by Django 1.11 on 2018-03-12 09:50%0Afrom __future__ import unicode_literals%0A%0Afrom bulk_update.helper import bulk_update%0Afrom django.db import migrations%0Afrom fluent.syntax import FluentParser, FluentSerializer%0A%0A%0Adef migrate_ftl_translations_to_0_6_4(apps, schema):%0A    %22%22%22%0A    Converts all FTL translations to the latest (0.5) syntax and serializes%0A    them with the latest (0.6.4) serializer to prevent creating duplicate%0A    translations on save. Also convert corresponding TranslationMemoryEntries.%0A%0A    See bugs 1441020 and 1442201 for more details.%0A    %22%22%22%0A    parser = FluentParser()%0A    serializer = FluentSerializer()%0A%0A    # Translations%0A    Translation = apps.get_model('base', 'Translation')%0A    translations = Translation.objects.filter(entity__resource__format='ftl')%0A    translations_to_update = %5B%5D%0A%0A    for t in translations:%0A        current = t.string%0A        ast = parser.parse_entry(current)%0A        t.string = serializer.serialize_entry(ast)%0A%0A        if t.string != current:%0A            translations_to_update.append(t)%0A%0A    bulk_update(translations_to_update, update_fields=%5B'string'%5D)%0A%0A    # Translation Memory Entries%0A    TranslationMemoryEntry = apps.get_model('base', 'TranslationMemoryEntry')%0A    updated_pks = %5Bx.pk for x in translations_to_update%5D%0A    tms = TranslationMemoryEntry.objects.filter(translation__pk__in=updated_pks)%0A    tms_to_update = %5B%5D%0A%0A    for tm in tms:%0A        current = tm.target%0A        ast = parser.parse_entry(current)%0A        tm.target = serializer.serialize_entry(ast)%0A%0A        if tm.target != current:%0A            tms_to_update.append(tm)%0A%0A    bulk_update(tms_to_update, update_fields=%5B'target'%5D)%0A%0A%0Aclass Migration(migrations.Migration):%0A%0A    dependencies = %5B%0A        ('base', '0115_idx_translation_date_locale'),%0A    %5D%0A%0A    operations = %5B%0A        migrations.RunPython(%0A            migrate_ftl_translations_to_0_6_4,%0A            migrations.RunPython.noop%0A        )%0A    %5D%0A

Fix bug 1441020: Migrate FTL translations to latest syntax (#893)