Commit afafec7d authored by dario's avatar dario

web/views: return correct HTTP status on send_pdf_file errors

  * render_template: add HTTP status parameter
parent d68d8e80
...@@ -35,13 +35,14 @@ def theme_for_url(url): ...@@ -35,13 +35,14 @@ def theme_for_url(url):
return config.default_theme return config.default_theme
def render_template(template, **context): def render_template(template, status=200, **context):
try: try:
context['git_commit'] = util.gitVersion.gitVersion(config.basedir) context['git_commit'] = util.gitVersion.gitVersion(config.basedir)
except: except:
pass pass
return Response(jinja_env.get_template(template).render(**context), return Response(jinja_env.get_template(template).render(**context),
status=status,
mimetype='application/xhtml+xml') mimetype='application/xhtml+xml')
......
...@@ -144,8 +144,10 @@ def send_pdf_file(request, pdffile): ...@@ -144,8 +144,10 @@ def send_pdf_file(request, pdffile):
pdfid = str_truncate_if_tail_matches(pdffile, ".pdf") pdfid = str_truncate_if_tail_matches(pdffile, ".pdf")
if not pdfid in public_pdf_db: if not pdfid in public_pdf_db:
return render_template('error.xml', return render_template('error.xml',
error_text='There is no PDF file with that ID', status=404,
theme=local.theme) error_hdr='Error',
error_text='There is no PDF file with that ID',
theme=local.theme)
meta = public_pdf_db[pdfid].metadata meta = public_pdf_db[pdfid].metadata
is_internal = remote_is_internal_network(request) is_internal = remote_is_internal_network(request)
...@@ -161,6 +163,7 @@ def send_pdf_file(request, pdffile): ...@@ -161,6 +163,7 @@ def send_pdf_file(request, pdffile):
pass pass
else: else:
return render_template('error.xml', return render_template('error.xml',
status=403,
error_hdr='Error', error_hdr='Error',
error_text='This PDF file is available from the FAU internal network only', error_text='This PDF file is available from the FAU internal network only',
theme=local.theme) theme=local.theme)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment