# Copyright © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later

# Generated by Django 4.2.1 on 2023-05-16 12:09

from django.db import migrations


def pending_explanation(apps, schema_editor):
    apps.get_model("trans", "Component")
    Unit = apps.get_model("trans", "Unit")
    units = Unit.objects.using(schema_editor.connection.alias).filter(
        translation__component__file_format="tbx"
    )
    # Translation explanations
    units.exclude(explanation="").exclude(translation__filename="").update(pending=True)
    # Source string explanations
    units.exclude(source_unit__explanation="").exclude(translation__filename="").update(
        pending=True
    )


class Migration(migrations.Migration):
    dependencies = [
        ("trans", "0166_alter_change_action"),
    ]

    operations = [
        migrations.RunPython(
            pending_explanation, migrations.RunPython.noop, elidable=True
        )
    ]
