diff --git a/sapl/comissoes/forms.py b/sapl/comissoes/forms.py index 03f40f517..e395fdf90 100644 --- a/sapl/comissoes/forms.py +++ b/sapl/comissoes/forms.py @@ -1,7 +1,9 @@ +import django_filters import logging +from crispy_forms.layout import Fieldset, Layout + from django import forms -from sapl.settings import MAX_DOC_UPLOAD_SIZE from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ValidationError from django.db import transaction @@ -11,10 +13,12 @@ from django.utils.translation import ugettext_lazy as _ from sapl.base.models import Autor, TipoAutor from sapl.comissoes.models import (Comissao, Composicao, DocumentoAcessorio, - Participacao, Reuniao, Periodo) -from sapl.materia.models import PautaReuniao + Participacao, Periodo, Reuniao) +from sapl.crispy_layout_mixin import form_actions, SaplFormHelper, to_row +from sapl.materia.models import MateriaEmTramitacao, PautaReuniao from sapl.parlamentares.models import Legislatura, Mandato, Parlamentar -from sapl.utils import FileFieldCheckMixin +from sapl.settings import MAX_DOC_UPLOAD_SIZE +from sapl.utils import FileFieldCheckMixin, FilterOverridesMetaMixin class ComposicaoForm(forms.ModelForm): @@ -416,6 +420,32 @@ class ReuniaoForm(ModelForm): return self.cleaned_data +class PautaReuniaoFilterSet(django_filters.FilterSet): + + class Meta(FilterOverridesMetaMixin): + model = MateriaEmTramitacao + fields = ['materia__tipo', 'materia__ano', 'materia__numero', 'materia__data_apresentacao'] + + def __init__(self, *args, **kwargs): + super(PautaReuniaoFilterSet, self).__init__(*args, **kwargs) + + self.filters['materia__tipo'].label = "Tipo da Matéria" + self.filters['materia__ano'].label = "Ano da Matéria" + self.filters['materia__data_apresentacao'].label = "Data (Inicial - Final)" + + row1 = to_row([('materia__numero', 4), ('materia__tipo', 4), ('materia__ano', 4)]) + row2 = to_row([('materia__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") + ) + ) + + class PautaReuniaoForm(forms.ModelForm): class Meta: diff --git a/sapl/comissoes/views.py b/sapl/comissoes/views.py index 35d066d3c..4d37d735a 100644 --- a/sapl/comissoes/views.py +++ b/sapl/comissoes/views.py @@ -12,18 +12,22 @@ from django.views.generic.detail import DetailView from django.views.generic.edit import FormMixin, UpdateView from django.utils.translation import ugettext_lazy as _ +from django_filters.views import FilterView + from sapl.base.models import AppConfig as AppsAppConfig from sapl.comissoes.apps import AppConfig from sapl.comissoes.forms import (ComissaoForm, ComposicaoForm, DocumentoAcessorioCreateForm, DocumentoAcessorioEditForm, ParticipacaoCreateForm, ParticipacaoEditForm, - PautaReuniaoForm, PeriodoForm, ReuniaoForm) + PautaReuniaoForm, PeriodoForm, ReuniaoForm, + PautaReuniaoFilterSet) from sapl.crud.base import (RP_DETAIL, RP_LIST, Crud, CrudAux, MasterDetailCrud, PermissionRequiredForAppCrudMixin) from sapl.materia.models import (MateriaLegislativa, Tramitacao, PautaReuniao, MateriaEmTramitacao) +from sapl.utils import show_results_filter_set from .models import (CargoComissao, Comissao, Composicao, DocumentoAcessorio, Participacao, Periodo, Reuniao, TipoComissao) @@ -218,7 +222,7 @@ class ReuniaoCrud(MasterDetailCrud): context['mats'] = MateriaLegislativa.objects.filter( pk__in=materias_pk - ).order_by('tipo', '-ano', '-numero') + ).order_by('tipo', '-ano', 'numero') context['num_mats'] = len(context['mats']) context['reuniao_pk'] = self.kwargs['pk'] @@ -296,8 +300,8 @@ class RemovePautaView(PermissionRequiredMixin, CreateView): context['materias'] = MateriaLegislativa.objects.filter( pk__in=materias_pk - ).order_by('tipo', '-ano', '-numero') - context['num_materias'] = len(context['materias']) + ).order_by('tipo', '-ano', 'numero') + context['numero_materias'] = len(context['materias']) return context @@ -319,9 +323,8 @@ class RemovePautaView(PermissionRequiredMixin, CreateView): return HttpResponseRedirect(success_url) -class AdicionaPautaView(PermissionRequiredMixin, CreateView): - model = PautaReuniao - form_class = PautaReuniaoForm +class AdicionaPautaView(PermissionRequiredMixin, FilterView): + filterset_class = PautaReuniaoFilterSet template_name = 'comissoes/pauta.html' permission_required = ('comissoes.add_reuniao', ) @@ -336,12 +339,19 @@ class AdicionaPautaView(PermissionRequiredMixin, CreateView): context['object'] = Reuniao.objects.get(pk=self.kwargs['pk']) context['root_pk'] = context['object'].comissao.pk - materias_comissao = lista_materias_comissao(context['object'].comissao.pk) - materias_pauta = PautaReuniao.objects.filter(reuniao=context['object']) + qr = self.request.GET.copy() + materias_pauta = PautaReuniao.objects.filter(reuniao=context['object']) nao_listar = [mp.materia.pk for mp in materias_pauta] - context['materias'] = materias_comissao.exclude(pk__in=nao_listar) - context['num_materias'] = len(context['materias']) + + context['object_list'] = context['object_list'].filter( + tramitacao__unidade_tramitacao_destino__comissao=context['root_pk'] + ).exclude(materia__pk__in=nao_listar).order_by( + "materia__tipo", "-materia__ano", "materia__numero" + ) + + context['numero_resultados'] = len(context['object_list']) + context['show_results'] = show_results_filter_set(qr) return context diff --git a/sapl/materia/forms.py b/sapl/materia/forms.py index 476b1a921..51ab2175a 100644 --- a/sapl/materia/forms.py +++ b/sapl/materia/forms.py @@ -1,6 +1,7 @@ - +import django_filters import logging import os +import sapl from crispy_forms.bootstrap import Alert, InlineRadios from crispy_forms.layout import (HTML, Button, Field, Fieldset, @@ -11,7 +12,7 @@ from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.core.files.base import File from django.core.urlresolvers import reverse from django.db import models, transaction -from django.db.models import Max, Q, F +from django.db.models import F, Max, Q from django.forms import ModelChoiceField, ModelForm, widgets from django.forms.forms import Form from django.forms.models import ModelMultipleChoiceField @@ -21,36 +22,37 @@ from django.utils.encoding import force_text from django.utils.html import format_html from django.utils.safestring import mark_safe from django.utils.translation import ugettext_lazy as _ -import django_filters -import sapl from sapl.base.models import AppConfig, Autor, TipoAutor -from sapl.comissoes.models import Comissao, Participacao, Composicao +from sapl.comissoes.models import Comissao, Composicao, Participacao from sapl.compilacao.models import (STATUS_TA_IMMUTABLE_PUBLIC, STATUS_TA_PRIVATE) -from sapl.crispy_layout_mixin import (SaplFormLayout, form_actions, to_column, - to_row) -from sapl.crispy_layout_mixin import SaplFormHelper +from sapl.crispy_layout_mixin import (SaplFormLayout, form_actions, + to_column, to_row, SaplFormHelper) from sapl.materia.models import (AssuntoMateria, Autoria, MateriaAssunto, - MateriaLegislativa, Orgao, RegimeTramitacao, - TipoDocumento, TipoProposicao, StatusTramitacao, + MateriaLegislativa, Orgao, + RegimeTramitacao, StatusTramitacao, + TipoDocumento, TipoProposicao, UnidadeTramitacao) -from sapl.norma.models import (LegislacaoCitada, NormaJuridica, +from sapl.norma.models import (LegislacaoCitada, NormaJuridica, TipoNormaJuridica) from sapl.parlamentares.models import Legislatura, Partido, Parlamentar -from sapl.protocoloadm.models import Protocolo, DocumentoAdministrativo, Anexado +from sapl.protocoloadm.models import (Anexado, DocumentoAdministrativo, + Protocolo) from sapl.settings import MAX_DOC_UPLOAD_SIZE -from sapl.utils import (YES_NO_CHOICES, SEPARADOR_HASH_PROPOSICAO, +from sapl.utils import (autor_label, autor_modal, ChoiceWithoutValidationField, - MateriaPesquisaOrderingFilter, RangeWidgetOverride, - autor_label, autor_modal, gerar_hash_arquivo, + choice_anos_com_materias, FileFieldCheckMixin, + FilterOverridesMetaMixin, gerar_hash_arquivo, + lista_anexados, MateriaPesquisaOrderingFilter, models_with_gr_for_model, qs_override_django_filter, - choice_anos_com_materias, FilterOverridesMetaMixin, FileFieldCheckMixin, - lista_anexados) + RangeWidgetOverride, SEPARADOR_HASH_PROPOSICAO, + YES_NO_CHOICES) -from .models import (AcompanhamentoMateria, Anexada, Autoria, DespachoInicial, - DocumentoAcessorio, Numeracao, Proposicao, Relatoria, - TipoMateriaLegislativa, Tramitacao, UnidadeTramitacao) +from .models import (AcompanhamentoMateria, Anexada, Autoria, + DespachoInicial, DocumentoAcessorio, Numeracao, + Proposicao, Relatoria, TipoMateriaLegislativa, + Tramitacao, UnidadeTramitacao) def CHOICE_TRAMITACAO(): diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 94f10f539..19e9085d7 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -1,13 +1,17 @@ -from datetime import datetime + import itertools import logging import os -from random import choice +import sapl import shutil -from string import ascii_letters, digits import tempfile +import weasyprint from crispy_forms.layout import HTML +from datetime import datetime +from random import choice +from string import ascii_letters, digits + from django.conf import settings from django.contrib import messages from django.contrib.auth.decorators import permission_required @@ -18,65 +22,53 @@ from django.db.models import Max, Q from django.http import HttpResponse, JsonResponse from django.http.response import Http404, HttpResponseRedirect from django.shortcuts import get_object_or_404, redirect -from django.template import RequestContext, loader +from django.template import loader, RequestContext from django.utils import formats, timezone from django.utils.translation import ugettext_lazy as _ -from django.views.generic import ListView, TemplateView, CreateView, UpdateView +from django.views.generic import CreateView, ListView, TemplateView, UpdateView from django.views.generic.base import RedirectView from django.views.generic.edit import FormView + from django_filters.views import FilterView -import weasyprint -import weasyprint -import sapl from sapl.base.email_utils import do_envia_email_confirmacao from sapl.base.models import Autor, CasaLegislativa, AppConfig as BaseAppConfig from sapl.base.signals import tramitacao_signal from sapl.comissoes.models import Comissao, Participacao, Composicao -from sapl.compilacao.models import (STATUS_TA_IMMUTABLE_RESTRICT, - STATUS_TA_PRIVATE) +from sapl.compilacao.models import STATUS_TA_IMMUTABLE_RESTRICT, STATUS_TA_PRIVATE from sapl.compilacao.views import IntegracaoTaView -from sapl.crispy_layout_mixin import SaplFormHelper -from sapl.crispy_layout_mixin import SaplFormLayout, form_actions -from sapl.crud.base import (RP_DETAIL, RP_LIST, Crud, CrudAux, - MasterDetailCrud, - PermissionRequiredForAppCrudMixin, make_pagination) -from sapl.materia.forms import (AnexadaForm, AutoriaForm, - AutoriaMultiCreateForm, - ConfirmarProposicaoForm, - DevolverProposicaoForm, LegislacaoCitadaForm, - OrgaoForm, ProposicaoForm, TipoProposicaoForm, - TramitacaoForm, TramitacaoUpdateForm, MateriaPesquisaSimplesForm, - DespachoInicialCreateForm) +from sapl.crispy_layout_mixin import form_actions, SaplFormHelper, SaplFormLayout +from sapl.crud.base import (Crud, CrudAux, make_pagination, MasterDetailCrud, + PermissionRequiredForAppCrudMixin, RP_DETAIL, RP_LIST) +from sapl.materia.forms import (AnexadaForm, AutoriaForm, AutoriaMultiCreateForm, + ConfirmarProposicaoForm, DevolverProposicaoForm, + DespachoInicialCreateForm, LegislacaoCitadaForm, + MateriaPesquisaSimplesForm, OrgaoForm, ProposicaoForm, + TipoProposicaoForm, TramitacaoForm, TramitacaoUpdateForm) from sapl.norma.models import LegislacaoCitada from sapl.parlamentares.models import Legislatura from sapl.protocoloadm.models import Protocolo -from sapl.settings import MEDIA_ROOT, MAX_DOC_UPLOAD_SIZE -from sapl.utils import (YES_NO_CHOICES, autor_label, autor_modal, SEPARADOR_HASH_PROPOSICAO, - gerar_hash_arquivo, get_base_url, get_client_ip, - get_mime_type_from_file_extension, montar_row_autor, - show_results_filter_set, mail_service_configured, lista_anexados) +from sapl.settings import MAX_DOC_UPLOAD_SIZE, MEDIA_ROOT +from sapl.utils import (autor_label, autor_modal, gerar_hash_arquivo, get_base_url, + get_client_ip, get_mime_type_from_file_extension, lista_anexados, + mail_service_configured, montar_row_autor, SEPARADOR_HASH_PROPOSICAO, + show_results_filter_set, YES_NO_CHOICES) from .forms import (AcessorioEmLoteFilterSet, AcompanhamentoMateriaForm, - AnexadaEmLoteFilterSet, - AdicionarVariasAutoriasFilterSet, DespachoInicialForm, - DocumentoAcessorioForm, EtiquetaPesquisaForm, - FichaPesquisaForm, FichaSelecionaForm, MateriaAssuntoForm, - MateriaLegislativaFilterSet, MateriaLegislativaForm, + AnexadaEmLoteFilterSet, AdicionarVariasAutoriasFilterSet, + compara_tramitacoes_mat, DespachoInicialForm, DocumentoAcessorioForm, + EtiquetaPesquisaForm, ExcluirTramitacaoEmLote, FichaPesquisaForm, + FichaSelecionaForm, filtra_tramitacao_destino, + filtra_tramitacao_destino_and_status, filtra_tramitacao_status, + MateriaAssuntoForm, MateriaLegislativaFilterSet, MateriaLegislativaForm, MateriaSimplificadaForm, PrimeiraTramitacaoEmLoteFilterSet, - ReceberProposicaoForm, RelatoriaForm, - TramitacaoEmLoteFilterSet, UnidadeTramitacaoForm, - filtra_tramitacao_destino, - filtra_tramitacao_destino_and_status, - filtra_tramitacao_status, - ExcluirTramitacaoEmLote, compara_tramitacoes_mat, - TramitacaoEmLoteForm) -from .models import (AcompanhamentoMateria, Anexada, AssuntoMateria, Autoria, - DespachoInicial, DocumentoAcessorio, MateriaAssunto, - MateriaLegislativa, Numeracao, Orgao, Origem, Proposicao, - RegimeTramitacao, Relatoria, StatusTramitacao, - TipoDocumento, TipoFimRelatoria, TipoMateriaLegislativa, - TipoProposicao, Tramitacao, UnidadeTramitacao) + ReceberProposicaoForm, RelatoriaForm, TramitacaoEmLoteFilterSet, + TramitacaoEmLoteForm, UnidadeTramitacaoForm) +from .models import (AcompanhamentoMateria, Anexada, AssuntoMateria, Autoria, DespachoInicial, + DocumentoAcessorio, MateriaAssunto, MateriaLegislativa, Numeracao, Orgao, + Origem, Proposicao, RegimeTramitacao, Relatoria, StatusTramitacao, + TipoDocumento, TipoFimRelatoria, TipoMateriaLegislativa, TipoProposicao, + Tramitacao, UnidadeTramitacao) AssuntoMateriaCrud = CrudAux.build(AssuntoMateria, 'assunto_materia') diff --git a/sapl/templates/comissoes/pauta.html b/sapl/templates/comissoes/pauta.html index 757c4cf86..63214ff60 100644 --- a/sapl/templates/comissoes/pauta.html +++ b/sapl/templates/comissoes/pauta.html @@ -5,64 +5,109 @@ {% block title %}
Total de Registros: {{num_mats}}
-Matéria | -
---|
- {{mat}} - | -
Total de Registros: {{ num_mats }}
+Matéria |
---|
{{mat}} |
Total de registros: {{num_docs}}
-Documento Acessório | -
---|
- {{ doc.nome }} - | -
Total de registros: {{ num_docs }}
+Documento Acessório |
---|
{{ doc.nome }} |