From 7ed799e6d37e87bf30d14a7a0123645de9698971 Mon Sep 17 00:00:00 2001
From: Nikolai Kristiansen
Date: Thu, 2 Feb 2012 23:20:16 +0100
Subject: [PATCH] PDF template updates
---
main/pdf.py | 26 +++++++++++++++++---------
main/templates/pdf/new_temp_user.html | 24 ++++++++++++++++++------
main/templates/private/list.html | 6 +++---
main/views.py | 3 ++-
scripts/delete_expired.py | 7 ++++---
5 files changed, 44 insertions(+), 22 deletions(-)
diff --git a/main/pdf.py b/main/pdf.py
index 418c5df..88d6755 100644
--- a/main/pdf.py
+++ b/main/pdf.py
@@ -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%s
' % 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
diff --git a/main/templates/pdf/new_temp_user.html b/main/templates/pdf/new_temp_user.html
index cee5127..178efc5 100644
--- a/main/templates/pdf/new_temp_user.html
+++ b/main/templates/pdf/new_temp_user.html
@@ -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 %}
Midlertidig Bruker For Trådløst Nettverk på Chateau Neuf
- Brukernavn: {{ userpass.username }}
- Passord: {{ userpass.password }}
- Utstedt: {{ log.created }}
- Gyldig til: {{ log.expires }}
+
+ Din bruker
+ Brukernavn: {{ userpass.username }}
+ Passord: {{ userpass.password }}
+ Gyldig til og med: {{ log.expires|date:"DATE_FORMAT" }}
+ Trådløst nettverk
+ Navn (SSID): dns-intern
-

+
Tjenesten er levert av EDB-gruppa i Kommunikasjonsvavdelingen - kak-edb@studentersamfundet.no
+

+
diff --git a/main/templates/private/list.html b/main/templates/private/list.html
index 0bdc84d..ef34e16 100644
--- a/main/templates/private/list.html
+++ b/main/templates/private/list.html
@@ -8,7 +8,7 @@
Produsert |
Produsert av |
For hvem/Hvorfor |
- Utgår |
+ Gyldig til og med |
Antall |
Skriv ut |
@@ -17,7 +17,7 @@
{{ user.created }} |
{{ user.issued_by }} |
{{ user.description }} |
- {{ user.expires|timeuntil}} |
+ {{ user.expires|date:"DATE_FORMAT" }} |
{{ user.count }} |
 |
@@ -25,6 +25,6 @@
Vis utgåtte ...
-« Tilbake
+« Gå tilbake
{% endblock %}
diff --git a/main/views.py b/main/views.py
index a7f7682..a3f47de 100644
--- a/main/views.py
+++ b/main/views.py
@@ -99,5 +99,6 @@ def download_pdf(request, tempuserlog_id=-1):
{
'pagesize':'A4',
'log': log,
- }
+ },
+ RequestContext(request)
)
diff --git a/scripts/delete_expired.py b/scripts/delete_expired.py
index 8ef63d4..626131a 100755
--- a/scripts/delete_expired.py
+++ b/scripts/delete_expired.py
@@ -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()