diff --git a/sapl/materia/forms.py b/sapl/materia/forms.py index 05e3d3161..a658c7a5f 100644 --- a/sapl/materia/forms.py +++ b/sapl/materia/forms.py @@ -1137,6 +1137,29 @@ class AcessorioEmLoteFilterSet(django_filters.FilterSet): Fieldset(_('Documentos Acessórios em Lote'), row1, row2, form_actions(label='Pesquisar'))) +class AnexadaEmLoteFilterSet(django_filters.FilterSet): + + class Meta(FilterOverridesMetaMixin): + model = MateriaLegislativa + fields = ['tipo', 'data_apresentacao'] + + def __init__(self, *args, **kwargs): + super(AnexadaEmLoteFilterSet, self).__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(_('Matéria Anexada em Lote'), + row1, row2, form_actions(label='Pesquisar'))) + class PrimeiraTramitacaoEmLoteFilterSet(django_filters.FilterSet): diff --git a/sapl/materia/urls.py b/sapl/materia/urls.py index e446e6a64..4533d3883 100644 --- a/sapl/materia/urls.py +++ b/sapl/materia/urls.py @@ -8,6 +8,7 @@ from sapl.materia.views import (AcompanhamentoConfirmarView, CriarProtocoloMateriaView, DespachoInicialCrud, DocumentoAcessorioCrud, DocumentoAcessorioEmLoteView, + MateriaAnexadaEmLoteView, EtiquetaPesquisaView, FichaPesquisaView, FichaSelecionaView, ImpressosView, LegislacaoCitadaCrud, MateriaAssuntoCrud, @@ -93,6 +94,8 @@ urlpatterns_materia = [ url(r'^materia/acessorio-em-lote', DocumentoAcessorioEmLoteView.as_view(), name='acessorio_em_lote'), + url(r'^materia/anexada-em-lote', MateriaAnexadaEmLoteView.as_view(), + name='anexada_em_lote'), url(r'^materia/primeira-tramitacao-em-lote', PrimeiraTramitacaoEmLoteView.as_view(), name='primeira_tramitacao_em_lote'), diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 3c7b1df6f..e31b93086 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -51,6 +51,7 @@ from sapl.utils import (YES_NO_CHOICES, autor_label, autor_modal, SEPARADOR_HASH show_results_filter_set, mail_service_configured) from .forms import (AcessorioEmLoteFilterSet, AcompanhamentoMateriaForm, + AnexadaEmLoteFilterSet, AdicionarVariasAutoriasFilterSet, DespachoInicialForm, DocumentoAcessorioForm, EtiquetaPesquisaForm, FichaPesquisaForm, FichaSelecionaForm, MateriaAssuntoForm, @@ -1996,6 +1997,58 @@ class DocumentoAcessorioEmLoteView(PermissionRequiredMixin, FilterView): messages.add_message(request, messages.SUCCESS, msg) return self.get(request, self.kwargs) +class MateriaAnexadaEmLoteView(PermissionRequiredMixin, FilterView): + filterset_class = AnexadaEmLoteFilterSet + template_name = 'materia/em_lote/anexada.html' + permission_required = ('materia.add_documentoacessorio',) + + def get_context_data(self, **kwargs): + context = super(MateriaAnexadaEmLoteView, + self).get_context_data(**kwargs) + + context['title'] = _('Matérias Anexadas em Lote') + # Verifica se os campos foram preenchidos + if not self.filterset.form.is_valid(): + return context + + qr = self.request.GET.copy() + # context['tipos_docs'] = TipoDocumento.objects.all() + import ipdb; ipdb.set_trace() + context['object_list'] = context['object_list'].order_by( + 'ano', 'numero') + context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' + + context['show_results'] = show_results_filter_set(qr) + + return context + + def post(self, request, *args, **kwargs): + marcadas = request.POST.getlist('materia_id') + + if len(marcadas) == 0: + msg = _('Nenhuma máteria foi selecionada.') + messages.add_message(request, messages.ERROR, msg) + return self.get(request, self.kwargs) + + tipo = TipoDocumento.objects.get(descricao=request.POST['tipo']) + + tz = timezone.get_current_timezone() + + for materia_id in marcadas: + doc = DocumentoAcessorio() + doc.materia_id = materia_id + doc.tipo = tipo + doc.arquivo = request.FILES['arquivo'] + doc.nome = request.POST['nome'] + doc.data = tz.localize(datetime.strptime( + request.POST['data'], "%d/%m/%Y")) + doc.autor = request.POST['autor'] + doc.ementa = request.POST['ementa'] + doc.save() + msg = _('Documento(s) criado(s).') + messages.add_message(request, messages.SUCCESS, msg) + return self.get(request, self.kwargs) + class PrimeiraTramitacaoEmLoteView(PermissionRequiredMixin, FilterView): filterset_class = PrimeiraTramitacaoEmLoteFilterSet diff --git a/sapl/templates/materia/em_lote/anexada.html b/sapl/templates/materia/em_lote/anexada.html new file mode 100644 index 000000000..738010083 --- /dev/null +++ b/sapl/templates/materia/em_lote/anexada.html @@ -0,0 +1,117 @@ +{% 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 object_list.count > 0 %} + {% if object_list.count == 1 %} +

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

+ {% else %} +

{% blocktrans with object_list.count as total_materias %}Foram encontradas {{total_materias}} matérias.{% endblocktrans %}

+ {% endif %} +
+ {% csrf_token %} +
+ Documento Acessório +
+
+
+ + +
+
+ +
+
+ + +
+
+ +
+
+ + +
+
+
+ +
+
+
+ + +
+
+
+ +
+
+
+ + +
+
+
+ +
+
+
+ + +
+
+
+
+ +
+ +
+ Matérias para inclusão do Documento Acessório + +
+
+ +
+
+ + + + + {% for materia in object_list %} + + + + {% endfor %} + +
Matéria
+ + {{materia.tipo.sigla}} {{materia.numero}}/{{materia.ano}} - {{materia.tipo.descricao}} +
+
+ +
+ {% else %} +

Nenhuma matéria encontrada.

+ {% endif %} + {% endif %} +{% endblock detail_content %} +{% block extra_js %} + +{% endblock %}