Browse Source

Merge pull request #554 from interlegis/553-relatorio-historico-tramitacao

Fix #553 relatorio historico tramitacao
pull/579/head
Edward 8 years ago
committed by GitHub
parent
commit
4a5b5da011
  1. 168
      sapl/base/forms.py
  2. 20
      sapl/base/urls.py
  3. 115
      sapl/base/views.py
  4. 5
      sapl/materia/views.py
  5. 34
      sapl/templates/base/RelatorioHistoricoTramitacao_filter.html
  6. 60
      sapl/templates/base/RelatorioMateriasPorAnoAutorTipo_filter.html
  7. 60
      sapl/templates/base/RelatorioMateriasPorAutor_filter.html
  8. 56
      sapl/templates/base/RelatorioMateriasPorTramitacao_filter.html
  9. 18
      sapl/templates/base/relatorios_list.html

168
sapl/base/forms.py

@ -1,14 +1,180 @@
import django_filters
from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Button, Fieldset, Layout
from django import forms
from django.contrib.auth.forms import AuthenticationForm
from django.core.exceptions import ValidationError
from django.db import models
from django.forms import ModelForm
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
from sapl.utils import (RANGE_ANOS, ImageThumbnailFileInput, autor_label,
autor_modal)
from .models import CasaLegislativa
class RangeWidgetOverride(forms.MultiWidget):
def __init__(self, attrs=None):
widgets = (forms.DateInput(format='%d/%m/%Y',
attrs={'class': 'dateinput',
'placeholder': 'Inicial'}),
forms.DateInput(format='%d/%m/%Y',
attrs={'class': 'dateinput',
'placeholder': 'Final'}))
super(RangeWidgetOverride, self).__init__(widgets, attrs)
def decompress(self, value):
if value:
return [value.start, value.stop]
return [None, None]
def format_output(self, rendered_widgets):
return ''.join(rendered_widgets)
class RelatorioHistoricoTramitacaoFilterSet(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', 'tramitacao__unidade_tramitacao_local',
'tramitacao__status', 'tramitacao__data_tramitacao']
def __init__(self, *args, **kwargs):
super(RelatorioHistoricoTramitacaoFilterSet, self).__init__(
*args, **kwargs)
self.filters['tipo'].label = 'Tipo de Matéria'
row1 = to_row([('tramitacao__data_tramitacao', 12)])
row2 = to_row(
[('tipo', 4),
('tramitacao__unidade_tramitacao_local', 4),
('tramitacao__status', 4)])
self.form.helper = FormHelper()
self.form.helper.form_method = 'GET'
self.form.helper.layout = Layout(
Fieldset(_('Histórico de Tramita'),
row1, row2,
form_actions(save_label='Pesquisar'))
)
class RelatorioMateriasTramitacaoilterSet(django_filters.FilterSet):
ano = django_filters.ChoiceFilter(required=True,
label=u'Ano da Matéria',
choices=RANGE_ANOS)
class Meta:
model = MateriaLegislativa
fields = ['ano', 'tipo', 'tramitacao__unidade_tramitacao_local',
'tramitacao__status']
def __init__(self, *args, **kwargs):
super(RelatorioMateriasTramitacaoilterSet, self).__init__(
*args, **kwargs)
self.filters['tipo'].label = 'Tipo de Matéria'
row1 = to_row([('ano', 12)])
row2 = to_row([('tipo', 12)])
row3 = to_row([('tramitacao__unidade_tramitacao_local', 12)])
row4 = to_row([('tramitacao__status', 12)])
self.form.helper = FormHelper()
self.form.helper.form_method = 'GET'
self.form.helper.layout = Layout(
Fieldset(_('Pesquisa de Matéria em Tramitação'),
row1, row2, row3, row4,
form_actions(save_label='Pesquisar'))
)
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: {
'filter_class': django_filters.DateFromToRangeFilter,
'extra': lambda f: {
'label': '%s (%s)' % (f.verbose_name, _('Inicial - Final')),
'widget': RangeWidgetOverride}
}}
autoria__autor = django_filters.CharFilter(widget=forms.HiddenInput())
class Meta:
model = MateriaLegislativa
fields = ['tipo', 'data_apresentacao']
def __init__(self, *args, **kwargs):
super(RelatorioMateriasPorAutorFilterSet, self).__init__(
*args, **kwargs)
self.filters['tipo'].label = 'Tipo de Matéria'
row1 = to_row(
[('tipo', 12)])
row2 = to_row(
[('data_apresentacao', 12)])
row3 = to_row(
[('autoria__autor', 0),
(Button('pesquisar',
'Pesquisar Autor',
css_class='btn btn-primary btn-sm'), 2),
(Button('limpar',
'limpar Autor',
css_class='btn btn-primary btn-sm'), 10)])
self.form.helper = FormHelper()
self.form.helper.form_method = 'GET'
self.form.helper.layout = Layout(
Fieldset(_('Pesquisar'),
row1, row2,
HTML(autor_label),
HTML(autor_modal),
row3,
form_actions(save_label='Pesquisar'))
)
class CasaLegislativaForm(ModelForm):
class Meta:

20
sapl/base/urls.py

@ -4,7 +4,11 @@ from django.views.generic.base import TemplateView
from .apps import AppConfig
from .forms import LoginForm
from .views import CasaLegislativaCrud, HelpView
from .views import (CasaLegislativaCrud, HelpView,
RelatorioHistoricoTramitacaoView,
RelatorioMateriasPorAnoAutorTipoView,
RelatorioMateriasPorAutorView,
RelatorioMateriasTramitacaoView)
app_name = AppConfig.name
@ -17,11 +21,23 @@ urlpatterns = [
url(r'^ajuda/(?P<topic>\w+)$', HelpView.as_view(), name='help_topic'),
url(r'^ajuda/', TemplateView.as_view(template_name='ajuda/index.html'),
name='help_base'),
url(r'^casa_legislativa/', include(CasaLegislativaCrud.get_urls())),
url(r'^login/$', views.login, {
'template_name': 'base/login.html', 'authentication_form': LoginForm},
name='login'),
url(r'^logout/$', views.logout, {'next_page': '/login'}, name='logout'),
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'),
url(r'^relatorio/materia-por-tramitacao$',
RelatorioMateriasTramitacaoView.as_view(),
name='materia_por_tramitacao'),
url(r'^relatorio/historico-tramitacoes$',
RelatorioHistoricoTramitacaoView.as_view(),
name='historico_tramitacoes'),
]

115
sapl/base/views.py

@ -1,13 +1,19 @@
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.utils.translation import ugettext_lazy as _
from django.views.generic.base import TemplateView
from django_filters.views import FilterView
from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView,
CrudDetailView, CrudUpdateView)
from sapl.materia.models import MateriaLegislativa, TipoMateriaLegislativa
from sapl.utils import permissao_tb_aux
from .forms import CasaLegislativaForm
from .forms import (CasaLegislativaForm, RelatorioHistoricoTramitacaoFilterSet,
RelatorioMateriasPorAnoAutorTipoFilterSet,
RelatorioMateriasPorAutorFilterSet,
RelatorioMateriasTramitacaoilterSet)
from .models import CasaLegislativa
@ -15,6 +21,113 @@ def get_casalegislativa():
return CasaLegislativa.objects.first()
class RelatorioHistoricoTramitacaoView(FilterView):
model = MateriaLegislativa
filterset_class = RelatorioHistoricoTramitacaoFilterSet
template_name = 'base/RelatorioHistoricoTramitacao_filter.html'
def get_context_data(self, **kwargs):
context = super(RelatorioHistoricoTramitacaoView,
self).get_context_data(**kwargs)
context['title'] = _('Histórico de Tramitações')
qr = self.request.GET.copy()
context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else ''
return context
class RelatorioMateriasTramitacaoView(FilterView):
model = MateriaLegislativa
filterset_class = RelatorioMateriasTramitacaoilterSet
template_name = 'base/RelatorioMateriasPorTramitacao_filter.html'
def get_context_data(self, **kwargs):
context = super(RelatorioMateriasTramitacaoView,
self).get_context_data(**kwargs)
context['title'] = _('Matérias por Ano, Autor e Tipo')
qs = context['object_list']
qs = qs.filter(em_tramitacao=True)
context['object_list'] = qs
qtdes = {}
for tipo in TipoMateriaLegislativa.objects.all():
qs = context['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 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
template_name = 'base/RelatorioMateriasPorAutor_filter.html'
def get_filterset_kwargs(self, filterset_class):
super(RelatorioMateriasPorAutorView,
self).get_filterset_kwargs(filterset_class)
kwargs = {'data': self.request.GET or None}
return kwargs
def get_context_data(self, **kwargs):
context = super(RelatorioMateriasPorAutorView,
self).get_context_data(**kwargs)
context['title'] = _('Matérias por Autor')
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 CasaLegislativaCrud(Crud):
model = CasaLegislativa
help_path = ''

5
sapl/materia/views.py

@ -929,11 +929,6 @@ class MateriaLegislativaPesquisaView(FilterView):
context['title'] = _('Pesquisar Matéria Legislativa')
paginator = context['paginator']
page_obj = context['page_obj']
context['page_range'] = make_pagination(
page_obj.number, paginator.num_pages)
self.filterset.form.fields['o'].label = _('Ordenação')
qr = self.request.GET.copy()

34
sapl/templates/base/RelatorioHistoricoTramitacao_filter.html

@ -0,0 +1,34 @@
{% extends "crud/list.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block base_content %}
{% if not filter_url %}
{% crispy filter.form %}
{% endif %}
{% if filter_url %}
<div class="actions btn-group pull-right" role="group">
<a href="{% url 'sapl.base:historico_tramitacoes' %}" class="btn btn-default">{% trans 'Fazer nova pesquisa' %}</a>
</div>
<br /><br /><br /><br />
<table class="table table-bordered table-hover">
<thead class="thead-default" >
<tr class="active">
<th>Matéria</th>
<th>Ementa</th>
</tr>
</thead>
<tbody>
{% for materia in object_list %}
<tr>
<td><a href="{% url 'sapl.materia:tramitacao_list' materia.pk %}">
{{materia.tipo.descricao}} - {{materia.tipo.sigla}} {{materia.numero}}/{{materia.ano}}
</a></td>
<td>{{materia.ementa}}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% endblock base_content %}

60
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 %}
<div class="actions btn-group pull-right" role="group">
<a href="{% url 'sapl.base:materia_por_ano_autor_tipo' %}" class="btn btn-default">{% trans 'Fazer nova pesquisa' %}</a>
</div>
<br /><br /><br /><br />
<table class="table table-bordered table-hover">
<thead class="thead-default" >
<tr class="active"><th colspan="2" class="text-center">QUADRO GERAL</th></tr>
<tr class="active">
<th>Tipo Matéria</th>
<th>Quantidade</th>
</tr>
</thead>
<tbody>
{% for key, value in qtdes.items %}
<tr>
<td>{{key.sigla}} - {{key}}</td>
<td>{{value}}</td>
</tr>
{% endfor %}
</tbody>
</table>
<table class="table table-bordered table-hover">
<thead class="thead-default" >
<tr class="active">
<th>Matéria</th>
<th>Ementa</th>
<th>Autor(es)</th>
</tr>
</thead>
<tbody>
{% for materia in object_list %}
<tr>
<td><a href="{% url 'sapl.materia:materialegislativa_detail' materia.pk %}">
{{materia.tipo.descricao}} - {{materia.tipo.sigla}} {{materia.numero}}/{{materia.ano}}
</a></td>
<td>{{materia.ementa}}</td>
<td>
{% for autor in materia.autoria_set.all %}
{{autor.autor}}<br />
{% endfor %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% endblock base_content %}

60
sapl/templates/base/RelatorioMateriasPorAutor_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 %}
<div class="actions btn-group pull-right" role="group">
<a href="{% url 'sapl.base:materia_por_autor' %}" class="btn btn-default">{% trans 'Fazer nova pesquisa' %}</a>
</div>
<br /><br /><br /><br />
<table class="table table-bordered table-hover">
<thead class="thead-default" >
<tr class="active"><th colspan="2" class="text-center">QUADRO GERAL</th></tr>
<tr class="active">
<th>Tipo Matéria</th>
<th>Quantidade</th>
</tr>
</thead>
<tbody>
{% for key, value in qtdes.items %}
<tr>
<td>{{key.sigla}} - {{key}}</td>
<td>{{value}}</td>
</tr>
{% endfor %}
</tbody>
</table>
<table class="table table-bordered table-hover">
<thead class="thead-default" >
<tr class="active">
<th>Matéria</th>
<th>Ementa</th>
<th>Autor(es)</th>
</tr>
</thead>
<tbody>
{% for materia in object_list %}
<tr>
<td><a href="{% url 'sapl.materia:materialegislativa_detail' materia.pk %}">
{{materia.tipo.sigla}} {{materia.numero}}/{{materia.ano}}
</a></td>
<td>{{materia.ementa}}</td>
<td>
{% for autor in materia.autoria_set.all %}
{{autor.autor}}<br />
{% endfor %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% endblock base_content %}

56
sapl/templates/base/RelatorioMateriasPorTramitacao_filter.html

@ -0,0 +1,56 @@
{% extends "crud/list.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block base_content %}
{% if not filter_url %}
{% crispy filter.form %}
{% endif %}
{% if filter_url %}
<div class="actions btn-group pull-right" role="group">
<a href="{% url 'sapl.base:materia_por_tramitacao' %}" class="btn btn-default">{% trans 'Fazer nova pesquisa' %}</a>
</div>
<br /><br /><br /><br />
<table class="table table-bordered table-hover">
<thead class="thead-default" >
<tr class="active"><th colspan="2" class="text-center">QUADRO GERAL</th></tr>
<tr class="active">
<th>Tipo Matéria</th>
<th>Quantidade</th>
</tr>
</thead>
<tbody>
{% for key, value in qtdes.items %}
<tr>
<td>{{key.sigla}} - {{key}}</td>
<td>{{value}}</td>
</tr>
{% endfor %}
</tbody>
</table>
<table class="table table-bordered table-hover">
<thead class="thead-default" >
<tr class="active">
<th>Matéria</th>
<th>Local Atual</th>
<th>Status</th>
</tr>
</thead>
<tbody>
{% for materia in object_list %}
<tr>
<td><a href="{% url 'sapl.materia:materialegislativa_detail' materia.pk %}">
{{materia.tipo.descricao}} {{materia.numero}}/{{materia.ano}}
</a></td>
<td>{{materia.tramitacao_set.last.unidade_tramitacao_local}}</td>
<td>{{materia.tramitacao_set.last.status}}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% endblock base_content %}

18
sapl/templates/base/relatorios_list.html

@ -13,16 +13,16 @@
</thead>
<tbody>
<tr>
<td><a href="">Matérias em tramitação</a></td>
<td>Matérias Legislativas por Ano, Tipo, Local atual e Status da Tramitação informados.</td>
<td><a href="{% url 'sapl.base:materia_por_tramitacao' %}">Matérias em tramitação</a></td>
<td> Matérias Legislativas por Ano, Tipo, Local atual e Status da Tramitação informados. </td>
</tr>
<tr>
<td><a href="">Proposituras por Tipo, Autor e Ano</a></td>
<td>Número de matérias legislativas, agrupadas por Tipo e Autor e Ano selecionado.</td>
<td><a href="{% url 'sapl.base:materia_por_autor' %}">Matérias por Autor</a></td>
<td> Listagem e totalização de matérias por autor, com filtros para tipo e período. </td>
</tr>
<tr>
<td><a href="">Proposituras por Autor</a></td>
<td>Resumo de Proposituras de um determinado ano, agrupadas por Autor.</td>
<td><a href="{% url 'sapl.base:materia_por_ano_autor_tipo' %}">Matérias por Ano, Autor e Tipo</a></td>
<td> Totalização anual de matérias agrupadas por autor e tipo. </td>
</tr>
<tr>
<td><a href="">Presença nas sessões</a></td>
@ -30,11 +30,11 @@
</tr>
<tr>
<td><a href="">Atas</a></td>
<td>Matérias Legislativas por Ano, Tipo, Local atual e Status da Tramitação informados.</td>
<td> Atas de Sessão Plenária. </td>
</tr>
<tr>
<td><a href="">Histórico de tramitações</a></td>
<td>Histórico de tramitações por período e local informados.</td>
<td><a href="{% url 'sapl.base:historico_tramitacoes' %}">Histórico de tramitações</a></td>
<td> Histórico de tramitações por período e local informados. </td>
</tr>
</tbody>
</table>

Loading…
Cancel
Save