diff --git a/sapl/base/forms.py b/sapl/base/forms.py index 085e6c4ea..9d8d4534d 100644 --- a/sapl/base/forms.py +++ b/sapl/base/forms.py @@ -11,7 +11,8 @@ from django.utils.translation import ugettext_lazy as _ from sapl.crispy_layout_mixin import form_actions, to_row from sapl.materia.models import MateriaLegislativa from sapl.settings import MAX_IMAGE_UPLOAD_SIZE -from sapl.utils import ImageThumbnailFileInput, autor_label, autor_modal +from sapl.utils import (RANGE_ANOS, ImageThumbnailFileInput, autor_label, + autor_modal) from .models import CasaLegislativa @@ -36,6 +37,32 @@ class RangeWidgetOverride(forms.MultiWidget): return ''.join(rendered_widgets) +class RelatorioMateriasPorAnoAutorTipoFilterSet(django_filters.FilterSet): + + ano = django_filters.ChoiceFilter(required=True, + label=u'Ano da Matéria', + choices=RANGE_ANOS) + + class Meta: + model = MateriaLegislativa + fields = ['ano'] + + def __init__(self, *args, **kwargs): + super(RelatorioMateriasPorAnoAutorTipoFilterSet, self).__init__( + *args, **kwargs) + + row1 = to_row( + [('ano', 12)]) + + self.form.helper = FormHelper() + self.form.helper.form_method = 'GET' + self.form.helper.layout = Layout( + Fieldset(_('Pesquisar'), + row1, + form_actions(save_label='Pesquisar')) + ) + + class RelatorioMateriasPorAutorFilterSet(django_filters.FilterSet): filter_overrides = {models.DateField: { diff --git a/sapl/base/urls.py b/sapl/base/urls.py index e7500d683..a60e0d718 100644 --- a/sapl/base/urls.py +++ b/sapl/base/urls.py @@ -4,7 +4,9 @@ from django.views.generic.base import TemplateView from .apps import AppConfig from .forms import LoginForm -from .views import CasaLegislativaCrud, HelpView, RelatorioMateriasPorAutorView +from .views import (CasaLegislativaCrud, HelpView, + RelatorioMateriasPorAnoAutorTipoView, + RelatorioMateriasPorAutorView) app_name = AppConfig.name @@ -26,4 +28,7 @@ urlpatterns = [ url(r'^relatorio/materia-por-autor$', RelatorioMateriasPorAutorView.as_view(), name='materia_por_autor'), + url(r'^relatorio/materia-por-ano-autor-tipo$', + RelatorioMateriasPorAnoAutorTipoView.as_view(), + name='materia_por_ano_autor_tipo'), ] diff --git a/sapl/base/views.py b/sapl/base/views.py index 719215d3e..06d48a5a6 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -10,7 +10,9 @@ from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, from sapl.materia.models import MateriaLegislativa, TipoMateriaLegislativa from sapl.utils import permissao_tb_aux -from .forms import CasaLegislativaForm, RelatorioMateriasPorAutorFilterSet +from .forms import (CasaLegislativaForm, + RelatorioMateriasPorAnoAutorTipoFilterSet, + RelatorioMateriasPorAutorFilterSet) from .models import CasaLegislativa @@ -18,6 +20,38 @@ def get_casalegislativa(): return CasaLegislativa.objects.first() +class RelatorioMateriasPorAnoAutorTipoView(FilterView): + model = MateriaLegislativa + filterset_class = RelatorioMateriasPorAnoAutorTipoFilterSet + template_name = 'base/RelatorioMateriasPorAnoAutorTipo_filter.html' + + def get_filterset_kwargs(self, filterset_class): + super(RelatorioMateriasPorAnoAutorTipoView, + self).get_filterset_kwargs(filterset_class) + + kwargs = {'data': self.request.GET or None} + return kwargs + + def get_context_data(self, **kwargs): + context = super(RelatorioMateriasPorAnoAutorTipoView, + self).get_context_data(**kwargs) + + context['title'] = _('Matérias por Ano, Autor e Tipo') + + qtdes = {} + for tipo in TipoMateriaLegislativa.objects.all(): + qs = kwargs['object_list'] + qtde = len(qs.filter(tipo_id=tipo.id)) + if qtde > 0: + qtdes[tipo] = qtde + context['qtdes'] = qtdes + + qr = self.request.GET.copy() + context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' + + return context + + class RelatorioMateriasPorAutorView(FilterView): model = MateriaLegislativa filterset_class = RelatorioMateriasPorAutorFilterSet diff --git a/sapl/templates/base/RelatorioMateriasPorAnoAutorTipo_filter.html b/sapl/templates/base/RelatorioMateriasPorAnoAutorTipo_filter.html new file mode 100644 index 000000000..2498c08be --- /dev/null +++ b/sapl/templates/base/RelatorioMateriasPorAnoAutorTipo_filter.html @@ -0,0 +1,60 @@ +{% extends "crud/list.html" %} +{% load i18n %} +{% load crispy_forms_tags %} + +{% block base_content %} + {% if not filter_url %} + {% crispy filter.form %} + {% endif %} + + {% if filter_url %} +
+ {% trans 'Fazer nova pesquisa' %} +
+



+ + + + + + + + + + + {% for key, value in qtdes.items %} + + + + + {% endfor %} + +
QUADRO GERAL
Tipo MatériaQuantidade
{{key.sigla}} - {{key}}{{value}}
+ + + + + + + + + + + {% for materia in object_list %} + + + + + + {% endfor %} + +
MatériaEmentaAutor(es)
+ {{materia.tipo.descricao}} - {{materia.tipo.sigla}} {{materia.numero}}/{{materia.ano}} + {{materia.ementa}} + {% for autor in materia.autoria_set.all %} + {{autor.autor}}
+ {% endfor %} +
+ {% endif %} + +{% endblock base_content %} diff --git a/sapl/templates/base/relatorios_list.html b/sapl/templates/base/relatorios_list.html index d27a7914e..849ef20d2 100644 --- a/sapl/templates/base/relatorios_list.html +++ b/sapl/templates/base/relatorios_list.html @@ -21,7 +21,7 @@ Listagem e totalização de matérias por autor, com filtros para tipo e período. - Matérias por Ano, Autor e Tipo + Matérias por Ano, Autor e Tipo Totalização anual de matérias agrupadas por autor e tipo.