Browse Source

Fixes #1284

pull/1416/head
Edward Ribeiro 8 years ago
parent
commit
2c01f30f86
  1. 42
      sapl/base/views.py
  2. 34
      sapl/templates/base/RelatorioMateriasPorAnoAutorTipo_filter.html

42
sapl/base/views.py

@ -19,7 +19,8 @@ from haystack.views import SearchView
from sapl.base.forms import AutorForm, AutorFormForAdmin, TipoAutorForm from sapl.base.forms import AutorForm, AutorFormForAdmin, TipoAutorForm
from sapl.base.models import Autor, TipoAutor from sapl.base.models import Autor, TipoAutor
from sapl.crud.base import CrudAux from sapl.crud.base import CrudAux
from sapl.materia.models import MateriaLegislativa, TipoMateriaLegislativa from sapl.materia.models import (Autoria, MateriaLegislativa,
TipoMateriaLegislativa)
from sapl.sessao.models import (PresencaOrdemDia, SessaoPlenaria, from sapl.sessao.models import (PresencaOrdemDia, SessaoPlenaria,
SessaoPlenariaPresenca) SessaoPlenariaPresenca)
from sapl.utils import parlamentares_ativos, sapl_logger from sapl.utils import parlamentares_ativos, sapl_logger
@ -344,6 +345,41 @@ class RelatorioMateriasPorAnoAutorTipoView(FilterView):
filterset_class = RelatorioMateriasPorAnoAutorTipoFilterSet filterset_class = RelatorioMateriasPorAnoAutorTipoFilterSet
template_name = 'base/RelatorioMateriasPorAnoAutorTipo_filter.html' template_name = 'base/RelatorioMateriasPorAnoAutorTipo_filter.html'
def get_materias_autor_ano(self, ano):
autorias = Autoria.objects.filter(materia__ano=ano).values(
'autor',
'materia__tipo__sigla',
'materia__tipo__descricao').annotate(
total=Count('materia__tipo')).order_by(
'autor',
'materia__tipo')
autores_ids = set([i['autor'] for i in autorias])
autores = dict((a.id, a) for a in Autor.objects.filter(
id__in=autores_ids))
relatorio = []
visitados = set()
curr = None
for a in autorias:
if a['autor'] not in visitados:
if curr:
relatorio.append(curr)
curr = {}
curr['materia'] = []
curr['total'] = 0
visitados.add(a['autor'])
curr['autor'] = autores[a['autor']]
curr['materia'].append((a['materia__tipo__descricao'], a['total']))
curr['total'] += a['total']
relatorio.append(curr)
return relatorio
def get_filterset_kwargs(self, filterset_class): def get_filterset_kwargs(self, filterset_class):
super(RelatorioMateriasPorAnoAutorTipoView, super(RelatorioMateriasPorAnoAutorTipoView,
self).get_filterset_kwargs(filterset_class) self).get_filterset_kwargs(filterset_class)
@ -368,6 +404,10 @@ class RelatorioMateriasPorAnoAutorTipoView(FilterView):
qr = self.request.GET.copy() qr = self.request.GET.copy()
context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else ''
ano = int(self.request.GET['ano'])
context['relatorio'] = self.get_materias_autor_ano(ano)
return context return context

34
sapl/templates/base/RelatorioMateriasPorAnoAutorTipo_filter.html

@ -13,44 +13,42 @@
</div> </div>
<br /><br /><br /><br /> <br /><br /><br /><br />
{% for r in relatorio %}
<h3>{{r.autor}}</h3><br/>
<table class="table table-bordered table-hover"> <table class="table table-bordered table-hover">
<thead class="thead-default" > <thead class="thead-default" >
<tr class="active"><th colspan="2" class="text-center">QUADRO GERAL</th></tr>
<tr class="active"> <tr class="active">
<th>Tipo Matéria</th> <th>Natureza da Propositura</th>
<th>Quantidade</th> <th>Quantidade</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for key, value in qtdes.items %} {% for i in r.materia %}
<tr> <tr>
<td>{{key.sigla}} - {{key}}</td> <td>{{i.0}}</td><td>{{i.1}}</td>
<td>{{value}}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
<h3>Total: {{r.total}}</h3><br/>
<br/>
<br/>
{% endfor %}
<br/><br/>
<table class="table table-bordered table-hover"> <table class="table table-bordered table-hover">
<thead class="thead-default" > <thead class="thead-default" >
<tr class="active"><th colspan="2" class="text-center">QUADRO GERAL</th></tr>
<tr class="active"> <tr class="active">
<th>Matéria</th> <th>Tipo Matéria</th>
<th>Ementa</th> <th>Quantidade</th>
<th>Autor(es)</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for materia in object_list %} {% for key, value in qtdes.items %}
<tr> <tr>
<td><a href="{% url 'sapl.materia:materialegislativa_detail' materia.pk %}"> <td>{{key.sigla}} - {{key}}</td>
{{materia.tipo.descricao}} - {{materia.tipo.sigla}} {{materia.numero}}/{{materia.ano}} <td>{{value}}</td>
</a></td>
<td>{{materia.ementa}}</td>
<td>
{% for autor in materia.autoria_set.all %}
{{autor.autor}}<br />
{% endfor %}
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>

Loading…
Cancel
Save