diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 4619552..b6ec1b1 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -8,3 +8,4 @@ psycopg2==2.9.3 django-bootstrap5==21.3 Pillow==9.0.0 django-localflavor==3.1 +requests==2.27.1 \ No newline at end of file diff --git a/sigi/apps/convenios/admin.py b/sigi/apps/convenios/admin.py index 6a9dc1e..387695c 100644 --- a/sigi/apps/convenios/admin.py +++ b/sigi/apps/convenios/admin.py @@ -1,35 +1,23 @@ -# -*- coding: utf-8 -*- from django.contrib import admin from django.http import HttpResponse, HttpResponseRedirect from django.utils.translation import gettext as _ -from geraldo.generators import PDFGenerator - +from django.utils.safestring import mark_safe from sigi.apps.convenios.models import (Projeto, StatusConvenio, TipoSolicitacao, Convenio, EquipamentoPrevisto, Anexo, Tramitacao, Gescon) -from sigi.apps.convenios.reports import ConvenioReport -from sigi.apps.convenios.views import adicionar_convenios_carrinho +# from sigi.apps.convenios.reports import ConvenioReport +# from sigi.apps.convenios.views import adicionar_convenios_carrinho from sigi.apps.utils import queryset_ascii -from sigi.apps.utils.base_admin import BaseModelAdmin from sigi.apps.servidores.models import Servidor from sigi.apps.casas.admin import GerentesInterlegisFilter -# class TramitacaoInline(admin.TabularInline): -# model = Tramitacao -# extra = 1 - class AnexosInline(admin.TabularInline): model = Anexo extra = 2 exclude = ['data_pub', ] -# class EquipamentoPrevistoInline(admin.TabularInline): -# model = EquipamentoPrevisto -# extra = 2 -# raw_id_fields = ('equipamento',) - -class AnexoAdmin(BaseModelAdmin): +class AnexoAdmin(admin.ModelAdmin): date_hierarchy = 'data_pub' exclude = ['data_pub', ] list_display = ('arquivo', 'descricao', 'data_pub', 'convenio') @@ -44,7 +32,8 @@ class AcompanhaFilter(admin.filters.RelatedFieldListFilter): convenio__isnull=False).order_by('nome_completo').distinct() self.lookup_choices = [(x.id, x) for x in servidores] -class ConvenioAdmin(BaseModelAdmin): +@admin.register(Convenio) +class ConvenioAdmin(admin.ModelAdmin): change_list_template = 'convenios/change_list.html' fieldsets = ( (None, @@ -65,8 +54,9 @@ class ConvenioAdmin(BaseModelAdmin): {'fields': ('atualizacao_gescon', 'observacao_gescon', 'link_gescon')} ), ) - readonly_fields = ('data_sigi', 'atualizacao_gescon', 'observacao_gescon', 'link_gescon') - actions = ['adicionar_convenios'] + readonly_fields = ('data_sigi', 'atualizacao_gescon', 'observacao_gescon', + 'link_gescon') + # actions = ['adicionar_convenios'] inlines = (AnexosInline,) list_display = ('num_convenio', 'projeto','casa_legislativa', 'get_uf', 'status_convenio', 'link_sigad', 'data_retorno_assinatura', @@ -76,7 +66,6 @@ class ConvenioAdmin(BaseModelAdmin): GerentesInterlegisFilter), 'projeto', 'casa_legislativa__tipo', 'conveniada','equipada', 'casa_legislativa__municipio__uf',) - #date_hierarchy = 'data_adesao' ordering = ('casa_legislativa', '-data_retorno_assinatura') raw_id_fields = ('casa_legislativa',) get_queryset = queryset_ascii @@ -102,28 +91,24 @@ class ConvenioAdmin(BaseModelAdmin): label = r"warning" else: label = r"info" - - return '

{status}

'.format(label=label, status=status) + return mark_safe(f'

{status}

') status_convenio.short_description = _("Status do convênio") - status_convenio.allow_tags = True def link_sigad(self, obj): if obj.pk is None: return "" - return obj.get_sigad_url() - + return mark_safe(obj.get_sigad_url()) link_sigad.short_description = _("Processo no Senado") - link_sigad.allow_tags = True def link_gescon(self, obj): if not obj.id_contrato_gescon: return "" - return ( - "https://adm.senado.gov.br/" - "gestao-contratos/api/{id}").format(id=obj.id_contrato_gescon) + return mark_safe( + f"" + f"https://adm.senado.gov.br/gestao-contratos/api/" + f"{obj.id_contrato_gescon}") link_gescon.short_description = _("Download MINUTA ASSINADA do Gescon") - link_gescon.allow_tags = True def changelist_view(self, request, extra_context=None): from sigi.apps.convenios.views import normaliza_data @@ -143,28 +128,28 @@ class ConvenioAdmin(BaseModelAdmin): extra_context={'query_str': '?' + request.META['QUERY_STRING']} ) - def relatorio(self, request, queryset): - # queryset.order_by('casa_legislativa__municipio__uf') - response = HttpResponse(content_type='application/pdf') - report = ConvenioReport(queryset=queryset) - report.generate_by(PDFGenerator, filename=response) - return response - relatorio.short_description = _('Exportar convênios selecionados para PDF') - - def adicionar_convenios(self, request, queryset): - if 'carrinho_convenios' in request.session: - q1 = len(request.session['carrinho_convenios']) - else: - q1 = 0 - adicionar_convenios_carrinho(request, queryset=queryset) - q2 = len(request.session['carrinho_convenios']) - quant = q2 - q1 - if quant: - self.message_user(request, str(q2 - q1) + _(" Convênios adicionados no carrinho")) - else: - self.message_user(request, _("Os Convênios selecionados já foram adicionadas anteriormente")) - return HttpResponseRedirect('.') - adicionar_convenios.short_description = _("Armazenar convênios no carrinho para exportar") + # def relatorio(self, request, queryset): + # # queryset.order_by('casa_legislativa__municipio__uf') + # response = HttpResponse(content_type='application/pdf') + # report = ConvenioReport(queryset=queryset) + # report.generate_by(PDFGenerator, filename=response) + # return response + # relatorio.short_description = _('Exportar convênios selecionados para PDF') + + # def adicionar_convenios(self, request, queryset): + # if 'carrinho_convenios' in request.session: + # q1 = len(request.session['carrinho_convenios']) + # else: + # q1 = 0 + # adicionar_convenios_carrinho(request, queryset=queryset) + # q2 = len(request.session['carrinho_convenios']) + # quant = q2 - q1 + # if quant: + # self.message_user(request, str(q2 - q1) + _(" Convênios adicionados no carrinho")) + # else: + # self.message_user(request, _("Os Convênios selecionados já foram adicionadas anteriormente")) + # return HttpResponseRedirect('.') + # adicionar_convenios.short_description = _("Armazenar convênios no carrinho para exportar") def get_actions(self, request): actions = super(ConvenioAdmin, self).get_actions(request) @@ -172,12 +157,12 @@ class ConvenioAdmin(BaseModelAdmin): del actions['delete_selected'] return actions - def lookup_allowed(self, lookup, value): - return super(ConvenioAdmin, self).lookup_allowed(lookup, value) or \ - lookup in ['casa_legislativa__municipio__uf__codigo_ibge__exact'] - + # def lookup_allowed(self, lookup, value): + # return super(ConvenioAdmin, self).lookup_allowed(lookup, value) or \ + # lookup in ['casa_legislativa__municipio__uf__codigo_ibge__exact'] -class EquipamentoPrevistoAdmin(BaseModelAdmin): +@admin.register(EquipamentoPrevisto) +class EquipamentoPrevistoAdmin(admin.ModelAdmin): list_display = ('convenio', 'equipamento', 'quantidade') list_display_links = ('convenio', 'equipamento') ordering = ('convenio', 'equipamento') @@ -193,5 +178,3 @@ class GesconAdmin(admin.ModelAdmin): admin.site.register(Projeto) admin.site.register(StatusConvenio) admin.site.register(TipoSolicitacao) -admin.site.register(Convenio, ConvenioAdmin) -admin.site.register(EquipamentoPrevisto, EquipamentoPrevistoAdmin) \ No newline at end of file diff --git a/sigi/apps/convenios/apps.py b/sigi/apps/convenios/apps.py new file mode 100644 index 0000000..71da54e --- /dev/null +++ b/sigi/apps/convenios/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig +from django.utils.translation import gettext_lazy as _ + +class ConveniosConfig(AppConfig): + name = 'sigi.apps.convenios' + verbose_name = _('convênios') diff --git a/sigi/apps/convenios/migrations/0001_initial.py b/sigi/apps/convenios/migrations/0001_initial.py index ca538b7..19bd5f4 100644 --- a/sigi/apps/convenios/migrations/0001_initial.py +++ b/sigi/apps/convenios/migrations/0001_initial.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models, migrations @@ -45,7 +44,7 @@ class Migration(migrations.Migration): ('observacao', models.CharField(max_length=100, null=True, blank=True)), ('conveniada', models.BooleanField(default=False)), ('equipada', models.BooleanField(default=False)), - ('casa_legislativa', models.ForeignKey(verbose_name='Casa Legislativa', to='casas.CasaLegislativa')), + ('casa_legislativa', models.ForeignKey(verbose_name='Casa Legislativa', to='casas.CasaLegislativa', on_delete=models.CASCADE)), ], options={ 'ordering': ('id',), @@ -59,8 +58,8 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('quantidade', models.PositiveSmallIntegerField(default=1)), - ('convenio', models.ForeignKey(verbose_name='conv\xeanio', to='convenios.Convenio')), - ('equipamento', models.ForeignKey(to='inventario.Equipamento')), + ('convenio', models.ForeignKey(verbose_name='conv\xeanio', to='convenios.Convenio', on_delete=models.CASCADE)), + ('equipamento', models.ForeignKey(to='inventario.Equipamento', on_delete=models.CASCADE)), ], options={ 'verbose_name': 'equipamento previsto', @@ -85,7 +84,7 @@ class Migration(migrations.Migration): ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('data', models.DateField()), ('observacao', models.CharField(max_length=b'512', null=True, verbose_name='observa\xe7\xe3o', blank=True)), - ('convenio', models.ForeignKey(verbose_name='conv\xeanio', to='convenios.Convenio')), + ('convenio', models.ForeignKey(verbose_name='conv\xeanio', to='convenios.Convenio', on_delete=models.CASCADE)), ], options={ 'verbose_name_plural': 'Tramita\xe7\xf5es', @@ -106,19 +105,19 @@ class Migration(migrations.Migration): migrations.AddField( model_name='tramitacao', name='unid_admin', - field=models.ForeignKey(verbose_name='Unidade Administrativa', to='convenios.UnidadeAdministrativa'), + field=models.ForeignKey(verbose_name='Unidade Administrativa', to='convenios.UnidadeAdministrativa', on_delete=models.CASCADE), preserve_default=True, ), migrations.AddField( model_name='convenio', name='projeto', - field=models.ForeignKey(to='convenios.Projeto'), + field=models.ForeignKey(to='convenios.Projeto', on_delete=models.CASCADE), preserve_default=True, ), migrations.AddField( model_name='anexo', name='convenio', - field=models.ForeignKey(verbose_name='conv\xeanio', to='convenios.Convenio'), + field=models.ForeignKey(verbose_name='conv\xeanio', to='convenios.Convenio', on_delete=models.CASCADE), preserve_default=True, ), ] diff --git a/sigi/apps/convenios/migrations/0002_convenio_duracao.py b/sigi/apps/convenios/migrations/0002_convenio_duracao.py index 7422d00..7314354 100644 --- a/sigi/apps/convenios/migrations/0002_convenio_duracao.py +++ b/sigi/apps/convenios/migrations/0002_convenio_duracao.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models, migrations diff --git a/sigi/apps/convenios/migrations/0003_auto_20210406_1945.py b/sigi/apps/convenios/migrations/0003_auto_20210406_1945.py index 1fd1c84..d241f52 100644 --- a/sigi/apps/convenios/migrations/0003_auto_20210406_1945.py +++ b/sigi/apps/convenios/migrations/0003_auto_20210406_1945.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models, migrations @@ -15,7 +14,7 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='convenio', name='casa_legislativa', - field=models.ForeignKey(verbose_name='Casa Legislativa', to='casas.Orgao'), + field=models.ForeignKey(verbose_name='Casa Legislativa', to='casas.Orgao', on_delete=models.CASCADE), preserve_default=True, ), ] diff --git a/sigi/apps/convenios/migrations/0004_auto_20210407_1928.py b/sigi/apps/convenios/migrations/0004_auto_20210407_1928.py index 184bd66..0b64bea 100644 --- a/sigi/apps/convenios/migrations/0004_auto_20210407_1928.py +++ b/sigi/apps/convenios/migrations/0004_auto_20210407_1928.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models, migrations @@ -42,7 +41,7 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='convenio', name='casa_legislativa', - field=models.ForeignKey(verbose_name='\xf3rg\xe3o conveniado', to='casas.Orgao'), + field=models.ForeignKey(verbose_name='\xf3rg\xe3o conveniado', to='casas.Orgao', on_delete=models.CASCADE), preserve_default=True, ), migrations.AlterField( diff --git a/sigi/apps/convenios/migrations/0005_auto_20210409_0842.py b/sigi/apps/convenios/migrations/0005_auto_20210409_0842.py index aa0a6d3..78d1385 100644 --- a/sigi/apps/convenios/migrations/0005_auto_20210409_0842.py +++ b/sigi/apps/convenios/migrations/0005_auto_20210409_0842.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models, migrations diff --git a/sigi/apps/convenios/migrations/0006_auto_20210416_0841.py b/sigi/apps/convenios/migrations/0006_auto_20210416_0841.py index 3698399..f3d4fbe 100644 --- a/sigi/apps/convenios/migrations/0006_auto_20210416_0841.py +++ b/sigi/apps/convenios/migrations/0006_auto_20210416_0841.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models, migrations diff --git a/sigi/apps/convenios/migrations/0007_auto_20210416_0918.py b/sigi/apps/convenios/migrations/0007_auto_20210416_0918.py index 0daaf23..200b83c 100644 --- a/sigi/apps/convenios/migrations/0007_auto_20210416_0918.py +++ b/sigi/apps/convenios/migrations/0007_auto_20210416_0918.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models, migrations diff --git a/sigi/apps/convenios/migrations/0008_auto_20210422_1907.py b/sigi/apps/convenios/migrations/0008_auto_20210422_1907.py index f061a28..83f1aec 100644 --- a/sigi/apps/convenios/migrations/0008_auto_20210422_1907.py +++ b/sigi/apps/convenios/migrations/0008_auto_20210422_1907.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models, migrations diff --git a/sigi/apps/convenios/migrations/0009_auto_20210611_0946.py b/sigi/apps/convenios/migrations/0009_auto_20210611_0946.py index 1e0a1bb..7d39264 100644 --- a/sigi/apps/convenios/migrations/0009_auto_20210611_0946.py +++ b/sigi/apps/convenios/migrations/0009_auto_20210611_0946.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models, migrations diff --git a/sigi/apps/convenios/migrations/0010_auto_20210819_0833.py b/sigi/apps/convenios/migrations/0010_auto_20210819_0833.py index e1827de..8c8a8ac 100644 --- a/sigi/apps/convenios/migrations/0010_auto_20210819_0833.py +++ b/sigi/apps/convenios/migrations/0010_auto_20210819_0833.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models, migrations diff --git a/sigi/apps/convenios/migrations/0011_convenio_data_termino_vigencia.py b/sigi/apps/convenios/migrations/0011_convenio_data_termino_vigencia.py index c5065c1..5eb61ad 100644 --- a/sigi/apps/convenios/migrations/0011_convenio_data_termino_vigencia.py +++ b/sigi/apps/convenios/migrations/0011_convenio_data_termino_vigencia.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models, migrations diff --git a/sigi/apps/convenios/migrations/0012_auto_20210831_0844.py b/sigi/apps/convenios/migrations/0012_auto_20210831_0844.py index b4e2692..5536a9e 100644 --- a/sigi/apps/convenios/migrations/0012_auto_20210831_0844.py +++ b/sigi/apps/convenios/migrations/0012_auto_20210831_0844.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from __future__ import unicode_literals from datetime import date from django.db import models, migrations diff --git a/sigi/apps/convenios/migrations/0013_remove_convenio_duracao.py b/sigi/apps/convenios/migrations/0013_remove_convenio_duracao.py index bcc66bc..41a399c 100644 --- a/sigi/apps/convenios/migrations/0013_remove_convenio_duracao.py +++ b/sigi/apps/convenios/migrations/0013_remove_convenio_duracao.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models, migrations diff --git a/sigi/apps/convenios/migrations/0014_gescon.py b/sigi/apps/convenios/migrations/0014_gescon.py index 7fe216c..05beb81 100644 --- a/sigi/apps/convenios/migrations/0014_gescon.py +++ b/sigi/apps/convenios/migrations/0014_gescon.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models, migrations diff --git a/sigi/apps/convenios/migrations/0015_remove_convenio_search_text.py b/sigi/apps/convenios/migrations/0015_remove_convenio_search_text.py index c187381..b5b338a 100644 --- a/sigi/apps/convenios/migrations/0015_remove_convenio_search_text.py +++ b/sigi/apps/convenios/migrations/0015_remove_convenio_search_text.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models, migrations diff --git a/sigi/apps/convenios/migrations/0016_auto_20210909_0732.py b/sigi/apps/convenios/migrations/0016_auto_20210909_0732.py index 9c98cbc..f6c565f 100644 --- a/sigi/apps/convenios/migrations/0016_auto_20210909_0732.py +++ b/sigi/apps/convenios/migrations/0016_auto_20210909_0732.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models, migrations diff --git a/sigi/apps/convenios/migrations/0017_convenio_id_contrato_gescon.py b/sigi/apps/convenios/migrations/0017_convenio_id_contrato_gescon.py index 83bddab..7619a1d 100644 --- a/sigi/apps/convenios/migrations/0017_convenio_id_contrato_gescon.py +++ b/sigi/apps/convenios/migrations/0017_convenio_id_contrato_gescon.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models, migrations diff --git a/sigi/apps/convenios/migrations/0018_auto_20211208_1256.py b/sigi/apps/convenios/migrations/0018_auto_20211208_1256.py index ed6b3c2..1755956 100644 --- a/sigi/apps/convenios/migrations/0018_auto_20211208_1256.py +++ b/sigi/apps/convenios/migrations/0018_auto_20211208_1256.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models, migrations diff --git a/sigi/apps/convenios/migrations/0019_alter_anexo_arquivo_alter_anexo_descricao_and_more.py b/sigi/apps/convenios/migrations/0019_alter_anexo_arquivo_alter_anexo_descricao_and_more.py new file mode 100644 index 0000000..62ae556 --- /dev/null +++ b/sigi/apps/convenios/migrations/0019_alter_anexo_arquivo_alter_anexo_descricao_and_more.py @@ -0,0 +1,93 @@ +# Generated by Django 4.0.1 on 2022-01-12 17:40 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('convenios', '0018_auto_20211208_1256'), + ] + + operations = [ + migrations.AlterField( + model_name='anexo', + name='arquivo', + field=models.FileField(max_length=500, upload_to='apps/convenios/anexo/arquivo'), + ), + migrations.AlterField( + model_name='anexo', + name='descricao', + field=models.CharField(max_length=70, verbose_name='descrição'), + ), + migrations.AlterField( + model_name='anexo', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='convenio', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='convenio', + name='id_contrato_gescon', + field=models.CharField(blank=True, default='', editable=False, max_length=20, verbose_name='ID do contrato no Gescon'), + ), + migrations.AlterField( + model_name='equipamentoprevisto', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='gescon', + name='email', + field=models.EmailField(help_text='Caixa de e-mail para onde o relatório diário de importação será enviado.', max_length=254, verbose_name='E-mail'), + ), + migrations.AlterField( + model_name='gescon', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='projeto', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='statusconvenio', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='tiposolicitacao', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='tramitacao', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='tramitacao', + name='observacao', + field=models.CharField(blank=True, max_length=512, null=True, verbose_name='observação'), + ), + migrations.AlterField( + model_name='unidadeadministrativa', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='unidadeadministrativa', + name='nome', + field=models.CharField(max_length=100), + ), + migrations.AlterField( + model_name='unidadeadministrativa', + name='sigla', + field=models.CharField(max_length=10), + ), + ] diff --git a/sigi/apps/convenios/models.py b/sigi/apps/convenios/models.py index f55f798..86ddfa5 100644 --- a/sigi/apps/convenios/models.py +++ b/sigi/apps/convenios/models.py @@ -1,24 +1,21 @@ -#-*- coding: utf-8 -*- import re import requests from datetime import datetime, date from django.db import models from django.db.models import Q, fields from django.core.mail import send_mail -from django.core.urlresolvers import reverse +from django.urls import reverse from django.utils.translation import gettext as _ -from sigi.apps.utils import SearchField, to_ascii +from sigi.apps.utils import to_ascii from sigi.apps.casas.models import Orgao from sigi.apps.servidores.models import Servidor, Servico + class Projeto(models.Model): - """ Modelo para representar os projetos do programa - Interlegis - """ nome = models.CharField(max_length=50) sigla = models.CharField(max_length=10) - def __unicode__(self): + def __str__(self): return self.sigla class Meta: @@ -33,7 +30,7 @@ class StatusConvenio(models.Model): verbose_name = _("Estado de convenios") verbose_name_plural = _("Estados de convenios") - def __unicode__(self): + def __str__(self): return self.nome class TipoSolicitacao(models.Model): @@ -44,7 +41,7 @@ class TipoSolicitacao(models.Model): verbose_name = _("tipo de solicitação") verbose_name_plural = _("Tipos de solicitação") - def __unicode__(self): + def __str__(self): return self.nome class Convenio(models.Model): @@ -53,7 +50,6 @@ class Convenio(models.Model): on_delete=models.PROTECT, verbose_name=_('órgão conveniado') ) - # campo de busca em caixa baixa e sem acentos projeto = models.ForeignKey( Projeto, on_delete=models.PROTECT, @@ -225,21 +221,19 @@ class Convenio(models.Model): return "" return obj.get_sigad_url() - link_sigad.short_description = _("Processo no Senado") - link_sigad.allow_tags = True - def get_sigad_url(self): m = re.match( r'(?P00100|00200)\.(?P\d{6})/(?P\d{4})-\d{2}', self.num_processo_sf ) if m: - return (r'{processo}').format(processo=self.num_processo_sf,**m.groupdict()) + orgao, sequencial, ano = m.groups() + return ( + f'{self.num_processo_sf}' + ) return self.num_processo_sf def save(self, *args, **kwargs): @@ -252,55 +246,35 @@ class Convenio(models.Model): ordering = ('id',) verbose_name = _('convênio') - def __unicode__(self): - # if self.data_retorno_assinatura is not None: - # return _("Convênio {project} nº {number} assinado em {date}. Status: {status}".format( - # number=self.num_convenio, - # project=self.projeto.sigla, - # date=self.data_retorno_assinatura, - # status=self.get_status())) - # else: - # return _("Adesão ao projeto %(project)s, em %(date)s") % dict( - # project=self.projeto.sigla, - # date=self.data_adesao) - + def __str__(self): + from django.conf import settings + SDF = settings.SHORT_DATE_FORMAT + number = self.num_convenio + project=self.projeto.sigla if ((self.data_retorno_assinatura is None) and (self.equipada and self.data_termo_aceite is not None)): - return _("{project} nº {number} - equipada em {date}" - ).format(number=self.num_convenio, - date=self.data_termo_aceite.strftime('%d/%m/%Y'), - project=self.projeto.sigla) + date=self.data_termo_aceite.strftime(SDF) + return _(f"{project} nº {number} - equipada em {date}") elif self.data_retorno_assinatura is None: - return _("{project}, nº {number}, início " - "em {date}").format(number=self.num_convenio, - project=self.projeto.sigla, - date=self.data_adesao) + date = self.data_adesao.strftime(SDF) if self.data_adesao else "" + return _(f"{project}, nº {number}, início em {date}") if ((self.data_retorno_assinatura is not None) and not (self.equipada and self.data_termo_aceite is not None)): - return _("{project}, nº {number}, inicio em " - "{date}. Status: {status}").format( - number=self.num_convenio, - project=self.projeto.sigla, - date=self.data_retorno_assinatura.strftime('%d/%m/%Y'), - status=self.get_status()) + date=self.data_retorno_assinatura.strftime(SDF) + status=self.get_status() + return _( + f"{project}, nº {number}, inicio em {date}. Status: {status}" + ) if ((self.data_retorno_assinatura is not None) and (self.equipada and self.data_termo_aceite is not None)): - return _("{project}, nº {number}, início em {date}" - " e equipada em {equipped_date}. Status: {status}" - ).format(number=self.num_convenio, - project=self.projeto.sigla, - date=self.data_retorno_assinatura.strftime( - '%d/%m/%Y'), - equipped_date=self.data_termo_aceite.strftime( - '%d/%m/%Y'), - status=self.get_status()) + date=self.data_retorno_assinatura.strftime(SDF) + equipped_date=self.data_termo_aceite.strftime(SDF) + return _( + f"{project}, nº {number}, início em {date} e equipada em " + f"{equipped_date}. Status: {self.get_status()}" + ) class EquipamentoPrevisto(models.Model): - - """ Modelo utilizado para registrar os equipamentos - disponibilizados para as Casas Legislativas - (foi usado na prmeira etapa do programa) - """ convenio = models.ForeignKey( Convenio, on_delete=models.CASCADE, @@ -316,15 +290,10 @@ class EquipamentoPrevisto(models.Model): verbose_name = _('equipamento previsto') verbose_name_plural = _('equipamentos previstos') - def __unicode__(self): - return '%s %s(s)' % (self.quantidade, self.equipamento) - + def __str__(self): + return _(f"{self.quantidade} {self.equipamento}(s)") class Anexo(models.Model): - - """ Modelo para giardar os documentos gerados - no processo de convênio - """ convenio = models.ForeignKey( Convenio, on_delete=models.CASCADE, @@ -332,7 +301,7 @@ class Anexo(models.Model): ) # caminho no sistema para o documento anexo arquivo = models.FileField(upload_to='apps/convenios/anexo/arquivo', max_length=500) - descricao = models.CharField(_('descrição'), max_length='70') + descricao = models.CharField(_('descrição'), max_length=70) data_pub = models.DateTimeField( _('data da publicação do anexo'), default=datetime.now @@ -341,28 +310,17 @@ class Anexo(models.Model): class Meta: ordering = ('-data_pub',) - def __unicode__(self): - return unicode("%s publicado em %s" % (self.descricao, self.data_pub)) - + def __str__(self): + return _(f"{self.descricao} publicado em {self.data_pub}") class UnidadeAdministrativa(models.Model): + sigla = models.CharField(max_length=10) + nome = models.CharField(max_length=100) - """ Modelo para representar uma Unidade Administrativa - que pode ser um servivo do próprio Interlegis, assim como - uma unidade do Senado Federal - """ - sigla = models.CharField(max_length='10') - nome = models.CharField(max_length='100') - - def __unicode__(self): - return unicode(self.sigla) - + def __str__(self): + return self.sigla class Tramitacao(models.Model): - - """ Modelo para registrar as vias do processo de convênio e a Unidade - responsável pelo tramite (ex. colher assinaturas do secretário do senado) - """ convenio = models.ForeignKey( Convenio, on_delete=models.CASCADE, @@ -376,7 +334,7 @@ class Tramitacao(models.Model): data = models.DateField() observacao = models.CharField( _('observação'), - max_length='512', + max_length=512, null=True, blank=True, ) @@ -384,12 +342,12 @@ class Tramitacao(models.Model): class Meta: verbose_name_plural = _('Tramitações') - def __unicode__(self): - in_date = _("em %(date)s") % dict(date=self.data) # for focused translation - result = "%s %s" % (self.unid_admin, in_date) + def __str__(self): + in_date = _(f"em {self.data}") # for focused translation + result = f"{self.unid_admin} {in_date}" if self.observacao: - result = result + " (%s)" % (self.observacao) - return unicode(result) # XXX is this unicode(...) really necessary??? + result = f"{result} ({self.observacao})" + return result class Gescon(models.Model): url_gescon = models.URLField( @@ -435,7 +393,7 @@ class Gescon(models.Model): verbose_name = _("Configuração do Gescon") verbose_name_plural = _("Configurações do Gescon") - def __unicode__(self): + def __str__(self): return self.url_gescon def save(self, *args, **kwargs): diff --git a/sigi/apps/convenios/reports.py b/sigi/apps/convenios/reports.py index 5c90551..f0893ca 100644 --- a/sigi/apps/convenios/reports.py +++ b/sigi/apps/convenios/reports.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from django.utils.translation import gettext as _ from geraldo import ReportBand, ObjectValue, Label, ReportGroup, FIELD_ACTION_SUM from reportlab.lib.units import cm diff --git a/sigi/apps/convenios/tests.py b/sigi/apps/convenios/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/sigi/apps/convenios/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/sigi/apps/convenios/urls.py b/sigi/apps/convenios/urls.py index 1986ecc..c3870d7 100644 --- a/sigi/apps/convenios/urls.py +++ b/sigi/apps/convenios/urls.py @@ -1,4 +1,3 @@ -# coding: utf-8 from django.conf.urls import patterns, url diff --git a/sigi/apps/convenios/views.py b/sigi/apps/convenios/views.py index 79b7a3d..62a8e26 100644 --- a/sigi/apps/convenios/views.py +++ b/sigi/apps/convenios/views.py @@ -1,30 +1,29 @@ -#-*- coding:utf-8 -*- import csv import datetime from django.contrib import messages from django.http.response import HttpResponseForbidden -import ho.pisa as pisa +# import ho.pisa as pisa from django.conf import settings from django.core.paginator import Paginator, InvalidPage, EmptyPage from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import render, get_list_or_404 from django.template import Context, loader from django.utils.translation import gettext as _ -from geraldo.generators import PDFGenerator +# from geraldo.generators import PDFGenerator +from django.contrib.auth.decorators import login_required from sigi.apps.casas.models import Orgao from sigi.apps.contatos.models import UnidadeFederativa from sigi.apps.convenios.models import Convenio, Gescon, Projeto -from sigi.apps.convenios.reports import (ConvenioReport, - ConvenioReportSemAceite, - ConvenioPorCMReport, - ConvenioPorALReport, - ConvenioReportSemAceiteAL, - ConvenioReportSemAceiteCM) -from django.contrib.auth.decorators import login_required - - +# from sigi.apps.convenios.reports import (ConvenioReport, +# ConvenioReportSemAceite, +# ConvenioPorCMReport, +# ConvenioPorALReport, +# ConvenioReportSemAceiteAL, +# ConvenioReportSemAceiteCM) + +""" def query_ordena(qs, o, ot): list_display = ('num_convenio', 'casa_legislativa', 'data_adesao', 'data_retorno_assinatura', 'data_termo_aceite', @@ -37,7 +36,7 @@ def query_ordena(qs, o, ot): else: qs = qs.order_by("-" + aux) return qs - +""" def normaliza_data(get, nome_param): import re if nome_param in get: @@ -50,7 +49,7 @@ def normaliza_data(get, nome_param): elif re.match('^\d*\D\d*$', value): # Year and month # Complete with 1st day of month get[nome_param] = '%s-01' % value - +""" def get_for_qs(get, qs): kwargs = {} ids = 0 @@ -82,9 +81,6 @@ def get_for_qs(get, qs): def carrinhoOrGet_for_qs(request): - """ - Verifica se existe convênios na sessão se não verifica get e retorna qs correspondente. - """ if 'carrinho_convenios' in request.session: ids = request.session['carrinho_convenios'] qs = Convenio.objects.filter(pk__in=ids) @@ -387,4 +383,5 @@ def importar_gescon(request): if action == 'importar': gescon.importa_contratos() - return render(request, "convenios/importar_gescon.html", {'gescon': gescon}) \ No newline at end of file + return render(request, "convenios/importar_gescon.html", {'gescon': gescon}) +""" \ No newline at end of file diff --git a/sigi/settings/base.py b/sigi/settings/base.py index 8a97af3..d2afb54 100644 --- a/sigi/settings/base.py +++ b/sigi/settings/base.py @@ -22,6 +22,7 @@ INSTALLED_APPS = [ 'sigi.apps.servidores', 'sigi.apps.contatos', 'sigi.apps.casas', + 'sigi.apps.convenios', 'sigi.apps.inventario', 'django_bootstrap5', 'localflavor',