Browse Source

impl vinculo em lote de docadm com matérias

pull/3586/head
LeandroJatai 3 years ago
parent
commit
df88dc282c
  1. 33
      sapl/protocoloadm/forms.py
  2. 5
      sapl/protocoloadm/urls.py
  3. 68
      sapl/protocoloadm/views.py
  4. 74
      sapl/templates/protocoloadm/em_lote/vinculodocadminmateria.html
  5. 14
      sapl/templates/protocoloadm/vinculodocadminmateria_list.html

33
sapl/protocoloadm/forms.py

@ -1801,7 +1801,32 @@ class VinculoDocAdminMateriaForm(ModelForm):
return cleaned_data return cleaned_data
def save(self, commit=False): def save(self, commit=False):
anexada = super().save(commit) vinculo = super().save(commit)
anexada.materia = self.cleaned_data['materia'] vinculo.materia = self.cleaned_data['materia']
anexada.save() vinculo.save()
return anexada 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')))

5
sapl/protocoloadm/urls.py

@ -26,7 +26,8 @@ from sapl.protocoloadm.views import (AcompanhamentoDocumentoView,
PrimeiraTramitacaoEmLoteAdmView, PrimeiraTramitacaoEmLoteAdmView,
TramitacaoEmLoteAdmView, TramitacaoEmLoteAdmView,
apaga_protocolos_view, apaga_protocolos_view,
VinculoDocAdminMateriaCrud) VinculoDocAdminMateriaCrud,
VinculoDocAdminMateriaEmLoteView)
from .apps import AppConfig from .apps import AppConfig
@ -48,6 +49,8 @@ urlpatterns_documento_administrativo = [
url(r'^docadm/(?P<pk>\d+)/anexado_em_lote', DocumentoAnexadoEmLoteView.as_view(), url(r'^docadm/(?P<pk>\d+)/anexado_em_lote', DocumentoAnexadoEmLoteView.as_view(),
name='anexado_em_lote'), name='anexado_em_lote'),
url(r'^docadm/(?P<pk>\d+)/vinculo-em-lote', VinculoDocAdminMateriaEmLoteView.as_view(),
name='vinculodocadminmateria_em_lote'),
] ]
urlpatterns_protocolo = [ urlpatterns_protocolo = [

68
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.models import MateriaLegislativa, TipoMateriaLegislativa, UnidadeTramitacao
from sapl.materia.views import gerar_pdf_impressos from sapl.materia.views import gerar_pdf_impressos
from sapl.parlamentares.models import Legislatura, Parlamentar 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,\ from sapl.protocoloadm.models import Protocolo, DocumentoAdministrativo,\
VinculoDocAdminMateria VinculoDocAdminMateria
from sapl.relatorios.views import relatorio_doc_administrativos from sapl.relatorios.views import relatorio_doc_administrativos
@ -1804,22 +1805,20 @@ class VinculoDocAdminMateriaCrud(MasterDetailCrud):
return context return context
"""
class VinculoDocAdminMateriaEmLoteView(PermissionRequiredMixin, FilterView): class VinculoDocAdminMateriaEmLoteView(PermissionRequiredMixin, FilterView):
filterset_class = AnexadaEmLoteFilterSet filterset_class = VinculoDocAdminMateriaEmLoteFilterSet
template_name = 'materia/em_lote/anexada.html' template_name = 'protocoloadm/em_lote/vinculodocadminmateria.html'
permission_required = ('materia.add_documentoacessorio',) permission_required = ('protocoloadm.add_documentoadministrativo',)
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(MateriaAnexadaEmLoteView, context = super(VinculoDocAdminMateriaEmLoteView,
self).get_context_data(**kwargs) self).get_context_data(**kwargs)
context['root_pk'] = self.kwargs['pk'] 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 # Verifica se os campos foram preenchidos
if not self.request.GET.get('tipo', " "): if not self.request.GET.get('tipo', " "):
@ -1843,38 +1842,14 @@ class VinculoDocAdminMateriaEmLoteView(PermissionRequiredMixin, FilterView):
else: else:
context['object_list'] = context['object_list'].order_by( context['object_list'] = context['object_list'].order_by(
'numero', '-ano') 'numero', '-ano')
principal = MateriaLegislativa.objects.get(pk=self.kwargs['pk']) documento = DocumentoAdministrativo.objects.get(
pk=self.kwargs['pk'])
not_list = [self.kwargs['pk']] + \ not_list = [self.kwargs['pk']] + \
[m for m in principal.materia_principal_set.all( [m for m in documento.materiasvinculadas.values_list(
).values_list('materia_anexada_id', flat=True)] 'id', flat=True)]
context['object_list'] = context['object_list'].exclude( context['object_list'] = context['object_list'].exclude(
pk__in=not_list) 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['numero_res'] = len(context['object_list'])
context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' 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) messages.add_message(request, messages.ERROR, msg)
return self.get(request, self.kwargs) 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): for materia in MateriaLegislativa.objects.filter(id__in=marcadas):
anexada = Anexada() v = VinculoDocAdminMateria()
anexada.materia_principal = principal v.documento = documento
anexada.materia_anexada = materia v.materia = materia
anexada.data_anexacao = data_anexacao v.data_anexacao = data_anexacao
anexada.data_desanexacao = data_desanexacao v.data_desanexacao = data_desanexacao
anexada.save() v.save()
msg = _('Matéria(s) anexada(s).') msg = _('Matéria(s) vinculadas(s).')
messages.add_message(request, messages.SUCCESS, msg) 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']}) kwargs={'pk': kwargs['pk']})
return HttpResponseRedirect(success_url) return HttpResponseRedirect(success_url)
"""

74
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 %}
<h3 style="text-align: right;">{% trans 'Pesquisa concluída com sucesso! Foi encontrada 1 matéria.'%}</h3>
{% else %}
<h3 style="text-align: right;">Foram encontradas {{ numero_res }} matérias.</h3>
{% endif %}
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
<fieldset>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label>Data Anexação*</label><input type="text" name="data_anexacao" class="form-control dateinput" required="True">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label>Data Desanexação</label><input type="text" name="data_desanexacao" class="form-control dateinput">
</div>
</div>
</div>
</fieldset>
<br />
<fieldset>
<legend>Matérias para Vincular em Lote</legend>
<table class="table table-striped table-hover">
<div class="controls">
<div class="checkbox">
<label for="id_check_all"><input type="checkbox" id="id_check_all" onchange="checkAll(this)" /> Marcar/Desmarcar Todos</label>
</div>
</div>
<thead><tr><th>Matéria</th></tr></thead>
<tbody>
{% for materia in object_list %}
<tr>
<td class="p-0">
<label for="mat_{{materia.id}}" class="d-flex w-100 p-3">
<input type="checkbox" id="mat_{{materia.id}}" name="materia_id" value="{{materia.id}}" {% if check %} checked {% endif %}/>
{{materia.tipo.sigla}} {{materia.numero}}/{{materia.ano}} - {{materia.tipo.descricao}}
</label>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</fieldset>
<input type="submit" value="Salvar" class="btn btn-primary"S>
</form>
{% else %}
<tr><td><h3 style="text-align: right;">Nenhuma matéria encontrada.</h3></td></tr>
{% endif %}
{% endif %}
{% endblock detail_content %}
{% block extra_js %}
<script language="JavaScript">
function checkAll(elem) {
let checkboxes = document.getElementsByName('materia_id');
for (let i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].type == 'checkbox')
checkboxes[i].checked = elem.checked;
}
}
</script>
{% endblock %}

14
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 %}
<a href="{% url 'sapl.protocoloadm:vinculodocadminmateria_em_lote' root_pk %}" class="btn btn-outline-primary">
{% trans "Adicionar Vínculos em Lote" %}
</a>
{% endif %}
{% endblock more_buttons %}
Loading…
Cancel
Save