Browse Source

geracao de pdf relatorio de materias por ano autor tipo

pull/2895/head
ricardocanela 7 years ago
parent
commit
31a8f3ef2d
  1. 4
      sapl/base/forms.py
  2. 42
      sapl/base/views.py
  3. 25
      sapl/relatorios/views.py
  4. 7
      sapl/templates/relatorios/relatorio_materias_em_tramitacao.html
  5. 132
      sapl/templates/relatorios/relatorio_materias_por_ano_autor.html
  6. 6
      sapl/templates/relatorios/relatorio_materias_por_autor.html

4
sapl/base/forms.py

@ -1153,6 +1153,8 @@ class RelatorioMateriasPorAnoAutorTipoFilterSet(django_filters.FilterSet):
label='Ano da Matéria',
choices=choice_anos_com_materias)
o = AnoNumeroOrderingFilter(help_text='')
class Meta:
model = MateriaLegislativa
fields = ['ano']
@ -1182,7 +1184,7 @@ class RelatorioMateriasPorAnoAutorTipoFilterSet(django_filters.FilterSet):
self.form.helper = SaplFormHelper()
self.form.helper.form_method = 'GET'
self.form.helper.layout = Layout(
Fieldset(_('Pesquisa de Matéria por Autor'),
Fieldset(_('Pesquisa de Matéria por Ano Autor Tipo'),
row1,
buttons, )
)

42
sapl/base/views.py

@ -29,7 +29,8 @@ from django_filters.views import FilterView
from haystack.views import SearchView
from haystack.query import SearchQuerySet
from sapl.relatorios.views import relatorio_materia_em_tramitacao, relatorio_materia_por_autor
from sapl.relatorios.views import (relatorio_materia_em_tramitacao, relatorio_materia_por_autor,
relatorio_materia_por_ano_autor)
from sapl import settings
from sapl.audiencia.models import AudienciaPublica, TipoAudienciaPublica
@ -861,7 +862,7 @@ class RelatorioMateriasPorAnoAutorTipoView(FilterView):
return context
qtdes = {}
for tipo in TipoMateriaLegislativa.objects.all():
qs = kwargs['object_list']
qs = context['object_list']
qtde = len(qs.filter(tipo_id=tipo.id))
if qtde > 0:
qtdes[tipo] = qtde
@ -882,6 +883,43 @@ class RelatorioMateriasPorAnoAutorTipoView(FilterView):
return context
def get(self, request, *args, **kwargs):
super(RelatorioMateriasPorAnoAutorTipoView, self).get(request)
# Se a pesquisa estiver quebrando com a paginação
# Olhe esta função abaixo
# Provavelmente você criou um novo campo no Form/FilterSet
# Então a ordem da URL está diferente
data = self.filterset.data
if data and data.get('tipo') is not None:
url = "&" + str(self.request.environ['QUERY_STRING'])
if url.startswith("&page"):
ponto_comeco = url.find('tipo=') - 1
url = url[ponto_comeco:]
else:
url = ''
self.filterset.form.fields['o'].label = _('Ordenação')
# é usada essa verificação anônima para quando os documentos administrativos
# estão no modo ostensivo, mas podem existir documentos administrativos
# restritos
if request.user.is_anonymous():
length = self.object_list.filter(restrito=False).count()
else:
length = self.object_list.count()
is_relatorio = request.GET.get('is_relatorio', None)
self.paginate_by = None if is_relatorio else self.paginate_by
context = self.get_context_data(filter=self.filterset,
filter_url=url,
numero_res=length
)
context['show_results'] = show_results_filter_set(
self.request.GET.copy())
if is_relatorio:
return relatorio_materia_por_ano_autor(request, context)
else:
return self.render_to_response(context)
class RelatorioMateriasPorAutorView(FilterView):
model = MateriaLegislativa

25
sapl/relatorios/views.py

@ -1378,7 +1378,6 @@ def relatorio_materia_em_tramitacao(request, context):
header_context = {"casa": casa, 'logotipo': casa.logotipo, 'MEDIA_URL': MEDIA_URL}
#import ipdb; ipdb.set_trace();
html_template = render_to_string('relatorios/relatorio_materias_em_tramitacao.html', context)
html_header = render_to_string('relatorios/header_ata.html', header_context)
@ -1401,7 +1400,6 @@ def relatorio_materia_por_autor(request, context):
header_context = {"casa": casa, 'logotipo': casa.logotipo, 'MEDIA_URL': MEDIA_URL}
#import ipdb; ipdb.set_trace();
html_template = render_to_string('relatorios/relatorio_materias_por_autor.html', context)
html_header = render_to_string('relatorios/header_ata.html', header_context)
@ -1412,6 +1410,29 @@ def relatorio_materia_por_autor(request, context):
response['Content-Transfer-Encoding'] = 'binary'
response.write(pdf_file)
return response
def relatorio_materia_por_ano_autor(request, context):
base_url = request.build_absolute_uri()
casa = CasaLegislativa.objects.first()
rodape = ' '.join(get_rodape(casa))
context.update({'data': dt.today().strftime('%d/%m/%Y')})
context.update({'rodape': rodape})
header_context = {"casa": casa, 'logotipo': casa.logotipo, 'MEDIA_URL': MEDIA_URL}
html_template = render_to_string('relatorios/relatorio_materias_por_ano_autor.html', context)
html_header = render_to_string('relatorios/header_ata.html', header_context)
pdf_file = make_pdf(base_url=base_url, main_template=html_template, header_template=html_header)
response = HttpResponse(content_type='application/pdf;')
response['Content-Disposition'] = 'inline; filename=relatorio.pdf'
response['Content-Transfer-Encoding'] = 'binary'
response.write(pdf_file)
return response
def relatorio_sessao_plenaria_pdf(request, pk):

7
sapl/templates/relatorios/relatorio_materias_em_tramitacao.html

@ -43,6 +43,13 @@
</head>
<h2>Matérias em Tramitação</h2>
<b>PARÂMETROS DE PESQUISA:<br /></b>
&emsp;Ano: {{ ano }} <br />
&emsp;Tipo de matéria: {{ tipo }}<br />
&emsp;Status atual: {{ tramitacao__status }}<br />
&emsp;Local atual: {{ tramitacao__unidade_tramitacao_destino }}<br /><br /><br />
{% if object_list|length %}
<table class="table table-bordered table-hover">

132
sapl/templates/relatorios/relatorio_materias_por_ano_autor.html

@ -0,0 +1,132 @@
{% load i18n %}
{% load common_tags %}
{% load static %}
<head>
<style>
@page{
margin-top: 4.5cm;
size: A4 portrait;
@bottom-right {
content: "Página" counter(page);
height: 3cm;
font-size: 8pt;
}
@bottom-center {
border-top: 1px solid black;
font-size: 8pt;
height: 1cm;
content: "{{rodape|safe}}";
font-style:italic;
}
@bottom-left {
content: "{{data}}";
height: 3cm;
font-size: 8pt;
}
@top-center {
content: string(title);
}
header {
width: 0;
height: 0;
visibility: hidden;
string-set: title content();
}
}
</style>
<link rel="stylesheet" href="{% static '/sapl/css/relatorio.css'%}">
</head>
<h2>Matérias por Ano Autor Tipo</h2>
<b>PARÂMETROS DE PESQUISA:<br /></b>
&emsp;Ano: {{ano}}<br /><br /><br/>
{% if object_list|length %}
<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>
</br>
</br>
{% if object_list|length %}
<h1>Autorias</h1>
<br/><br/>
{% for r in relatorio %}
<h2>{{r.autor}}</h2><br/>
<table class="table table-bordered table-hover">
<thead class="thead-default" >
<tr class="active">
<th>Natureza da Propositura</th>
<th>Quantidade</th>
</tr>
</thead>
<tbody>
{% for i in r.materia %}
<tr>
<td>{{i.0}}</td><td>{{i.1}}</td>
</tr>
{% endfor %}
</tbody>
</table>
<h3>Total: {{r.total}}</h3><br/>
<br/>
<br/>
{% endfor %}
<br/><br/>
<h1>Coautorias</h1>
<br/><br/>
{% for r in corelatorio %}
<h2>{{r.autor}}</h2><br/>
<table class="table table-bordered table-hover">
<thead class="thead-default" >
<tr class="active">
<th>Natureza da Propositura</th>
<th>Quantidade</th>
</tr>
</thead>
<tbody>
{% for i in r.materia %}
<tr>
<td>{{i.0}}</td><td>{{i.1}}</td>
</tr>
{% endfor %}
</tbody>
</table>
<h3>Total: {{r.total}}</h3><br/>
<br/>
<br/>
{% endfor %}
{% endif %}
{% else %}
<h3>Nenhum documento encontrado com essas especificações</h3>
{% endif %}
</body>

6
sapl/templates/relatorios/relatorio_materias_por_autor.html

@ -43,6 +43,12 @@
</head>
<h2>Matérias por Autor</h2>
<b>PARÂMETROS DE PESQUISA:<br /></b>
&emsp;Autor: {{ autor }}<br />
&emsp;Tipo de matéria: {{ tipo }}<br />
&emsp;Data de apresentação: {{periodo}}<br /><br /><br/>
{% if object_list|length %}
<table class="table table-bordered table-hover">

Loading…
Cancel
Save