2013-10-01 21:40:42 +00:00
|
|
|
from django.shortcuts import render
|
2013-10-14 16:07:15 +00:00
|
|
|
from django.contrib.sites.models import get_current_site
|
2013-10-02 11:22:36 +00:00
|
|
|
from django.http import HttpResponse
|
2014-04-21 13:46:55 +00:00
|
|
|
from django.template.loader import render_to_string
|
2014-06-20 18:53:37 +00:00
|
|
|
from django.template.response import TemplateResponse
|
2014-06-19 08:53:22 +00:00
|
|
|
from django.core.urlresolvers import reverse
|
2014-04-21 13:46:55 +00:00
|
|
|
from StringIO import StringIO
|
|
|
|
from xhtml2pdf import pisa
|
2013-10-02 11:22:36 +00:00
|
|
|
|
2014-06-19 08:53:22 +00:00
|
|
|
def resumelink(request):
|
|
|
|
return request.build_absolute_uri(reverse('basics:resumepdf'))
|
|
|
|
|
2014-04-21 13:46:55 +00:00
|
|
|
def resumepdf(request):
|
2014-06-19 08:53:22 +00:00
|
|
|
body = render_to_string('basics/resume.html', {
|
|
|
|
'resume_link': resumelink(request),
|
|
|
|
'pdf': True
|
2014-06-22 15:42:05 +00:00
|
|
|
}).replace('<span class="at-obfuscation"></span>', '@')
|
2014-04-21 13:46:55 +00:00
|
|
|
dst = StringIO()
|
|
|
|
pdf = pisa.CreatePDF(body, dst)
|
|
|
|
pdf_data = dst.getvalue()
|
|
|
|
dst.close()
|
|
|
|
|
|
|
|
if not pdf.err:
|
2014-06-19 08:55:39 +00:00
|
|
|
return HttpResponse(pdf_data, content_type = 'application/pdf')
|
2014-04-21 13:46:55 +00:00
|
|
|
|
2014-06-19 08:52:18 +00:00
|
|
|
return HttpResponse('We had some errors: <pre>%s</pre>' % escape(html))
|
2014-04-21 13:46:55 +00:00
|
|
|
|
2013-10-01 21:40:42 +00:00
|
|
|
def resume(request):
|
2014-06-19 08:53:22 +00:00
|
|
|
return render(request, 'basics/resume.html', {
|
|
|
|
'resume_link': resumelink(request)
|
|
|
|
})
|
2013-10-01 21:40:42 +00:00
|
|
|
|
|
|
|
def about(request):
|
|
|
|
return render(request, 'basics/about.html', {})
|
|
|
|
|
|
|
|
def disclaimer(request):
|
|
|
|
return render(request, 'basics/disclaimer.html', {})
|
2014-06-14 17:09:10 +00:00
|
|
|
|
|
|
|
def notfound(request):
|
2014-06-20 18:53:37 +00:00
|
|
|
return TemplateResponse(request, 'basics/notfound.html', status = 404).render()
|
2014-06-14 17:09:10 +00:00
|
|
|
|
|
|
|
def serverror(request):
|
2014-06-20 18:53:37 +00:00
|
|
|
return TemplateResponse(request, 'basics/serverror.html', status = 500).render()
|
2014-06-14 17:09:10 +00:00
|
|
|
|
|
|
|
def forbidden(request):
|
2014-06-20 18:53:37 +00:00
|
|
|
return TemplateResponse(request, 'basics/forbidden.html', status = 403).render()
|
2014-06-14 17:09:10 +00:00
|
|
|
|
|
|
|
def badrequest(request):
|
2014-06-20 18:53:37 +00:00
|
|
|
return TemplateResponse(request, 'basics/badrequest.html', status = 400).render()
|