Convert markdown to html if Accept header prioritizes text/html over text/markdown. Fixes #1926. Commit ready for merge.
- Legacy-Id: 16564
This commit is contained in:
parent
f76c46bef0
commit
65b3f93afe
|
@ -160,3 +160,21 @@ def is_nomcom_eligible(person, date=datetime.date.today()):
|
|||
is_iab = person.role_set.filter(group__acronym='iab',name_id__in=['member','chair']).exists()
|
||||
is_iaoc = person.role_set.filter(group__acronym='iaoc',name_id__in=['member','chair']).exists()
|
||||
return len(attended)>=3 and not (is_iesg or is_iab or is_iaoc)
|
||||
|
||||
def sort_accept_tuple(accept):
|
||||
tup = []
|
||||
if accept:
|
||||
accept_types = accept.split(',')
|
||||
for at in accept_types:
|
||||
keys = at.split(';', 1)
|
||||
q = 1.0
|
||||
if len(keys) != 1:
|
||||
qlist = keys[1].split('=', 1)
|
||||
if len(qlist) == 2:
|
||||
try:
|
||||
q = float(qlist[1])
|
||||
except ValueError:
|
||||
q = 0.0
|
||||
tup.append((keys[0], q))
|
||||
return sorted(tup, key = lambda x: float(x[1]), reverse = True)
|
||||
return tup
|
||||
|
|
|
@ -14,6 +14,7 @@ import pytz
|
|||
import re
|
||||
import six
|
||||
import tarfile
|
||||
import markdown2
|
||||
|
||||
|
||||
from calendar import timegm
|
||||
|
@ -67,6 +68,7 @@ from ietf.meeting.helpers import send_interim_cancellation_notice
|
|||
from ietf.meeting.helpers import send_interim_approval_request
|
||||
from ietf.meeting.helpers import send_interim_announcement_request
|
||||
from ietf.meeting.utils import finalize
|
||||
from ietf.meeting.utils import sort_accept_tuple
|
||||
from ietf.message.utils import infer_message
|
||||
from ietf.secr.proceedings.utils import handle_upload_file
|
||||
from ietf.secr.proceedings.proc_utils import (get_progress_stats, post_process, import_audio_files,
|
||||
|
@ -210,6 +212,19 @@ def materials_document(request, document, num=None, ext=None):
|
|||
|
||||
mtype, chset = get_mime_type(bytes)
|
||||
content_type = "%s; %s" % (mtype, chset)
|
||||
|
||||
file_ext = os.path.splitext(filename)
|
||||
if len(file_ext) == 2 and file_ext[1] == '.md' and mtype == 'text/plain':
|
||||
sorted_accept = sort_accept_tuple(request.META.get('HTTP_ACCEPT'))
|
||||
for atype in sorted_accept:
|
||||
if atype[0] == 'text/markdown':
|
||||
content_type = content_type.replace('plain', 'markdown', 1)
|
||||
break;
|
||||
elif atype[0] == 'text/html':
|
||||
bytes = "<html>\n<head></head>\n<body>\n%s\n</body>\n</html>\n" % markdown2.markdown(bytes)
|
||||
content_type = content_type.replace('plain', 'html', 1)
|
||||
break;
|
||||
|
||||
response = HttpResponse(bytes, content_type=content_type)
|
||||
response['Content-Disposition'] = 'inline; filename="%s"' % basename
|
||||
return response
|
||||
|
|
|
@ -63,4 +63,4 @@ Unidecode>=0.4.18
|
|||
xml2rfc>=2.9.3,!=2.6.0
|
||||
xym==0.4.2,<1.0
|
||||
#zxcvbn-python>=4.4.14 # Not needed until we do back-end password entropy validation
|
||||
|
||||
markdown2>=2.3.8
|
||||
|
|
Loading…
Reference in a new issue