From 57025cd5e6d7008ce11b871e33398f6b602232a3 Mon Sep 17 00:00:00 2001 From: Alan Boudreault Date: Fri, 23 May 2014 12:15:46 -0400 Subject: [PATCH 1/2] Add missing mimetypes for xblock resources --- lms/djangoapps/courseware/module_render.py | 1 - lms/startup.py | 14 ++++++++++++++ lms/tests.py | 15 +++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/courseware/module_render.py b/lms/djangoapps/courseware/module_render.py index 0a074b2313..7bc1e1eb33 100644 --- a/lms/djangoapps/courseware/module_render.py +++ b/lms/djangoapps/courseware/module_render.py @@ -64,7 +64,6 @@ XQUEUE_INTERFACE = XQueueInterface( # Some brave person should make the variable names consistently someday, but the code's # coupled enough that it's kind of tricky--you've been warned! - class LmsModuleRenderError(Exception): """ An exception class for exceptions thrown by module_render that don't fit well elsewhere diff --git a/lms/startup.py b/lms/startup.py index ea4d27b167..59de997329 100644 --- a/lms/startup.py +++ b/lms/startup.py @@ -20,6 +20,8 @@ def run(): """ autostartup() + add_mimetypes() + if settings.FEATURES.get('USE_CUSTOM_THEME', False): enable_theme() @@ -30,6 +32,18 @@ def run(): enable_third_party_auth() +def add_mimetypes(): + """ + Add extra mimetypes. Used in xblock_resource. + """ + import mimetypes + + mimetypes.add_type('application/vnd.ms-fontobject', '.eot') + mimetypes.add_type('application/x-font-opentype', '.otf') + mimetypes.add_type('application/x-font-ttf', '.ttf') + mimetypes.add_type('application/font-woff', '.woff') + + def enable_theme(): """ Enable the settings for a custom theme, whose files should be stored diff --git a/lms/tests.py b/lms/tests.py index a164dd654e..c6c7be64e9 100644 --- a/lms/tests.py +++ b/lms/tests.py @@ -1,10 +1,25 @@ """Tests for the lms module itself.""" +import mimetypes + from django.test import TestCase from edxmako import add_lookup, LOOKUP from lms import startup + +class LmsModuleTests(TestCase): + """ + Tests for lms module itself. + """ + + def test_new_mimetypes(self): + extensions = ['eot', 'otf', 'ttf', 'woff'] + for extension in extensions: + mimetype, _ = mimetypes.guess_type('test.' + extension) + self.assertIsNotNone(mimetype) + + class TemplateLookupTests(TestCase): """ Tests for TemplateLookup. From 031ac9852ed790ef674c0b1c253ec557177de5fc Mon Sep 17 00:00:00 2001 From: Alan Boudreault Date: Thu, 29 May 2014 11:44:14 -0400 Subject: [PATCH 2/2] Add mimetype additions in studio startup --- cms/startup.py | 16 ++++++++++++++++ lms/startup.py | 2 ++ 2 files changed, 18 insertions(+) diff --git a/cms/startup.py b/cms/startup.py index 13225f4a49..893cd6a2a8 100644 --- a/cms/startup.py +++ b/cms/startup.py @@ -14,3 +14,19 @@ def run(): Executed during django startup """ autostartup() + + add_mimetypes() + + +def add_mimetypes(): + """ + Add extra mimetypes. Used in xblock_resource. + + If you add a mimetype here, be sure to also add it in lms/startup.py. + """ + import mimetypes + + mimetypes.add_type('application/vnd.ms-fontobject', '.eot') + mimetypes.add_type('application/x-font-opentype', '.otf') + mimetypes.add_type('application/x-font-ttf', '.ttf') + mimetypes.add_type('application/font-woff', '.woff') diff --git a/lms/startup.py b/lms/startup.py index 59de997329..e43e9fddba 100644 --- a/lms/startup.py +++ b/lms/startup.py @@ -35,6 +35,8 @@ def run(): def add_mimetypes(): """ Add extra mimetypes. Used in xblock_resource. + + If you add a mimetype here, be sure to also add it in cms/startup.py. """ import mimetypes