From 7dde59f87383b7f824d8886620ff4c363c088d31 Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Mon, 20 Jun 2016 18:01:35 +0000 Subject: [PATCH] Avoid multiple doctype declarations and other html errors by parsing sesion agenda html files and inserting our title and doctype. - Legacy-Id: 11417 --- ietf/meeting/views.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/ietf/meeting/views.py b/ietf/meeting/views.py index 74b0d75e2..189184f60 100644 --- a/ietf/meeting/views.py +++ b/ietf/meeting/views.py @@ -10,6 +10,7 @@ from collections import OrderedDict, Counter import csv import json import pytz +from pyquery import PyQuery import debug # pyflakes:ignore @@ -592,11 +593,22 @@ def session_agenda(request, num, session): return HttpResponse(content, content_type="text/plain; charset=%s"%settings.DEFAULT_CHARSET) elif ext == "pdf": return HttpResponse(content, content_type="application/pdf") + elif ext in ["html", "htm"]: + d = PyQuery(content) + d("head title").empty() + d("head title").append(str(agenda)) + d('meta[http-equiv]').remove() + content = "" + d.html() + elif not content: + content = "

Could not read agenda file '%s'

" % agenda.external_url + content = (html5_preamble % agenda) + content + html5_postamble + agenda = "Error" else: - if not content: - content = "

Could not read agenda file '%s'

" % agenda.external_url - agenda = "Error" - return HttpResponse((html5_preamble % agenda) + content + html5_postamble) + content = "

Unrecognized agend file '%s'

" % agenda.external_url + content = (html5_preamble % agenda) + content + html5_postamble + agenda = "Error" + + return HttpResponse(content) raise Http404("No agenda for the %s session of IETF %s is available" % (session, num))