Skip to content
Snippets Groups Projects
Verified Commit 3a88c4b0 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Working TeX document generation.

parent a43cb72a
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,6 @@ setup( ...@@ -17,7 +17,6 @@ setup(
'django-bootstrap3', 'django-bootstrap3',
'django-ldapdb2>=0.9.2', 'django-ldapdb2>=0.9.2',
'django-leaflet', 'django-leaflet',
'django-latex',
'django-localflavor', 'django-localflavor',
'django-tables2', 'django-tables2',
'geopy', 'geopy',
......
...@@ -44,7 +44,6 @@ INSTALLED_APPS = [ ...@@ -44,7 +44,6 @@ INSTALLED_APPS = [
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'django_tables2', 'django_tables2',
'django_cron', 'django_cron',
'latex',
'leaflet', 'leaflet',
] ]
......
{% load i18n %}
{% autoescape off %} {% autoescape off %}
\documentclass{teckidsproto} \documentclass{teckidsproto}
......
...@@ -5,7 +5,6 @@ from django.template.loader import get_template ...@@ -5,7 +5,6 @@ from django.template.loader import get_template
from django.urls import reverse from django.urls import reverse
from django.template.loader import get_template from django.template.loader import get_template
from django_tables2 import RequestConfig from django_tables2 import RequestConfig
from latex import LatexDocument
from .tables import PersonTable from .tables import PersonTable
from .util import filter_disallowed_persons, get_relevant_groups, may_see_group, may_see_person from .util import filter_disallowed_persons, get_relevant_groups, may_see_group, may_see_person
...@@ -48,8 +47,8 @@ def persons(request, group=None): ...@@ -48,8 +47,8 @@ def persons(request, group=None):
format = request.GET.get('format', 'html') format = request.GET.get('format', 'html')
# For PDF format, determine template # For PDF format, determine template
if format == 'pdf': if format == 'pdf' or format == 'tex':
template = request.GET.get('template'. 'list_participants') template = request.GET.get('template', 'list_participants')
context = {} context = {}
...@@ -90,7 +89,7 @@ def persons(request, group=None): ...@@ -90,7 +89,7 @@ def persons(request, group=None):
"type": "Point", "type": "Point",
"coordinates": [person.longitude, person.latitude] "coordinates": [person.longitude, person.latitude]
}}) }})
elif format == 'pdf': elif format == 'pdf' or format == 'tex':
# Simply add persons to the context # Simply add persons to the context
context['persons'] = persons context['persons'] = persons
...@@ -100,26 +99,33 @@ def persons(request, group=None): ...@@ -100,26 +99,33 @@ def persons(request, group=None):
return render(request, 'ticdesk_org/persons.html', context) return render(request, 'ticdesk_org/persons.html', context)
elif format == 'geojson': elif format == 'geojson':
return JsonResponse(geojson, safe=False) return JsonResponse(geojson, safe=False)
elif format == 'pdf': elif format == 'pdf' or format == 'tex':
# Get the template and render it # Get the template and render it
tpl = get_template('ticdesk_org/%s.tex' % template) tpl = get_template('ticdesk_org/%s.tex' % template)
latex_str = tpl.render(context).encode('utf-8') latex_str = tpl.render(context).encode('utf-8')
# Pass rendered TeX string to django-latex if format == 'pdf':
latex_doc = LatexDocument(latex_str) # Pass rendered TeX string to django-latex
latex_doc = LatexDocument(latex_str)
# Pass all images of the persons for inclusion # Pass all images of the persons for inclusion
for person in persons: for person in persons:
latex_doc.add_file(person.jpeg_phot, '%s.jpg' % person.uid) latex_doc.add_file(person.jpeg_phot, '%s.jpg' % person.uid)
# Generate PDF # Generate PDF
pdf = latex_doc.as_pdf() pdf = latex_doc.as_pdf()
# Write HTTP response # Write HTTP response
res = HttpResponse(content_type='application/pdf') res = HttpResponse(content_type='application/pdf')
res['Content-Disposition'] = 'attachment; filename="%s_%s.pdf"' % (template, group.cn) res['Content-Disposition'] = 'attachment; filename="%s_%s.pdf"' % (template, group.cn)
res.write(pdf) res.write(pdf)
return res return res
elif format == 'tex':
# Write HTTP response
res = HttpResponse(content_type='text/x-tex')
res['Content-Disposition'] = 'attachment; filename="%s_%s.tex"' % (template, group.cn)
res.write(latex_str)
return res
def map(request): def map(request):
context = {} context = {}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment