Skip to content

Instantly share code, notes, and snippets.

@edsu edsu/views.py
Created Feb 5, 2009

Embed
What would you like to do?
#@cache_page(86400)
def page_pdf(request, lccn, date, edition, sequence):
title = get_object_or_404(models.Title, lccn=lccn)
_year, _month, _day = date.split("-")
try:
_date = datetime.date(int(_year), int(_month), int(_day))
except ValueError, e:
raise Http404
try:
issue = title.issues.get(date_issued=_date, edition=edition)
except models.Issue.DoesNotExist, e:
raise Http404
try:
page = issue.pages.get(sequence=int(sequence))
except models.Page.DoesNotExist, e:
raise Http404
f = file(page.pdf_abs_filename)
#content = f.read()
#return HttpResponse(content, mimetype='application/pdf')
response = HttpResponse(wsgiref.util.FileWrapper(f))
response['Content-Type'] = 'application/pdf'
response['Content-Disposition'] = 'Attachment; filename=file.pdf'
return response
return HttpResponse(content, mimetype='application/pdf')
#return HttpResponse(wsgiref.util.FileWrapper(f), mimetype='ap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.