From df88dc282c228fd2a74093009989d07bec99aa77 Mon Sep 17 00:00:00 2001 From: LeandroJatai Date: Fri, 5 Aug 2022 14:25:12 -0300 Subject: [PATCH] =?UTF-8?q?impl=20vinculo=20em=20lote=20de=20docadm=20com?= =?UTF-8?q?=20mat=C3=A9rias?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/protocoloadm/forms.py | 33 ++++++++- sapl/protocoloadm/urls.py | 5 +- sapl/protocoloadm/views.py | 68 ++++++----------- .../em_lote/vinculodocadminmateria.html | 74 +++++++++++++++++++ .../vinculodocadminmateria_list.html | 14 ++++ 5 files changed, 142 insertions(+), 52 deletions(-) create mode 100644 sapl/templates/protocoloadm/em_lote/vinculodocadminmateria.html create mode 100644 sapl/templates/protocoloadm/vinculodocadminmateria_list.html diff --git a/sapl/protocoloadm/forms.py b/sapl/protocoloadm/forms.py index 601d430ab..744d30e5e 100644 --- a/sapl/protocoloadm/forms.py +++ b/sapl/protocoloadm/forms.py @@ -1801,7 +1801,32 @@ class VinculoDocAdminMateriaForm(ModelForm): return cleaned_data def save(self, commit=False): - anexada = super().save(commit) - anexada.materia = self.cleaned_data['materia'] - anexada.save() - return anexada + vinculo = super().save(commit) + vinculo.materia = self.cleaned_data['materia'] + vinculo.save() + return vinculo + + +class VinculoDocAdminMateriaEmLoteFilterSet(django_filters.FilterSet): + + class Meta(FilterOverridesMetaMixin): + model = MateriaLegislativa + fields = ['tipo', 'data_apresentacao'] + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + self.filters['tipo'].label = 'Tipo de Matéria' + self.filters['data_apresentacao'].label = 'Data (Inicial - Final)' + + self.form.fields['tipo'].required = True + self.form.fields['data_apresentacao'].required = True + + row1 = to_row([('tipo', 12)]) + row2 = to_row([('data_apresentacao', 12)]) + + self.form.helper = SaplFormHelper() + self.form.helper.form_method = 'GET' + self.form.helper.layout = Layout( + Fieldset(_('Pesquisa de Matérias'), + row1, row2, form_actions(label='Pesquisar'))) diff --git a/sapl/protocoloadm/urls.py b/sapl/protocoloadm/urls.py index d40f83192..0d0290ac5 100644 --- a/sapl/protocoloadm/urls.py +++ b/sapl/protocoloadm/urls.py @@ -26,7 +26,8 @@ from sapl.protocoloadm.views import (AcompanhamentoDocumentoView, PrimeiraTramitacaoEmLoteAdmView, TramitacaoEmLoteAdmView, apaga_protocolos_view, - VinculoDocAdminMateriaCrud) + VinculoDocAdminMateriaCrud, + VinculoDocAdminMateriaEmLoteView) from .apps import AppConfig @@ -48,6 +49,8 @@ urlpatterns_documento_administrativo = [ url(r'^docadm/(?P\d+)/anexado_em_lote', DocumentoAnexadoEmLoteView.as_view(), name='anexado_em_lote'), + url(r'^docadm/(?P\d+)/vinculo-em-lote', VinculoDocAdminMateriaEmLoteView.as_view(), + name='vinculodocadminmateria_em_lote'), ] urlpatterns_protocolo = [ diff --git a/sapl/protocoloadm/views.py b/sapl/protocoloadm/views.py index 1d7c59cc2..869c6d240 100755 --- a/sapl/protocoloadm/views.py +++ b/sapl/protocoloadm/views.py @@ -35,7 +35,8 @@ from sapl.crud.base import (Crud, CrudAux, MasterDetailCrud, make_pagination, from sapl.materia.models import MateriaLegislativa, TipoMateriaLegislativa, UnidadeTramitacao from sapl.materia.views import gerar_pdf_impressos from sapl.parlamentares.models import Legislatura, Parlamentar -from sapl.protocoloadm.forms import VinculoDocAdminMateriaForm +from sapl.protocoloadm.forms import VinculoDocAdminMateriaForm,\ + VinculoDocAdminMateriaEmLoteFilterSet from sapl.protocoloadm.models import Protocolo, DocumentoAdministrativo,\ VinculoDocAdminMateria from sapl.relatorios.views import relatorio_doc_administrativos @@ -1804,22 +1805,20 @@ class VinculoDocAdminMateriaCrud(MasterDetailCrud): return context -""" - class VinculoDocAdminMateriaEmLoteView(PermissionRequiredMixin, FilterView): - filterset_class = AnexadaEmLoteFilterSet - template_name = 'materia/em_lote/anexada.html' - permission_required = ('materia.add_documentoacessorio',) + filterset_class = VinculoDocAdminMateriaEmLoteFilterSet + template_name = 'protocoloadm/em_lote/vinculodocadminmateria.html' + permission_required = ('protocoloadm.add_documentoadministrativo',) def get_context_data(self, **kwargs): - context = super(MateriaAnexadaEmLoteView, + context = super(VinculoDocAdminMateriaEmLoteView, self).get_context_data(**kwargs) context['root_pk'] = self.kwargs['pk'] - context['subnav_template_name'] = 'materia/subnav.yaml' + context['subnav_template_name'] = 'protocoloadm/subnav.yaml' - context['title'] = _('Matérias Anexadas em Lote') + context['title'] = _('Matérias Vinculadas em Lote') # Verifica se os campos foram preenchidos if not self.request.GET.get('tipo', " "): @@ -1843,38 +1842,14 @@ class VinculoDocAdminMateriaEmLoteView(PermissionRequiredMixin, FilterView): else: context['object_list'] = context['object_list'].order_by( 'numero', '-ano') - principal = MateriaLegislativa.objects.get(pk=self.kwargs['pk']) + documento = DocumentoAdministrativo.objects.get( + pk=self.kwargs['pk']) not_list = [self.kwargs['pk']] + \ - [m for m in principal.materia_principal_set.all( - ).values_list('materia_anexada_id', flat=True)] + [m for m in documento.materiasvinculadas.values_list( + 'id', flat=True)] context['object_list'] = context['object_list'].exclude( pk__in=not_list) - context['temp_object_list'] = context['object_list'] - context['object_list'] = [] - for obj in context['temp_object_list']: - materia_anexada = obj - ciclico = False - anexadas_anexada = Anexada.objects.filter( - materia_principal=materia_anexada - ) - - while anexadas_anexada and not ciclico: - anexadas = [] - - for anexa in anexadas_anexada: - - if principal == anexa.materia_anexada: - ciclico = True - else: - for a in Anexada.objects.filter(materia_principal=anexa.materia_anexada): - anexadas.append(a) - - anexadas_anexada = anexadas - - if not ciclico: - context['object_list'].append(obj) - context['numero_res'] = len(context['object_list']) context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' @@ -1912,20 +1887,19 @@ class VinculoDocAdminMateriaEmLoteView(PermissionRequiredMixin, FilterView): messages.add_message(request, messages.ERROR, msg) return self.get(request, self.kwargs) - principal = MateriaLegislativa.objects.get(pk=kwargs['pk']) + documento = DocumentoAdministrativo.objects.get(pk=kwargs['pk']) for materia in MateriaLegislativa.objects.filter(id__in=marcadas): - anexada = Anexada() - anexada.materia_principal = principal - anexada.materia_anexada = materia - anexada.data_anexacao = data_anexacao - anexada.data_desanexacao = data_desanexacao - anexada.save() + v = VinculoDocAdminMateria() + v.documento = documento + v.materia = materia + v.data_anexacao = data_anexacao + v.data_desanexacao = data_desanexacao + v.save() - msg = _('Matéria(s) anexada(s).') + msg = _('Matéria(s) vinculadas(s).') messages.add_message(request, messages.SUCCESS, msg) - success_url = reverse('sapl.materia:anexada_list', + success_url = reverse('sapl.protocoloadm:vinculodocadminmateria_list', kwargs={'pk': kwargs['pk']}) return HttpResponseRedirect(success_url) -""" diff --git a/sapl/templates/protocoloadm/em_lote/vinculodocadminmateria.html b/sapl/templates/protocoloadm/em_lote/vinculodocadminmateria.html new file mode 100644 index 000000000..e4393b805 --- /dev/null +++ b/sapl/templates/protocoloadm/em_lote/vinculodocadminmateria.html @@ -0,0 +1,74 @@ +{% extends "crud/detail.html" %} +{% load i18n crispy_forms_tags %} +{% block actions %}{% endblock %} + +{% block detail_content %} + {% if not show_results %} + {% crispy filter.form %} + {% endif %} + {% if show_results %} + {% if numero_res > 0 %} + {% if numero_res == 1 %} +

{% trans 'Pesquisa concluída com sucesso! Foi encontrada 1 matéria.'%}

+ {% else %} +

Foram encontradas {{ numero_res }} matérias.

+ {% endif %} +
+ {% csrf_token %} +
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+ Matérias para Vincular em Lote + +
+
+ +
+
+ + + {% for materia in object_list %} + + + + {% endfor %} + +
Matéria
+ +
+
+ +
+ {% else %} +

Nenhuma matéria encontrada.

+ {% endif %} + {% endif %} +{% endblock detail_content %} + +{% block extra_js %} + +{% endblock %} diff --git a/sapl/templates/protocoloadm/vinculodocadminmateria_list.html b/sapl/templates/protocoloadm/vinculodocadminmateria_list.html new file mode 100644 index 000000000..791d62557 --- /dev/null +++ b/sapl/templates/protocoloadm/vinculodocadminmateria_list.html @@ -0,0 +1,14 @@ +{% extends "crud/list.html" %} +{% load i18n %} +{% load common_tags %} + + +{% block more_buttons %} + +{% if perms|get_add_perm:view %} + + {% trans "Adicionar Vínculos em Lote" %} + +{% endif %} + +{% endblock more_buttons %}