From 7039520557390336cd495d3a61f4e1a7975a1bdc Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Mon, 22 Jul 2019 18:09:53 +0000 Subject: [PATCH] Merged in [16557] from pusateri@bangj.com: Partially addresses issue #1926 still displaying markdown as text. Fixes #2704. - Legacy-Id: 16576 Note: SVN reference [16557] has been migrated to Git commit f76c46bef038c6574f5ed4c5cb9b8a37d5036575 --- ietf/doc/views_doc.py | 5 ++++- ietf/meeting/forms.py | 2 +- ietf/meeting/tests_views.py | 5 +++-- ietf/settings.py | 10 ++++++++-- ietf/templates/meeting/session_agenda_include.html | 4 ++-- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/ietf/doc/views_doc.py b/ietf/doc/views_doc.py index d10323ce5..3f1ea00a5 100644 --- a/ietf/doc/views_doc.py +++ b/ietf/doc/views_doc.py @@ -584,8 +584,11 @@ def document_main(request, name, rev=None): if not url.endswith("/") and not url.endswith(extension): url = urlbase + extension if extension == ".txt": - content = doc.text_or_error() # pyflakes:ignore + content = doc.text_or_error() t = "plain text" + elif extension == ".md": + content = doc.text_or_error() + t = "markdown" other_types.append((t, url)) return render(request, "doc/document_material.html", diff --git a/ietf/meeting/forms.py b/ietf/meeting/forms.py index 8cea55790..ebb1edace 100644 --- a/ietf/meeting/forms.py +++ b/ietf/meeting/forms.py @@ -342,7 +342,7 @@ class FileUploadForm(forms.Form): self.file_encoding = {} self.file_encoding[file.name] = encoding.replace('charset=','') if encoding else None if self.mime_types: - if mime_type != file.content_type: + if not file.content_type in settings.MEETING_VALID_UPLOAD_MIME_FOR_OBSERVED_MIME[mime_type]: raise ValidationError('Upload Content-Type (%s) is different from the observed mime-type (%s)' % (file.content_type, mime_type)) if mime_type in settings.MEETING_VALID_MIME_TYPE_EXTENSIONS: if not ext in settings.MEETING_VALID_MIME_TYPE_EXTENSIONS[mime_type]: diff --git a/ietf/meeting/tests_views.py b/ietf/meeting/tests_views.py index e9669c007..c049182d7 100644 --- a/ietf/meeting/tests_views.py +++ b/ietf/meeting/tests_views.py @@ -1840,8 +1840,9 @@ class MaterialsTests(TestCase): self.assertNotIn('
', text) self.assertIn('charset="utf-8"', text) + # txt upload test_file = BytesIO(b'This is some text for a test, with the word\nvirtual at the beginning of a line.') - test_file.name = "not_really.txt" + test_file.name = "some.txt" r = self.client.post(url,dict(file=test_file,apply_to_all=False)) self.assertEqual(r.status_code, 302) doc = session.sessionpresentation_set.filter(document__type_id=doctype).first().document @@ -1853,7 +1854,7 @@ class MaterialsTests(TestCase): q = PyQuery(r.content) self.assertIn('Revise', six.text_type(q("Title"))) test_file = BytesIO(b'this is some different text for a test') - test_file.name = "also_not_really.txt" + test_file.name = "also_some.txt" r = self.client.post(url,dict(file=test_file,apply_to_all=True)) self.assertEqual(r.status_code, 302) doc = Document.objects.get(pk=doc.pk) diff --git a/ietf/settings.py b/ietf/settings.py index 6b593c4d0..03dee382c 100644 --- a/ietf/settings.py +++ b/ietf/settings.py @@ -814,18 +814,24 @@ MEETING_VALID_UPLOAD_EXTENSIONS = { } MEETING_VALID_UPLOAD_MIME_TYPES = { - 'agenda': ['text/plain', 'text/html', ], - 'minutes': ['text/plain', 'text/html', 'application/pdf', ], + 'agenda': ['text/plain', 'text/html', 'text/markdown', ], + 'minutes': ['text/plain', 'text/html', 'application/pdf', 'text/markdown', ], 'slides': [], 'bluesheets': ['application/pdf', 'text/plain', ], } MEETING_VALID_MIME_TYPE_EXTENSIONS = { 'text/plain': ['.txt', '.md', ], + 'text/markdown': ['.txt', '.md', ], 'text/html': ['.html', '.htm'], 'application/pdf': ['.pdf'], } +MEETING_VALID_UPLOAD_MIME_FOR_OBSERVED_MIME = { + 'text/plain': ['text/plain', 'text/markdown', ], + 'text/html': ['text/html', ], + 'application/pdf': ['application/pdf', ], +} INTERNET_DRAFT_DAYS_TO_EXPIRE = 185 diff --git a/ietf/templates/meeting/session_agenda_include.html b/ietf/templates/meeting/session_agenda_include.html index 72cf127c4..5165efa8a 100644 --- a/ietf/templates/meeting/session_agenda_include.html +++ b/ietf/templates/meeting/session_agenda_include.html @@ -16,7 +16,7 @@