PDF template updates

This commit is contained in:
nikolark committed 2012-02-02 23:20:16 +01:00
1 parent a6040edc86
commit 7ed799e6d3
5 files changed
+44 -22

No files matched your search

+17 -9
View File
@@ -4,21 +4,29 @@
# - http://stackoverflow.com/questions/1377446/html-to-pdf-for-a-django-site
# - http://stackoverflow.com/questions/2179958/django-pisa-adding-images-to-pdf-output ?
# - http://web.archive.org/web/20090413054650/http://www.xhtml2pdf.com/doc/pisa-en.html
import os
from cgi import escape
from django.template.loader import render_to_string
from django.template import RequestContext
from django.conf import settings
from django.http import HttpResponse
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)
def render_to_pdf(template_src, context_dict, context_instance):
html = render_to_string(template_src, context_dict, context_instance=context_instance)
result = StringIO.StringIO()
pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("UTF-8")), result)
pdf = pisa.pisaDocument(
StringIO.StringIO(html.encode("UTF-8")),
dest=result,
link_callback=fetch_resources)
if not pdf.err:
return HttpResponse(result.getvalue(), mimetype='application/pdf')
return HttpResponse('We had some errors<pre>%s</pre>' % escape(html))
def fetch_resources(uri, rel):
# Replace the url with the physical path.
path = os.path.join(settings.STATIC_ROOT, uri.replace(settings.STATIC_URL, ""))
return path
+18 -6
View File
@@ -20,6 +20,13 @@
.monospace {
font-family: monospace;
}
.sub_header {
font-size: 0.6em;
margin-bottom:1cm;
}
h1, h2 {
margin-bottom:0px;
}
#logo {
margin-top: 1cm;
}
@@ -29,17 +36,22 @@
{% for userpass in log.userpass_set.all %}
<div>
<h1>Midlertidig Bruker For Trådløst Nettverk på Chateau Neuf</h1>
Brukernavn: <span class="monospace">{{ userpass.username }}</span><br />
Passord: <span class="monospace">{{ userpass.password }}</span><br />
Utstedt: {{ log.created }}<br />
Gyldig til: {{ log.expires }}<br />
<span class="sub_header">Utstedt {{ log.created }}</span>
<h2>Din bruker</h2>
<strong>Brukernavn:</strong> <span class="monospace">{{ userpass.username }}</span><br />
<strong>Passord:</strong> <span class="monospace">{{ userpass.password }}</span><br />
<strong>Gyldig til og med:</strong> {{ log.expires|date:"DATE_FORMAT" }}<br />
<h2>Trådløst nettverk</h2>
Navn (SSID): <span class="monospace">dns-intern</span><br />
</div>
<div id="logo">
<img src="/home/nikolark/dev/edb/mbftns/static/standard/images/DNSlogo.jpg" />
<em>Tjenesten er levert av EDB-gruppa i Kommunikasjonsvavdelingen - kak-edb@studentersamfundet.no</em>
<img src="{{ STATIC_URL }}standard/images/edb_brick.jpg" /><br />
<img src="{{ STATIC_URL }}standard/images/DNSlogo.jpg" />
</div>
<div id="footerContent">
{% block page_foot %}
Page <pdf:pagenumber>
Side <pdf:pagenumber>
{% endblock %}
</div>
<pdf:nextpage>
+3 -3
View File
@@ -8,7 +8,7 @@
<th>Produsert</th>
<th>Produsert av</th>
<th>For hvem/Hvorfor</th>
<th>Utgår</th>
<th>Gyldig til og med</th>
<th>Antall</th>
<th>Skriv ut</th>
</tr>
@@ -17,7 +17,7 @@
<td>{{ user.created }}</td>
<td>{{ user.issued_by }}</td>
<td>{{ user.description }}</td>
<td>{{ user.expires|timeuntil}}</td>
<td>{{ user.expires|date:"DATE_FORMAT" }}</td>
<td>{{ user.count }}</td>
<td><a href="{% url download_pdf tempuserlog_id=user.id %}"><img src="{{STATIC_URL}}standard/images/printer.png" class="list" /></a></td>
</tr>
@@ -25,6 +25,6 @@
</table>
<a href="deleted">Vis utgåtte ...</a>
</p>
<a href="{% url system %}" class="btn">« Tilbake</a>
<a href="{% url system %}" class="btn">« Gå tilbake</a>
{% endblock %}
+2 -1
View File
@@ -99,5 +99,6 @@ def download_pdf(request, tempuserlog_id=-1):
{
'pagesize':'A4',
'log': log,
}
},
RequestContext(request)
)
+4 -3
View File
@@ -4,7 +4,7 @@ import os
import sys
from datetime import datetime
project_path = '/home/nikolark/dev/edb/mbftns/'
project_path = '/var/www/neuf.no/mbftns/mbftns/'
if project_path not in sys.path:
sys.path.append(project_path)
@@ -16,7 +16,8 @@ setup_environ(settings)
from main.models import *
from radius.models import *
# Find expired userpass objects, format into a list
# Find expired userpass objects, format into a list.
# Then use the id's in an inner query to delete them
# Note: Use this way of referencing since UserPass and Radcheck objects are in different DBs
up_ids = UserPass.objects.filter(log__expires__lte=datetime.now()).values_list('radcheck_id', flat=True)
# then use the id's in an inner query to delete them
Radcheck.objects.filter(id__in=list(up_ids)).delete()