diff --git a/sigi/apps/servicos/migrations/0019_ajusta_dominios.py b/sigi/apps/servicos/migrations/0019_ajusta_dominios.py new file mode 100644 index 0000000..dd466a1 --- /dev/null +++ b/sigi/apps/servicos/migrations/0019_ajusta_dominios.py @@ -0,0 +1,48 @@ +# Generated by Django 4.1.2 on 2022-11-02 13:59 + +from django.db import migrations +from sigi.apps.servicos import generate_instance_name + + +def dominios_fw(apps, schema_editor): + Servico = apps.get_model("servicos", "Servico") + for s in Servico.objects.filter(tipo_servico__modo="R"): + if s.url == "": + nova_url = generate_instance_name(s.casa_legislativa).replace( + "-", "." + ) + if s.tipo_servico.sigla == "LEGBR": + nova_url += ".leg.br" + else: + nova_url += ".gov.br" + else: + nova_url = ( + s.url.replace("http://", "") + .replace("https://", "") + .replace("www.", "") + .replace("sapl.", "") + .replace("/", "") + ) + if nova_url.startswith("."): + nova_url = nova_url.replace(".", "", 1) + if s.url != nova_url: + s.url = nova_url + s.save() + + +def dominios_rw(apps, schema_editor): + # Não precisa fazer nada para reverter essa migração. # + # esta função está aqui apenas para que a migration # + # não seja irreversível e atrapalhe ajustes futuros. # + pass + + +class Migration(migrations.Migration): + + dependencies = [ + ("servicos", "0018_servico_flag_confirmado"), + ] + + operations = [ + migrations.RunPython(dominios_fw, dominios_rw), + ]