Browse Source

geracao de pdf relatorio de presenca de dos parlamentares em sessoes

pull/2895/head
ricardocanela 6 years ago
parent
commit
ef9fc01c84
  1. 19
      sapl/base/forms.py
  2. 52
      sapl/base/views.py
  3. 25
      sapl/relatorios/views.py
  4. 13
      sapl/templates/relatorios/relatorio_materias_em_tramitacao.html
  5. 95
      sapl/templates/relatorios/relatorio_presenca_sessao.html

19
sapl/base/forms.py

@ -908,6 +908,8 @@ class RelatorioNormasVigenciaFilterSet(django_filters.FilterSet):
class RelatorioPresencaSessaoFilterSet(django_filters.FilterSet):
o = AnoNumeroOrderingFilter(help_text='')
class Meta(FilterOverridesMetaMixin):
model = SessaoPlenaria
fields = ['data_inicio',
@ -935,11 +937,26 @@ class RelatorioPresencaSessaoFilterSet(django_filters.FilterSet):
('tipo', 4)])
row3 = to_row([('exibir_ordem_dia', 12)])
buttons = FormActions(
*[
HTML('''
<div class="form-check">
<input name="relatorio" type="checkbox" class="form-check-input" id="relatorio">
<label class="form-check-label" for="relatorio">Gerar relatório PDF</label>
</div>
''')
],
Submit('pesquisar', _('Pesquisar'), css_class='float-right',
onclick='return true;'),
css_class='form-group row justify-content-between'
,
)
self.form.helper = SaplFormHelper()
self.form.helper.form_method = 'GET'
self.form.helper.layout = Layout(
Fieldset(_('Presença dos parlamentares nas sessões plenárias'),
row1, row2, row3, form_actions(label='Pesquisar'))
row1, row2, row3, buttons, )
)
@property

52
sapl/base/views.py

@ -30,7 +30,7 @@ from haystack.views import SearchView
from haystack.query import SearchQuerySet
from sapl.relatorios.views import (relatorio_materia_em_tramitacao, relatorio_materia_por_autor,
relatorio_materia_por_ano_autor)
relatorio_materia_por_ano_autor, relatorio_presenca_sessao)
from sapl import settings
from sapl.audiencia.models import AudienciaPublica, TipoAudienciaPublica
@ -541,6 +541,41 @@ class RelatorioPresencaSessaoView(FilterView):
return context
def get(self, request, *args, **kwargs):
super(RelatorioPresencaSessaoView, 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
length = self.object_list.count()
is_relatorio = request.GET.get('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_presenca_sessao(request, context)
else:
return self.render_to_response(context)
class RelatorioHistoricoTramitacaoView(FilterView):
model = MateriaLegislativa
@ -781,10 +816,7 @@ class RelatorioMateriasTramitacaoView(FilterView):
# é 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()
length = self.object_list.count()
is_relatorio = url != '' and request.GET.get('relatorio', None)
self.paginate_by = None if is_relatorio else self.paginate_by
@ -901,10 +933,7 @@ class RelatorioMateriasPorAnoAutorTipoView(FilterView):
# é 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()
length = self.object_list.count()
is_relatorio = request.GET.get('is_relatorio', None)
self.paginate_by = None if is_relatorio else self.paginate_by
@ -985,10 +1014,7 @@ class RelatorioMateriasPorAutorView(FilterView):
# é 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()
length = self.object_list.count()
is_relatorio = url != '' and request.GET.get('relatorio', None)
self.paginate_by = None if is_relatorio else self.paginate_by

25
sapl/relatorios/views.py

@ -1390,6 +1390,7 @@ def relatorio_materia_em_tramitacao(request, context):
return response
def relatorio_materia_por_autor(request, context):
base_url = request.build_absolute_uri()
casa = CasaLegislativa.objects.first()
@ -1412,6 +1413,7 @@ def relatorio_materia_por_autor(request, context):
return response
def relatorio_materia_por_ano_autor(request, context):
base_url = request.build_absolute_uri()
casa = CasaLegislativa.objects.first()
@ -1432,9 +1434,32 @@ def relatorio_materia_por_ano_autor(request, context):
response['Content-Transfer-Encoding'] = 'binary'
response.write(pdf_file)
return response
def relatorio_presenca_sessao(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_presenca_sessao.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):
base_url=request.build_absolute_uri()
logger = logging.getLogger(__name__)

13
sapl/templates/relatorios/relatorio_materias_em_tramitacao.html

@ -40,15 +40,16 @@
}
</style>
<link rel="stylesheet" href="{% static '/sapl/css/relatorio.css'%}">
</head>
</head>
<body>
<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 />
Ano: {{ ano }} <br />
Tipo de matéria: {{ tipo }}<br />
Status atual: {{ tramitacao__status }}<br />
Local atual: {{ tramitacao__unidade_tramitacao_destino }}<br /><br /><br />
{% if object_list|length %}
@ -74,7 +75,7 @@
{% for materia in object_list %}
<div style="border-top: 1px solid black;margin-bottom:0.3cm">
{% if request.user.is_anonymous and not d.restrito or not request.user.is_anonymous%}
{% if not request.user.is_anonymous%}
<strong>Matéria:</strong> {{materia.tipo.descricao}} {{materia.numero}}/{{materia.ano}}
</br>
<strong>Local Atual:</strong>&nbsp;<a> {{materia.tramitacao_set.last.unidade_tramitacao_destino}} </a>

95
sapl/templates/relatorios/relatorio_presenca_sessao.html

@ -0,0 +1,95 @@
{% 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>
<body>
<h2>Presença dos parlamentares nas sessões</h2>
<b>PARÂMETROS DE PESQUISA:<br /></b>
{% if show_results %}
<style type="text/css">
.presenca_table td, th{
text-align: center;
}
</style>
<br />
PERÍODO: {{periodo}}<br />
Legislatura: {{legislatura}}<br />
Sessão Legislativa: {{sessao_legislativa}}<br />
TOTAIS NO PERÍODO - SESSÕES: {{total_sessao}} - ORDENS DO DIA: {{total_ordemdia}}</b>
<br /><br />
<table class="table table-bordered table-hover presenca_table">
<thead class="thead-default" align="center">
<tr class="active">
<th rowspan="2">Nome Parlamentar / Partido</th>
<th rowspan="2">Titular?</th>
<th rowspan="2">Ativo?</th>
<th colspan="2">Sessão</th>
<th colspan="2">Ordem do Dia</th>
</tr>
<tr class="active">
<th>(Qtd)</th>
<th>( % )</th>
<th>(Qtd)</th>
<th>( % )</th>
</tr>
</thead>
<tbody>
{% for p in parlamentares %}
<tr>
<td><b>{{p.parlamentar}}</b> / {{p.parlamentar|filiacao_intervalo_filter:date_range|default:"Sem Partido"}}</td>
<td>{% if p.titular %} Sim {% else %} Não {% endif %}</td>
<td>{% if p.parlamentar.ativo %} Sim {% else %} Não {% endif %}</td>
<td>{{p.sessao_count}}</td>
<td>{{p.sessao_porc}}</td>
<td>{{p.ordemdia_count}}</td>
<td>{{p.ordemdia_porc}}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
</body>
Loading…
Cancel
Save