Browse Source

primeiro relatorio de diagnostico

stable/1.0
Felipe Vieira 13 years ago
parent
commit
adfcceb2ad
  1. 28
      sigi/apps/diagnosticos/views.py
  2. 18
      sigi/shortcuts.py
  3. 55
      sigi/templates/diagnosticos/diagnostico_pdf.html
  4. 5
      sigi/urls.py

28
sigi/apps/diagnosticos/views.py

@ -1,10 +1,12 @@
# -*- coding: utf8 -*-
import new
from django.http import HttpResponse
from django.utils import simplejson
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.views.decorators.cache import never_cache
from geraldo.generators import PDFGenerator
from sigi.apps.diagnosticos.urls import LOGIN_REDIRECT_URL
from sigi.apps.utils.decorators import login_required
@ -13,6 +15,7 @@ from sigi.apps.diagnosticos.models import Diagnostico, Categoria
from sigi.apps.casas.models import Funcionario
from sigi.apps.diagnosticos.forms import (DiagnosticoMobileForm,
CasaLegislativaMobileForm, FuncionariosMobileForm)
from sigi.shortcuts import render_to_pdf
@never_cache
@ -185,3 +188,28 @@ def categoria_contatos(request, id_diagnostico):
'diagnostico': diagnostico, 'casa_legislativa': casa_legislativa})
return render_to_response('diagnosticos/diagnosticos_categoria_contatos_form.html',
context)
def diagnostico_pdf(request, id_diagnostico):
diagnostico = Diagnostico.objects.get(pk=id_diagnostico)
categorias = Categoria.objects.all()
forms = []
for categoria in categorias:
form = DiagnosticoMobileForm(
instance=diagnostico,
category=categoria.id
)
fields = []
for field in form:
#field.value = field.data[field.name]
fields.append(field)
forms.append((categoria,fields))
context = RequestContext(request, {
'pagesize':'A4',
'diagnostico': diagnostico,
'forms': forms,
})
return render_to_response('diagnosticos/diagnostico_pdf.html', context)

18
sigi/shortcuts.py

@ -0,0 +1,18 @@
import cStringIO as StringIO
import ho.pisa as pisa
from django.template.loader import get_template
from django.template import Context
from django.http import HttpResponse
from cgi import escape
def render_to_pdf(template_src, context_dict):
template = get_template(template_src)
context = Context(context_dict)
html = template.render(context)
result = StringIO.StringIO()
pdf = pisa.pisaDocument(StringIO.StringIO(html.encode('utf-8')), result)
if not pdf.err:
return HttpResponse(result.getvalue(), mimetype='application/pdf')
return HttpResponse('We had some errors<pre>%s</pre>' % escape(html))

55
sigi/templates/diagnosticos/diagnostico_pdf.html

@ -0,0 +1,55 @@
<!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>My Title</title>
<style type="text/css">
@page {
size: {{ pagesize }};
margin: 2cm;
@frame header {
-pdf-frame-content: header;
top: 0.5cm;
margin-left: 9cm;
margin-right: 9cm;
height: 1cm;
}
@frame footer {
-pdf-frame-content: footer;
bottom: 0cm;
margin-left: 9cm;
margin-right: 9cm;
height: 1cm;
}
}
</style>
</head>
<body>
<div id="header">
{%block page_header%}
Interlegis
{%endblock%}
</div>
<div>
{% for categoria, fields in forms %}
<h1>Bloco {{categoria.nome}}</h1>
{% for field in fields %}
<h2>
{% if field.help_text %}
{{ field.label }} ({{ field.help_text }})
{% else %}
{{ field.label }}
{% endif %}
</h2>
<p>{{ field }}<p>
{% endfor %}
<pdf:nextpage>
{% endfor %}
</div>
<div id="footer">
{%block page_foot%}
Página <pdf:pagenumber>
{%endblock%}
</div>
</body>
</html>

5
sigi/urls.py

@ -37,7 +37,10 @@ urlpatterns = patterns(
'sigi.apps.casas.views.casas_sem_convenio_report'),
# reports convenios
(r'^sigi/convenios/convenio/reports/',
'sigi.apps.convenios.views.report'),
'sigi.apps.convenios.views.report'),
# reports diagnosticos
(r'^sigi/diagnosticos/diagnostico/(?P<id_diagnostico>\w+).pdf',
'sigi.apps.diagnosticos.views.diagnostico_pdf'),
#Carrinho Casa
(r'^sigi/casas/casalegislativa/carrinho/deleta_itens_carrinho',
'sigi.apps.casas.views.deleta_itens_carrinho'),

Loading…
Cancel
Save