From 6b9eca7fd88d92363e7f6eea6959159750e7e087 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Wed, 14 Sep 2016 16:15:53 -0300 Subject: [PATCH 1/6] =?UTF-8?q?Inicia=20tela=20de=20pesquisa=20de=20mat?= =?UTF-8?q?=C3=A9rias?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/materia/forms.py | 31 +++++++++ sapl/materia/urls.py | 8 ++- sapl/materia/views.py | 55 +++++++++++++++- sapl/templates/materia/acessorio_lote.html | 73 ++++++++++++++++++++++ 4 files changed, 162 insertions(+), 5 deletions(-) create mode 100644 sapl/templates/materia/acessorio_lote.html diff --git a/sapl/materia/forms.py b/sapl/materia/forms.py index 851dd51ba..4ef42e922 100644 --- a/sapl/materia/forms.py +++ b/sapl/materia/forms.py @@ -755,3 +755,34 @@ class AutorForm(ModelForm): u.groups.add(grupo) return autor + + +class AcessorioEmLoteFilterSet(django_filters.FilterSet): + + filter_overrides = {models.DateField: { + 'filter_class': django_filters.DateFromToRangeFilter, + 'extra': lambda f: { + 'label': '%s (%s)' % (f.verbose_name, _('Inicial - Final')), + 'widget': RangeWidgetOverride} + }} + + class Meta: + model = MateriaLegislativa + fields = ['tipo', 'data_apresentacao'] + + def __init__(self, *args, **kwargs): + super(AcessorioEmLoteFilterSet, 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 = FormHelper() + self.form.helper.form_method = 'GET' + self.form.helper.layout = Layout( + Fieldset(_('Documentos Acessórios em Lote'), + row1, row2, form_actions(save_label='Pesquisar'))) diff --git a/sapl/materia/urls.py b/sapl/materia/urls.py index a0584d94d..10bbbe08d 100644 --- a/sapl/materia/urls.py +++ b/sapl/materia/urls.py @@ -5,8 +5,9 @@ from sapl.materia.views import (AcompanhamentoConfirmarView, AcompanhamentoMateriaView, AnexadaCrud, AutorCrud, AutoriaCrud, ConfirmarEmailView, ConfirmarProposicao, DespachoInicialCrud, - DocumentoAcessorioCrud, LegislacaoCitadaCrud, - MateriaLegislativaCrud, + DocumentoAcessorioCrud, + DocumentoAcessorioEmLoteView, + LegislacaoCitadaCrud, MateriaLegislativaCrud, MateriaLegislativaPesquisaView, MateriaTaView, NumeracaoCrud, OrgaoCrud, OrigemCrud, ProposicaoCrud, ProposicaoDevolvida, @@ -86,4 +87,7 @@ urlpatterns = [ url(r'^materia/(?P\d+)/acompanhar-excluir$', AcompanhamentoExcluirView.as_view(), name='acompanhar_excluir'), + + url(r'^acessorio-em-lote', DocumentoAcessorioEmLoteView.as_view(), + name='acessorio_em_lote'), ] diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 4f7966118..3ddd1e946 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -4,7 +4,6 @@ from string import ascii_letters, digits from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Button -from django.db.models import Q from django.conf import settings from django.contrib import messages from django.contrib.auth.mixins import PermissionRequiredMixin @@ -13,6 +12,7 @@ from django.contrib.auth.tokens import default_token_generator from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist from django.core.mail import send_mail from django.core.urlresolvers import reverse +from django.db.models import Q from django.http.response import HttpResponseRedirect from django.shortcuts import redirect from django.template import Context, loader @@ -34,8 +34,9 @@ from sapl.utils import (autor_label, autor_modal, gerar_hash_arquivo, get_base_url, permissao_tb_aux, permissoes_autor, permissoes_materia, permissoes_protocoloadm) -from .forms import (AcompanhamentoMateriaForm, AnexadaForm, AutorForm, - AutoriaForm, ConfirmarProposicaoForm, DespachoInicialForm, +from .forms import (AcessorioEmLoteFilterSet, AcompanhamentoMateriaForm, + AnexadaForm, AutorForm, AutoriaForm, + ConfirmarProposicaoForm, DespachoInicialForm, DocumentoAcessorioForm, LegislacaoCitadaForm, MateriaLegislativaFilterSet, NumeracaoForm, ProposicaoForm, ReceberProposicaoForm, RelatoriaForm, TramitacaoForm, @@ -1246,3 +1247,51 @@ def do_envia_email_tramitacao(request, materia): enviar_emails(sender, recipients, messages) return None + + +class DocumentoAcessorioEmLoteView(PermissionRequiredMixin, FilterView): + filterset_class = AcessorioEmLoteFilterSet + template_name = 'materia/acessorio_lote.html' + + def get_context_data(self, **kwargs): + context = super(DocumentoAcessorioEmLoteView, + self).get_context_data(**kwargs) + + context['title'] = _('Documentos Acessórios em Lote') + qr = self.request.GET.copy() + context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' + return context + + # def post(self, request, *args, **kwargs): + # marcadas = request.POST.getlist('materia_id') + # + # for m in marcadas: + # try: + # tipo_votacao = request.POST['tipo_votacao_%s' % m] + # except MultiValueDictKeyError: + # msg = _('Formulário Inválido. Você esqueceu de selecionar ' + + # 'o tipo de votação de %s' % + # MateriaLegislativa.objects.get(id=m)) + # messages.add_message(request, messages.ERROR, msg) + # return self.get(request, self.kwargs) + # + # if tipo_votacao: + # lista_materias_expediente = ExpedienteMateria.objects.filter( + # sessao_plenaria_id=self.kwargs[ + # 'pk']) + # + # materia = MateriaLegislativa.objects.get(id=m) + # + # expediente = ExpedienteMateria() + # expediente.sessao_plenaria_id = self.kwargs['pk'] + # expediente.materia_id = materia.id + # if lista_materias_expediente: + # posicao = lista_materias_expediente.last().numero_ordem + 1 + # expediente.numero_ordem = posicao + # else: + # expediente.numero_ordem = 1 + # expediente.data_ordem = datetime.now() + # expediente.tipo_votacao = request.POST['tipo_votacao_%s' % m] + # expediente.save() + # + # return self.get(request, self.kwargs) diff --git a/sapl/templates/materia/acessorio_lote.html b/sapl/templates/materia/acessorio_lote.html new file mode 100644 index 000000000..7c5493455 --- /dev/null +++ b/sapl/templates/materia/acessorio_lote.html @@ -0,0 +1,73 @@ +{% extends "crud/detail.html" %} +{% load i18n crispy_forms_tags %} +{% block actions %}{% endblock %} +{% block sections_nav %}{% endblock %} +{% block detail_content %} + + {% if not filter_url %} + {% crispy filter.form %} + {% endif %} + + +{% endblock detail_content %} From e84c2b1b28a262467ce56411cab8a6fed44ad4aa Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Wed, 14 Sep 2016 16:35:26 -0300 Subject: [PATCH 2/6] =?UTF-8?q?Listagem=20das=20mat=C3=A9rias=20encontrada?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/materia/views.py | 5 ++ sapl/templates/materia/acessorio_lote.html | 85 +++++++--------------- 2 files changed, 33 insertions(+), 57 deletions(-) diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 3ddd1e946..ce9fa45d7 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -1252,12 +1252,17 @@ def do_envia_email_tramitacao(request, materia): class DocumentoAcessorioEmLoteView(PermissionRequiredMixin, FilterView): filterset_class = AcessorioEmLoteFilterSet template_name = 'materia/acessorio_lote.html' + permission_required = permissoes_materia() def get_context_data(self, **kwargs): context = super(DocumentoAcessorioEmLoteView, self).get_context_data(**kwargs) context['title'] = _('Documentos Acessórios em Lote') + # Verifica se os campos foram preenchidos + if not self.filterset.form.is_valid(): + return context + qr = self.request.GET.copy() context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' return context diff --git a/sapl/templates/materia/acessorio_lote.html b/sapl/templates/materia/acessorio_lote.html index 7c5493455..f91c3017d 100644 --- a/sapl/templates/materia/acessorio_lote.html +++ b/sapl/templates/materia/acessorio_lote.html @@ -8,66 +8,37 @@ {% crispy filter.form %} {% endif %} - + {% endif %} {% endblock detail_content %} From 513a545ace1bb8ada9d27c457deaeb61e1c7dc83 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Wed, 14 Sep 2016 17:55:45 -0300 Subject: [PATCH 3/6] =?UTF-8?q?Adiciona=20formul=C3=A1rio=20com=20campos?= =?UTF-8?q?=20do=20documento=20acess=C3=B3rio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/materia/views.py | 4 + sapl/templates/materia/acessorio_lote.html | 87 ++++++++++++++++------ 2 files changed, 70 insertions(+), 21 deletions(-) diff --git a/sapl/materia/views.py b/sapl/materia/views.py index ce9fa45d7..69fff1b79 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -1264,9 +1264,13 @@ class DocumentoAcessorioEmLoteView(PermissionRequiredMixin, FilterView): return context qr = self.request.GET.copy() + context['tipos_docs'] = TipoDocumento.objects.all() context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' return context + def post(self, request, *args, **kwargs): + return self.get(request, self.kwargs) + # def post(self, request, *args, **kwargs): # marcadas = request.POST.getlist('materia_id') # diff --git a/sapl/templates/materia/acessorio_lote.html b/sapl/templates/materia/acessorio_lote.html index f91c3017d..ec689286b 100644 --- a/sapl/templates/materia/acessorio_lote.html +++ b/sapl/templates/materia/acessorio_lote.html @@ -18,27 +18,72 @@ {% else %}

Nenhuma matéria encontrada.

{% endif %} +
+ {% csrf_token %} +
+ Documento Acessório +
+
+ + +
- - - - - - - - - - {% csrf_token %} - {% for materia in object_list %} - - - - {% endfor %} - - -
Matérias
- - {{materia.tipo.sigla}} {{materia.numero}}/{{materia.ano}} - {{materia.tipo.descricao}} -
+
+ + +
+ +
+ + +
+
+ +
+
+ + +
+
+ +
+
+ + +
+
+ +
+
+ + +
+
+
+ +


+ +
+ 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}} +
+
+ + {% endif %} {% endblock detail_content %} From 408686fdd318d78d271bb2cc85c45f48b6b187dd Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Wed, 14 Sep 2016 18:17:04 -0300 Subject: [PATCH 4/6] =?UTF-8?q?Cria=20documento=20acessorio=20das=20mat?= =?UTF-8?q?=C3=A9rias=20selecionadas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/materia/views.py | 56 ++++++++-------------- sapl/templates/materia/acessorio_lote.html | 6 +-- 2 files changed, 24 insertions(+), 38 deletions(-) diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 69fff1b79..1a904396c 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -1269,38 +1269,24 @@ class DocumentoAcessorioEmLoteView(PermissionRequiredMixin, FilterView): return context def post(self, request, *args, **kwargs): - return self.get(request, self.kwargs) - - # def post(self, request, *args, **kwargs): - # marcadas = request.POST.getlist('materia_id') - # - # for m in marcadas: - # try: - # tipo_votacao = request.POST['tipo_votacao_%s' % m] - # except MultiValueDictKeyError: - # msg = _('Formulário Inválido. Você esqueceu de selecionar ' + - # 'o tipo de votação de %s' % - # MateriaLegislativa.objects.get(id=m)) - # messages.add_message(request, messages.ERROR, msg) - # return self.get(request, self.kwargs) - # - # if tipo_votacao: - # lista_materias_expediente = ExpedienteMateria.objects.filter( - # sessao_plenaria_id=self.kwargs[ - # 'pk']) - # - # materia = MateriaLegislativa.objects.get(id=m) - # - # expediente = ExpedienteMateria() - # expediente.sessao_plenaria_id = self.kwargs['pk'] - # expediente.materia_id = materia.id - # if lista_materias_expediente: - # posicao = lista_materias_expediente.last().numero_ordem + 1 - # expediente.numero_ordem = posicao - # else: - # expediente.numero_ordem = 1 - # expediente.data_ordem = datetime.now() - # expediente.tipo_votacao = request.POST['tipo_votacao_%s' % m] - # expediente.save() - # - # return self.get(request, self.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']) + for materia_id in marcadas: + DocumentoAcessorio.objects.create( + materia_id=materia_id, + tipo=tipo, + arquivo=request.POST['arquivo'], + nome=request.POST['nome'], + data=datetime.strptime(request.POST['data'], "%d/%m/%Y"), + autor=request.POST['autor'], + ementa=request.POST['ementa'] + ) + msg = _('Documento(s) criado(s).') + messages.add_message(request, messages.SUCCESS, msg) + return self.get(reverse('sapl.materia:acessorio_lote')) diff --git a/sapl/templates/materia/acessorio_lote.html b/sapl/templates/materia/acessorio_lote.html index ec689286b..77adfb4e4 100644 --- a/sapl/templates/materia/acessorio_lote.html +++ b/sapl/templates/materia/acessorio_lote.html @@ -25,7 +25,7 @@
- {% for t in tipos_docs %} {% endfor %}
@@ -37,7 +37,7 @@
- +
@@ -58,7 +58,7 @@
- +
From 6f7c0e715f5b2133f2ad8e31d968dd49dfd7059e Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Wed, 14 Sep 2016 18:39:49 -0300 Subject: [PATCH 5/6] =?UTF-8?q?Adiciona=20op=C3=A7=C3=A3o=20para=20acess?= =?UTF-8?q?=C3=B3rio=20em=20lote=20na=20navbar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/materia/views.py | 2 +- sapl/templates/base.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 1a904396c..4541c9c07 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -1289,4 +1289,4 @@ class DocumentoAcessorioEmLoteView(PermissionRequiredMixin, FilterView): ) msg = _('Documento(s) criado(s).') messages.add_message(request, messages.SUCCESS, msg) - return self.get(reverse('sapl.materia:acessorio_lote')) + return self.get(request, self.kwargs) diff --git a/sapl/templates/base.html b/sapl/templates/base.html index 363c1d7e0..f1c78437d 100644 --- a/sapl/templates/base.html +++ b/sapl/templates/base.html @@ -83,8 +83,8 @@ {% endif %} - +