Browse Source

Refatora relatório completo de Casa para usar Pisa

pull/11/head
Sesostris Vieira 6 years ago
parent
commit
3e14232c7b
  1. 288
      sigi/apps/casas/reports.py
  2. 237
      sigi/apps/casas/templates/casas/report_complete_pdf.html
  3. 60
      sigi/apps/casas/views.py

288
sigi/apps/casas/reports.py

@ -1,8 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.templatetags.static import static
from django.utils.translation import ugettext as _
from geraldo import Report, DetailBand, Label, ObjectValue, ReportGroup, ReportBand, landscape, SubReport, BAND_WIDTH, SystemField from geraldo import Report, DetailBand, Label, ObjectValue, ReportGroup, ReportBand, landscape, SubReport, BAND_WIDTH, SystemField
from geraldo.graphics import Image from geraldo.graphics import Image
from django.templatetags.static import static
from django.utils.translation import ugettext as _
from reportlab.lib.enums import TA_CENTER from reportlab.lib.enums import TA_CENTER
from reportlab.lib.pagesizes import A4 from reportlab.lib.pagesizes import A4
from reportlab.lib.units import cm from reportlab.lib.units import cm
@ -238,7 +239,6 @@ class CasasLegislativasReport(ReportDefault):
top=label_top, top=label_top,
), ),
] ]
class band_page_footer(ReportDefault.band_page_footer): class band_page_footer(ReportDefault.band_page_footer):
@ -293,285 +293,3 @@ class CasasLegislativasReport(ReportDefault):
class CasasSemConvenioReport(CasasLegislativasReport): class CasasSemConvenioReport(CasasLegislativasReport):
title = _(u'Relatório de Casas Legislativas sem Convênio') title = _(u'Relatório de Casas Legislativas sem Convênio')
class InfoCasaLegislativa(ReportDefault):
title = _(u'Casa Legislativa')
class band_summary(ReportBand):
pass
class band_page_footer(ReportBand):
height = 1 * cm
elements = [
SystemField(expression=_(u'%(now:%d/%m/%Y)s às %(now:%H:%M)s'), top=0.3 * cm),
]
class band_detail(ReportDefault.band_detail):
posicao_left = [
0, 1.3, # Tipo
0, 1.8, # Regiao
5.5, 6.8, # U.F.
0, 2.3, # Municipio
0, 2.4, # Endereco
0, 1.6, # Bairro
0, 1.3, # CEP
0, 1.6, # CNPJ
0, 2.3, # Telefone
0, 2.7, # Presidente
]
posicao_top = [
0.5, # Tipo
1.3, # Regiao
1.3, # U.F.
2.1, # Municipio
2.9, # Logradouro
3.7, # Bairro
4.5, # CEP
5.3, # CNPJ
6.1, # Telefone
6.9, # Presidente
]
height = 30 * cm
display_inline = True
default_style = {'fontName': 'Helvetica', 'fontSize': 14}
elements = [
Label(
text=label_text(_(u"Tipo")),
left=posicao_left[0] * cm,
top=posicao_top[0] * cm,
),
ObjectValue(
attribute_name='tipo.nome',
left=posicao_left[1] * cm,
top=posicao_top[0] * cm,
width=6 * cm,
),
Label(
text=label_text(_(u"Região")),
left=posicao_left[2] * cm,
top=posicao_top[1] * cm,
),
ObjectValue(
attribute_name='municipio.uf.regiao',
left=posicao_left[3] * cm,
top=posicao_top[1] * cm,
get_value=lambda instance:
{'SL': _(u'Sul'), 'SD': _(u'Sudeste'), 'CO': _(u'Centro-Oeste'), 'NE': _(u'Nordeste'), 'NO': _(u'Norte'), }
[instance.municipio.uf.regiao]
),
Label(
text=label_text(_(u"UF")),
left=posicao_left[4] * cm,
top=posicao_top[2] * cm,
),
ObjectValue(
attribute_name='municipio.uf',
left=posicao_left[5] * cm,
top=posicao_top[2] * cm,
),
Label(
text=label_text(_(u"Município")),
left=posicao_left[6] * cm,
top=posicao_top[3] * cm,
),
ObjectValue(
attribute_name='municipio.nome',
left=posicao_left[7] * cm,
top=posicao_top[3] * cm,
width=20 * cm,
),
# Linha 3
Label(
text=label_text(_(u"Endereço")),
left=posicao_left[8] * cm,
top=posicao_top[4] * cm,
),
ObjectValue(
attribute_name='logradouro',
left=posicao_left[9] * cm,
top=posicao_top[4] * cm,
width=20 * cm,
),
Label(
text=label_text(_(u"Bairro")),
left=posicao_left[10] * cm,
top=posicao_top[5] * cm,
),
ObjectValue(
attribute_name='bairro',
left=posicao_left[11] * cm,
top=posicao_top[5] * cm,
),
Label(
text=label_text(_(u"CEP")),
left=posicao_left[12] * cm,
top=posicao_top[6] * cm,
),
ObjectValue(
attribute_name='cep',
left=posicao_left[13] * cm,
top=posicao_top[6] * cm,
),
Label(
text=label_text(_(u"CNPJ")),
left=posicao_left[14] * cm,
top=posicao_top[7] * cm,
),
ObjectValue(
attribute_name='cnpj',
left=posicao_left[15] * cm,
top=posicao_top[7] * cm,
),
Label(
text=label_text(_(u"Telefone")),
left=posicao_left[16] * cm,
top=posicao_top[8] * cm,
),
ObjectValue(
attribute_name='telefone',
left=posicao_left[17] * cm,
top=posicao_top[8] * cm,
),
Label(
text=label_text(_(u"Presidente")),
left=posicao_left[18] * cm,
top=posicao_top[9] * cm,
),
ObjectValue(
attribute_name='presidente',
left=posicao_left[19] * cm,
top=posicao_top[9] * cm,
width=20 * cm,
),
]
# Telefones
tel_top = 2 * cm
tel_left = [0, 3, 5]
# Contato
cont_top = 2 * cm
cont_left = [0, 6, 9]
# Convenios
convenio_top = 2 * cm
convenio_left = [0, 1.8, 4.5, 8, 10.5, 13, 15.5, 18]
subreports = [
# Telefones
SubReport(
queryset_string='%(object)s.telefones.all()',
band_header=ReportBand(
default_style={'fontName': 'Helvetica', 'fontSize': 12},
height=2.5 * cm,
elements=[
Label(
text=_(u"Telefone(s)"),
style={'fontSize': 14, 'alignment': TA_CENTER},
width=BAND_WIDTH,
top=1 * cm,
),
Label(text=_(u"Número"), left=tel_left[0] * cm, top=tel_top),
Label(text=_(u"Tipo"), left=tel_left[1] * cm, top=tel_top),
Label(text=_(u"Nota"), left=tel_left[2] * cm, top=tel_top),
],
borders={'bottom': True},
),
band_detail=ReportBand(
default_style={'fontName': 'Helvetica', 'fontSize': 11},
height=0.5 * cm,
elements=[
ObjectValue(attribute_name='__unicode__', left=tel_left[0] * cm),
ObjectValue(attribute_name='tipo', left=tel_left[1] * cm,
get_value=lambda instance:
{'F': _(u'Fixo'), 'M': _(u'Móvel'), 'X': _(u'Fax'), 'I': _(u'Indefinido')}[instance.tipo],
),
ObjectValue(attribute_name='nota', left=tel_left[2] * cm),
],
#borders = {'all':True},
),
),
# Contatos
SubReport(
queryset_string='%(object)s.funcionario_set.all()',
band_header=ReportBand(
default_style={'fontName': 'Helvetica', 'fontSize': 12},
height=2.5 * cm,
elements=[
Label(
text=_(u"Contato(s)"),
style={'fontSize': 14, 'alignment': TA_CENTER},
width=BAND_WIDTH,
top=1 * cm,
),
Label(text=_(u"Nome"), left=cont_left[0] * cm, top=cont_top),
Label(text=_(u"Nota"), left=cont_left[1] * cm, top=cont_top),
Label(text=_(u"E-mail"), left=cont_left[2] * cm, top=cont_top),
],
borders={'bottom': True, 'top': True},
),
band_detail=ReportBand(
default_style={'fontName': 'Helvetica', 'fontSize': 11},
height=0.5 * cm,
elements=[
ObjectValue(attribute_name='nome', left=cont_left[0] * cm),
ObjectValue(attribute_name='nota', left=cont_left[1] * cm),
ObjectValue(attribute_name='email', left=cont_left[2] * cm),
],
#borders = {'all':True},
),
),
# Convenios
SubReport(
queryset_string='%(object)s.convenio_set.all()',
band_header=ReportBand(
default_style={'fontName': 'Helvetica', 'fontSize': 12},
height=2.5 * cm,
elements=[
Label(
text=_(u"Convênio(s)"),
style={'fontSize': 14, 'alignment': TA_CENTER},
width=BAND_WIDTH,
top=1 * cm,
),
Label(text=_(u"Projeto"), left=convenio_left[0] * cm, top=convenio_top),
Label(text=_(u"Nº Convenio"), left=convenio_left[1] * cm, top=convenio_top),
Label(text=_(u"Nº Processo SF"), left=convenio_left[2] * cm, top=convenio_top),
Label(text=_(u"Adesão"), left=convenio_left[3] * cm, top=convenio_top),
Label(text=_(u"Convênio"), left=convenio_left[4] * cm, top=convenio_top),
Label(text=_(u"Equipada"), left=convenio_left[5] * cm, top=convenio_top),
Label(text=_(u"Data D.O."), left=convenio_left[6] * cm, top=convenio_top),
],
borders={'bottom': True}
),
band_detail=ReportBand(
default_style={'fontName': 'Helvetica', 'fontSize': 11},
height=0.5 * cm,
elements=[
ObjectValue(attribute_name='projeto.sigla', left=convenio_left[0] * cm),
ObjectValue(attribute_name='num_convenio', left=convenio_left[1] * cm),
ObjectValue(attribute_name='num_processo_sf', left=convenio_left[2] * cm),
ObjectValue(attribute_name='data_adesao', left=convenio_left[3] * cm,
get_value=lambda instance:
instance.data_adesao.strftime('%d/%m/%Y') if instance.data_adesao is not None else '-'
),
ObjectValue(attribute_name='data_retorno_assinatura', left=convenio_left[4] * cm,
get_value=lambda instance:
instance.data_retorno_assinatura.strftime('%d/%m/%Y') if instance.data_retorno_assinatura is not None else '-'
),
ObjectValue(attribute_name='data_termo_aceite', left=convenio_left[5] * cm,
get_value=lambda instance:
instance.data_termo_aceite.strftime('%d/%m/%Y') if instance.data_termo_aceite is not None else '-'
),
ObjectValue(attribute_name='data_pub_diario', left=convenio_left[6] * cm,
get_value=lambda instance:
instance.data_pub_diario.strftime('%d/%m/%Y') if instance.data_pub_diario is not None else '-'
),
],
#borders = {'all':True},
),
)
]

237
sigi/apps/casas/templates/casas/report_complete_pdf.html

@ -0,0 +1,237 @@
{% load smart_if %}
{% load static from staticfiles %}
{% load i18n %}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Casa Legislativa</title>
<style type="text/css">
table {
padding: 3px;
line-height: 1em;
-fs-table-paginate: paginate;
}
thead {
display: table-header-group;
}
th {
font-weight: bold;
text-align: left;
}
th, td {
border-bottom: 1px solid #ddd;
}
.identificacao th {
width: 20%;
}
div#capa h3 {
text-align: center;
margin-top: 5px;
margin-bottom: 0px;
}
div#capa p {
text-align: center;
}
td.logo {
text-align: center;
}
td.header_text p {
margin: 0px;
font-size: 1.4em;
}
td.header_text {
width: 550px;
}
ul {
list-style-type: none;
padding-left: 15px;
}
li {
padding-left: 5px;
color: #999;
}
li.selected {
list-style-type: disc;
color: #000;
font-weight: bold;
}
p.strong {
margin-left: 25px;
line-height: 1em;
}
h1 {
font-size: 2em;
text-align: center;
}
h2 {
font-size: 1.7em;
}
h3 {
margin-top: 10px;
margin-bottom: 0px;
}
body {
font-family: "Helvetica, Arial, sans-serif";
font-size: 1.3em;
line-height: 1em;
}
div.new_page {
page-break-before: always;
}
div.same_page_ {
-pdf-keep-with-next: true;
}
@page {
size: {{ pagesize }};
margin: 4cm 1cm 1cm 2cm;
font-family: "Helvetica, Arial, sans-serif";
font-size: 2em;
@frame header {
-pdf-frame-content: header;
top: 1cm;
}
@frame footer {
-pdf-frame-content: footer;
bottom: 0cm;
margin-left: 9cm;
margin-right: 9cm;
height: 1cm;
}
}
</style>
</head>
<body>
<div id="header">
<table>
<tr>
<td class="logo"><img src="{% static 'img/logo-senado.jpg' %}"/></td>
<td class="header_text">
<p><strong>{% trans 'SENADO FEDERAL' %}</strong></p>
<p><strong>{% trans 'ILB - Interlegis' %}</strong></p>
<p>{% trans 'Relatório completo' %}</p>
</td>
<td class="logo"><img src="{% static 'img/logo-interlegis.jpg' %}"/></td>
</tr>
</table>
</div>
{% for casa in casas %}
<div class="{% if forloop.first %}{% else %}new_page{% endif %}">
<h2>{{ casa.nome }}</h2>
<table class="identificacao">
<tr><th>{% trans 'Presidente:' %}</th><td>{{ casa.presidente }}</td></tr>
<tr><th>{% trans 'Tipo:' %}</th><td>{{ casa.tipo.nome }}</td></tr>
<tr><th>{% trans 'Estado / região:' %}</th><td>{{ casa.municipio.uf.nome }} / {{ casa.municipio.uf.get_regiao_display }}</td></tr>
<tr><th>{% trans 'Município:' %}</th><td>{{ casa.municipio.nome }}</td></tr>
<tr><th>{% trans 'Endereço:' %}</th><td>{{ casa.logradouro }}</td></tr>
<tr><th>{% trans 'Bairro:' %}</th><td>{{ casa.bairro }}</td></tr>
<tr><th>{% trans 'CEP:' %}</th><td>{{ casa.cep }}</td></tr>
<tr><th>{% trans 'CNPJ:' %}</th><td>{{ casa.cnpj }}</td></tr>
<tr><th>{% trans 'Telefone:' %}</th><td>{{ casa.telefone }}</td></tr>
<tr><th>{% trans 'E-mail:' %}</th><td>{{ casa.email }}</td></tr>
</table>
<h3>Telefones</h3>
<table repeat="1">
<thead>
<tr>
<th>Número</th>
<th>Tipo</th>
<th>Nota</th>
</tr>
<thead>
{% for tel in casa.telefones.all %}
<tr>
<td>{{ tel.numero }}</td>
<td>{{ tel.get_tipo_display }}</td>
<td>{{ tel.nota }}</td>
</tr>
{% endfor %}
</table>
<h3>Pessoas de contato</h3>
<table repeat="1">
<thead>
<tr>
<th>Nome</th>
<th>E-mail</th>
<th>Setor</th>
<th>Notas</th>
</tr>
</thead>
{% for func in casa.funcionario_set.all %}
<tr>
<td>{{ func.nome }}</td>
<td>{{ func.email }}</td>
<td>{{ func.get_setor_display }}</td>
<td>{{ func.nota }}</td>
</tr>
{% endfor %}
</table>
<h3>Convênios</h3>
<table repeat="1">
<thead>
<tr>
<th>Projeto</th>
<th>Nº convênio</th>
<th>Nº processo SF</th>
<th>Adesão</th>
<th>Convênio</th>
<th>Equipada</th>
<th>Publicada</th>
</tr>
</thead>
{% for conv in casa.convenio_set.all %}
<tr>
<td>{{ conv.projeto.nome }}</td>
<td>{{ conv.num_convenio|default_if_none:"-" }}</td>
<td>{{ conv.num_processo_sf|default_if_none:"-" }}</td>
<td>{{ conv.data_adesao|date:"SHORT_DATE_FORMAT" }}</td>
<td>{{ conv.data_retorno_assinatura|date:"SHORT_DATE_FORMAT" }}</td>
<td>{{ conv.equipada|yesno }}</td>
<td>{{ conv.data_pub_diario|date:"SHORT_DATE_FORMAT" }}</td>
</tr>
{% endfor %}
</table>
<h3>Serviços Interlegis</h3>
<table repeat="1">
<thead>
<tr>
<th>Serviço</th>
<th>Endereço</th>
<th>Ativado em</th>
<th>Desativado em</th>
</tr>
</thead>
{% for srv in casa.servico_set.all %}
<tr>
<td>{{ srv.tipo_servico.nome }}</td>
<td>{{ srv.url|default_if_none:"-" }}</td>
<td>{{ srv.data_ativacao|date:"SHORT_DATE_FORMAT" }}</td>
<td>{{ srv.data_desativacao|date:"SHORT_DATE_FORMAT" }}</td>
</tr>
{% endfor %}
</table>
</div>
{% endfor %}
<div id="footer">
{%block page_foot%}
{% trans 'Página' %} <pdf:pagenumber>
{%endblock%}
</div>
</body>
</html>

60
sigi/apps/casas/views.py

@ -1,30 +1,31 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import csv import csv
from functools import reduce from functools import reduce
from geraldo.generators import PDFGenerator
from django.contrib.auth.decorators import login_required
from django.core.paginator import Paginator, InvalidPage, EmptyPage from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.http import HttpResponse, HttpResponseRedirect, Http404 from django.db.models import Count, Q
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render, get_object_or_404 from django.shortcuts import render, get_object_or_404
from django.utils.translation import ugettext as _, ungettext from django.utils.translation import ugettext as _, ungettext
from geraldo.generators import PDFGenerator
from sigi.apps.casas.forms import PortfolioForm
from sigi.apps.casas.models import CasaLegislativa from sigi.apps.casas.models import CasaLegislativa
from sigi.apps.casas.reports import CasasLegislativasLabels, CasasLegislativasLabelsSemPresidente, CasasLegislativasReport, CasasSemConvenioReport, InfoCasaLegislativa from sigi.apps.casas.reports import (CasasLegislativasLabels,
from sigi.apps.parlamentares.reports import ParlamentaresLabels CasasLegislativasLabelsSemPresidente,
CasasLegislativasReport,
CasasSemConvenioReport)
from sigi.apps.contatos.models import UnidadeFederativa, Mesorregiao, Microrregiao from sigi.apps.contatos.models import UnidadeFederativa, Mesorregiao, Microrregiao
from sigi.apps.casas.forms import PortfolioForm from sigi.apps.ocorrencias.models import Ocorrencia
from django.contrib.auth.decorators import login_required from sigi.apps.parlamentares.reports import ParlamentaresLabels
from sigi.apps.servicos.models import TipoServico from sigi.apps.servicos.models import TipoServico
from sigi.apps.servidores.models import Servidor from sigi.apps.servidores.models import Servidor
from sigi.apps.ocorrencias.models import Ocorrencia from sigi.shortcuts import render_to_pdf
from django.db.models import Count, Q
from django.http.response import JsonResponse
# @param qs: queryset # @param qs: queryset
# @param o: (int) number of order field # @param o: (int) number of order field
def query_ordena(qs, o): def query_ordena(qs, o):
from sigi.apps.casas.admin import CasaLegislativaAdmin from sigi.apps.casas.admin import CasaLegislativaAdmin
list_display = CasaLegislativaAdmin.list_display list_display = CasaLegislativaAdmin.list_display
@ -85,6 +86,7 @@ def adicionar_casas_carrinho(request, queryset=None, id=None):
lista.append(id) lista.append(id)
request.session['carrinho_casas'] = lista request.session['carrinho_casas'] = lista
@login_required @login_required
def visualizar_carrinho(request): def visualizar_carrinho(request):
@ -117,12 +119,14 @@ def visualizar_carrinho(request):
} }
) )
@login_required @login_required
def excluir_carrinho(request): def excluir_carrinho(request):
if 'carrinho_casas' in request.session: if 'carrinho_casas' in request.session:
del request.session['carrinho_casas'] del request.session['carrinho_casas']
return HttpResponseRedirect('.') return HttpResponseRedirect('.')
@login_required @login_required
def deleta_itens_carrinho(request): def deleta_itens_carrinho(request):
if request.method == 'POST': if request.method == 'POST':
@ -139,6 +143,7 @@ def deleta_itens_carrinho(request):
return HttpResponseRedirect('.') return HttpResponseRedirect('.')
@login_required @login_required
def labels_report(request, id=None, tipo=None, formato='3x9_etiqueta'): def labels_report(request, id=None, tipo=None, formato='3x9_etiqueta'):
""" TODO: adicionar suporte para resultado de pesquisa do admin. """ TODO: adicionar suporte para resultado de pesquisa do admin.
@ -168,6 +173,7 @@ def labels_report(request, id=None, tipo=None, formato='3x9_etiqueta'):
return response return response
@login_required @login_required
def labels_report_parlamentar(request, id=None, formato='3x9_etiqueta'): def labels_report_parlamentar(request, id=None, formato='3x9_etiqueta'):
""" TODO: adicionar suporte para resultado de pesquisa do admin. """ TODO: adicionar suporte para resultado de pesquisa do admin.
@ -216,6 +222,7 @@ def carrinhoOrGet_for_parlamentar_qs(request):
qs = get_for_qs(request.GET, qs) qs = get_for_qs(request.GET, qs)
return qs return qs
@login_required @login_required
def labels_report_sem_presidente(request, id=None, formato='2x5_etiqueta'): def labels_report_sem_presidente(request, id=None, formato='2x5_etiqueta'):
""" TODO: adicionar suporte para resultado de pesquisa do admin. """ TODO: adicionar suporte para resultado de pesquisa do admin.
@ -236,6 +243,7 @@ def labels_report_sem_presidente(request, id=None, formato='2x5_etiqueta'):
return response return response
@login_required @login_required
def report(request, id=None, tipo=None): def report(request, id=None, tipo=None):
@ -261,6 +269,7 @@ def report(request, id=None, tipo=None):
report.generate_by(PDFGenerator, filename=response) report.generate_by(PDFGenerator, filename=response)
return response return response
@login_required @login_required
def report_complete(request, id=None): def report_complete(request, id=None):
@ -272,32 +281,8 @@ def report_complete(request, id=None):
if not qs: if not qs:
return HttpResponseRedirect('../') return HttpResponseRedirect('../')
response = HttpResponse(content_type='application/pdf') return render_to_pdf('casas/report_complete_pdf.html', {'casas': qs})
response['Content-Disposition'] = 'attachment; filename=casas.pdf'
# Gera um relatorio para cada casa e concatena os relatorios
cont = 0
canvas = None
quant = qs.count()
if quant > 1:
for i in qs:
cont += 1
# queryset deve ser uma lista
lista = (i,)
if cont == 1:
report = InfoCasaLegislativa(queryset=lista)
canvas = report.generate_by(PDFGenerator, return_canvas=True, filename=response,)
else:
report = InfoCasaLegislativa(queryset=lista)
if cont == quant:
report.generate_by(PDFGenerator, canvas=canvas)
else:
canvas = report.generate_by(PDFGenerator, canvas=canvas, return_canvas=True)
else:
report = InfoCasaLegislativa(queryset=qs)
report.generate_by(PDFGenerator, filename=response)
return response
@login_required @login_required
def casas_sem_convenio_report(request): def casas_sem_convenio_report(request):
@ -313,6 +298,7 @@ def casas_sem_convenio_report(request):
report.generate_by(PDFGenerator, filename=response) report.generate_by(PDFGenerator, filename=response)
return response return response
@login_required @login_required
def export_csv(request): def export_csv(request):
response = HttpResponse(content_type='text/csv') response = HttpResponse(content_type='text/csv')
@ -392,6 +378,7 @@ def export_csv(request):
return response return response
@login_required @login_required
def portfolio(request): def portfolio(request):
page = request.GET.get('page', 1) page = request.GET.get('page', 1)
@ -602,6 +589,7 @@ def casas_carteira(request, casas, context):
return casas, context return casas, context
@login_required @login_required
def painel_relacionamento(request): def painel_relacionamento(request):
page = request.GET.get('page', 1) page = request.GET.get('page', 1)

Loading…
Cancel
Save