Merged in [16564] from pusateri@bangj.com and added tests:
Convert markdown to html if Accept header prioritizes text/html over text/markdown. Fixes #1926.
- Legacy-Id: 16982
Note: SVN reference [16564] has been migrated to Git commit 65b3f93afe
This commit is contained in:
commit
290a98631f
|
@ -5,7 +5,6 @@
|
|||
|
||||
/personal/rcross/6.99.2.dev0@16607 # Code review found an issue
|
||||
|
||||
/personal/pusateri/6.99.2.dev0@16564 # Code review found an issue
|
||||
/personal/rjs/6.99.2.dev0@16581 # internal branch fixup
|
||||
/personal/rjs/6.99.2.dev0@16579 # internal branch fixup
|
||||
/personal/rjs/6.99.2.dev0@16568 # internal branch fixup
|
||||
|
|
|
@ -169,7 +169,7 @@ def make_meeting_test_data(meeting=None):
|
|||
mars_session.sessionpresentation_set.add(pres) #
|
||||
|
||||
doc = DocumentFactory.create(name='minutes-72-mars', type_id='minutes', title="Minutes",
|
||||
uploaded_filename="minutes-72-mars.txt", group=mars, rev='00', states=[('minutes','active')])
|
||||
uploaded_filename="minutes-72-mars.md", group=mars, rev='00', states=[('minutes','active')])
|
||||
pres = SessionPresentation.objects.create(session=mars_session,document=doc,rev=doc.rev)
|
||||
mars_session.sessionpresentation_set.add(pres)
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import datetime
|
|||
import io
|
||||
import os
|
||||
import random
|
||||
import re
|
||||
import shutil
|
||||
import six
|
||||
|
||||
|
@ -21,6 +22,7 @@ from six.moves.urllib.parse import urlparse
|
|||
from django.urls import reverse as urlreverse
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import Client
|
||||
|
||||
import debug # pyflakes:ignore
|
||||
|
||||
|
@ -300,6 +302,26 @@ class MeetingTests(TestCase):
|
|||
kwargs=dict(num=meeting.number, document=session.minutes()))
|
||||
r = self.client.get(url)
|
||||
self.assertContains(r, "1. More work items underway")
|
||||
|
||||
|
||||
cont_disp = r._headers.get('content-disposition', ('Content-Disposition', ''))[1]
|
||||
cont_disp = re.split('; ?', cont_disp)
|
||||
cont_disp_settings = dict( e.split('=', 1) for e in cont_disp if '=' in e )
|
||||
filename = cont_disp_settings.get('filename', '').strip('"')
|
||||
if filename.endswith('.md'):
|
||||
for accept, cont_type, content in [
|
||||
('text/html,text/plain,text/markdown', 'text/html', '<li><p>More work items underway</p></li>'),
|
||||
('text/markdown,text/html,text/plain', 'text/markdown', '1. More work items underway'),
|
||||
('text/plain,text/markdown, text/html', 'text/plain', '1. More work items underway'),
|
||||
('text/html', 'text/html', '<li><p>More work items underway</p></li>'),
|
||||
('text/markdown', 'text/markdown', '1. More work items underway'),
|
||||
('text/plain', 'text/plain', '1. More work items underway'),
|
||||
]:
|
||||
client = Client(HTTP_ACCEPT=accept)
|
||||
r = client.get(url)
|
||||
rtype = r['Content-Type'].split(';')[0]
|
||||
self.assertEqual(cont_type, rtype)
|
||||
self.assertContains(r, content)
|
||||
|
||||
# test with explicit meeting number in url
|
||||
if meeting.number.isdigit():
|
||||
|
|
|
@ -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,21 @@ 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;
|
||||
elif atype[0] == 'text/plain':
|
||||
break;
|
||||
|
||||
response = HttpResponse(bytes, content_type=content_type)
|
||||
response['Content-Disposition'] = 'inline; filename="%s"' % basename
|
||||
return response
|
||||
|
|
Loading…
Reference in a new issue