From 7de838edbc59d36e729f62e7e07099012944cb67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Thu, 30 Jun 2022 14:54:29 -0300 Subject: [PATCH] Inclui campo telefone_geral em Orgao --- sigi/apps/casas/admin.py | 3 +- .../migrations/0025_orgao_telefone_geral.py | 18 ++++++++++++ .../migrations/0026_carga_telefone_geral.py | 29 +++++++++++++++++++ sigi/apps/casas/models.py | 17 ++++++++--- ...30_alter_projeto_modelo_minuta_and_more.py | 25 ++++++++++++++++ sigi/apps/eventos/forms.py | 10 ++++++- 6 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 sigi/apps/casas/migrations/0025_orgao_telefone_geral.py create mode 100644 sigi/apps/casas/migrations/0026_carga_telefone_geral.py create mode 100644 sigi/apps/convenios/migrations/0030_alter_projeto_modelo_minuta_and_more.py diff --git a/sigi/apps/casas/admin.py b/sigi/apps/casas/admin.py index f25efa2..286ec0a 100644 --- a/sigi/apps/casas/admin.py +++ b/sigi/apps/casas/admin.py @@ -324,8 +324,9 @@ class OrgaoAdmin(CartExportReportMixin, admin.ModelAdmin): _("Outras informações"), { "fields": ( - "observacoes", + "telefone_geral", "horario_funcionamento", + "observacoes", "foto", "brasao", ), diff --git a/sigi/apps/casas/migrations/0025_orgao_telefone_geral.py b/sigi/apps/casas/migrations/0025_orgao_telefone_geral.py new file mode 100644 index 0000000..7d6c112 --- /dev/null +++ b/sigi/apps/casas/migrations/0025_orgao_telefone_geral.py @@ -0,0 +1,18 @@ +# Generated by Django 4.0.5 on 2022-06-30 17:21 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('casas', '0024_delete_presidente'), + ] + + operations = [ + migrations.AddField( + model_name='orgao', + name='telefone_geral', + field=models.CharField(blank=True, default='', help_text='Exemplo: (31)8851-9898.', max_length=64, verbose_name='telefone geral'), + ), + ] diff --git a/sigi/apps/casas/migrations/0026_carga_telefone_geral.py b/sigi/apps/casas/migrations/0026_carga_telefone_geral.py new file mode 100644 index 0000000..2462a32 --- /dev/null +++ b/sigi/apps/casas/migrations/0026_carga_telefone_geral.py @@ -0,0 +1,29 @@ +# Generated by Django 4.0.5 on 2022-06-30 17:26 + +from django.db import migrations + + +def carrega_telefone_geral(apps, schema_editor): + Orgao = apps.get_model("casas", "Orgao") + Telefone = apps.get_model("contatos", "Telefone") + telefones = Telefone.objects.filter( + content_type__app_label="casas", content_type__model="orgao" + ) + for orgao in Orgao.objects.all(): + telefone = ( + telefones.filter(object_id=orgao.id).exclude(numero="").first() + ) + if telefone: + orgao.telefone_geral = telefone.numero + orgao.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ("casas", "0025_orgao_telefone_geral"), + ] + + operations = [ + migrations.RunPython(carrega_telefone_geral), + ] diff --git a/sigi/apps/casas/models.py b/sigi/apps/casas/models.py index 345ef1d..e9ec425 100644 --- a/sigi/apps/casas/models.py +++ b/sigi/apps/casas/models.py @@ -100,6 +100,13 @@ class Orgao(models.Model): ult_alt_endereco = models.DateTimeField( _("última alteração do endereço"), null=True, blank=True, editable=True ) + telefone_geral = models.CharField( + _("telefone geral"), + max_length=64, + blank=True, + default="", + help_text=_("Exemplo: (31)8851-9898."), + ) telefones = GenericRelation("contatos.Telefone") foto = models.ImageField( _("foto"), @@ -153,10 +160,12 @@ class Orgao(models.Model): @property def telefone(self): - telefones = self.telefones.all() - if telefones: - return telefones[0] - return None + if self.telefone_geral: + return self.telefone_geral + telefone = self.telefones.first() + if telefone: + return telefone.numero + return "" @property def presidente(self): diff --git a/sigi/apps/convenios/migrations/0030_alter_projeto_modelo_minuta_and_more.py b/sigi/apps/convenios/migrations/0030_alter_projeto_modelo_minuta_and_more.py new file mode 100644 index 0000000..d0daa11 --- /dev/null +++ b/sigi/apps/convenios/migrations/0030_alter_projeto_modelo_minuta_and_more.py @@ -0,0 +1,25 @@ +# Generated by Django 4.0.5 on 2022-06-30 17:21 + +import django.core.validators +from django.db import migrations, models +import tinymce.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('convenios', '0029_alter_projeto_modelo_minuta_and_more'), + ] + + operations = [ + migrations.AlterField( + model_name='projeto', + name='modelo_minuta', + field=models.FileField(blank=True, help_text='\nUtilize os seguintes placeholders\n\n', upload_to='convenios/minutas/', validators=[django.core.validators.FileExtensionValidator(['docx'])], verbose_name='Modelo de minuta'), + ), + migrations.AlterField( + model_name='projeto', + name='texto_oficio', + field=tinymce.models.HTMLField(blank=True, help_text='\nUtilize os seguintes placeholders\n\n', verbose_name='texto do ofício'), + ), + ] diff --git a/sigi/apps/eventos/forms.py b/sigi/apps/eventos/forms.py index e56b4b9..fe2cc50 100644 --- a/sigi/apps/eventos/forms.py +++ b/sigi/apps/eventos/forms.py @@ -61,7 +61,15 @@ class ConviteForm(forms.ModelForm): class CasaForm(forms.ModelForm): class Meta: model = Orgao - fields = ["cnpj", "logradouro", "bairro", "cep", "email", "brasao"] + fields = [ + "cnpj", + "logradouro", + "bairro", + "cep", + "telefone_geral", + "email", + "brasao", + ] class FuncionarioForm(forms.ModelForm):