From c14f65a293ae662544116f80dd0c2b84be861867 Mon Sep 17 00:00:00 2001 From: Hasnain Date: Wed, 13 Jan 2016 17:57:21 +0500 Subject: [PATCH] Added site_map in static template Allow file extensions in MKTG_URL_LINK_MAP template keys Set content type on requests for static templates based on the template key --- common/djangoapps/edxmako/shortcuts.py | 3 --- .../static_template_view/tests/test_views.py | 26 +++++++++++++++++++ lms/djangoapps/static_template_view/views.py | 8 +++++- lms/envs/common.py | 3 +++ lms/envs/test.py | 1 + lms/templates/static_templates/sitemap.xml | 5 ++++ lms/urls.py | 9 ++++--- 7 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 lms/djangoapps/static_template_view/tests/test_views.py create mode 100644 lms/templates/static_templates/sitemap.xml diff --git a/common/djangoapps/edxmako/shortcuts.py b/common/djangoapps/edxmako/shortcuts.py index 3eda270d41..50e53855b2 100644 --- a/common/djangoapps/edxmako/shortcuts.py +++ b/common/djangoapps/edxmako/shortcuts.py @@ -166,8 +166,5 @@ def render_to_response(template_name, dictionary=None, context_instance=None, na lookup.get_template(args[0]).render with the passed arguments. """ - # see if there is an override template defined in the microsite - template_name = microsite.get_template_path(template_name) - dictionary = dictionary or {} return HttpResponse(render_to_string(template_name, dictionary, context_instance, namespace), **kwargs) diff --git a/lms/djangoapps/static_template_view/tests/test_views.py b/lms/djangoapps/static_template_view/tests/test_views.py new file mode 100644 index 0000000000..539777359a --- /dev/null +++ b/lms/djangoapps/static_template_view/tests/test_views.py @@ -0,0 +1,26 @@ +import mimetypes + +from django.test import TestCase +from django.conf import settings +from django.core.urlresolvers import reverse + + +class MarketingSiteViewTests(TestCase): + """ Tests for the marketing site views """ + + def _test_view(self, view_name, mimetype): + resp = self.client.get(reverse(view_name)) + self.assertEqual(resp.status_code, 200) + self.assertEqual(resp['Content-Type'], mimetype) + + def test_sitemap(self): + """ + Test the sitemap view + """ + self._test_view('sitemap_xml', 'application/xml') + + def test_about(self): + """ + Test the about view + """ + self._test_view('about', 'text/html') diff --git a/lms/djangoapps/static_template_view/views.py b/lms/djangoapps/static_template_view/views.py index e7c09a459f..6b51029a93 100644 --- a/lms/djangoapps/static_template_view/views.py +++ b/lms/djangoapps/static_template_view/views.py @@ -3,6 +3,8 @@ # List of valid templates is explicitly managed for (short-term) # security reasons. +import mimetypes + from edxmako.shortcuts import render_to_response, render_to_string from mako.exceptions import TopLevelLookupException from django.shortcuts import redirect @@ -39,7 +41,11 @@ def render(request, template): url(r'^jobs$', 'static_template_view.views.render', {'template': 'jobs.html'}, name="jobs") """ - return render_to_response('static_templates/' + template, {}) + + # Guess content type from file extension + content_type, __ = mimetypes.guess_type(template) + + return render_to_response('static_templates/' + template, {}, content_type=content_type) @ensure_csrf_cookie diff --git a/lms/envs/common.py b/lms/envs/common.py index 088779a71e..4adee7c0d1 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -1961,11 +1961,14 @@ MKTG_URL_LINK_MAP = { 'PRESS': 'press', 'BLOG': 'blog', 'DONATE': 'donate', + 'SITEMAP.XML': 'sitemap_xml', # Verified Certificates 'WHAT_IS_VERIFIED_CERT': 'verified-certificate', } +STATIC_TEMPLATE_VIEW_DEFAULT_FILE_EXTENSION = 'html' + SUPPORT_SITE_LINK = '' ############################# SOCIAL MEDIA SHARING ############################# diff --git a/lms/envs/test.py b/lms/envs/test.py index 9e7bb67486..52583cd3cf 100644 --- a/lms/envs/test.py +++ b/lms/envs/test.py @@ -352,6 +352,7 @@ MKTG_URL_LINK_MAP = { 'PRESS': 'press', 'BLOG': 'blog', 'DONATE': 'donate', + 'SITEMAP.XML': 'sitemap_xml', # Verified Certificates 'WHAT_IS_VERIFIED_CERT': 'verified-certificate', diff --git a/lms/templates/static_templates/sitemap.xml b/lms/templates/static_templates/sitemap.xml new file mode 100644 index 0000000000..cb778ddf30 --- /dev/null +++ b/lms/templates/static_templates/sitemap.xml @@ -0,0 +1,5 @@ +## This page is not used by edx.org but is left here for possible use by installations of Open edX. + + +https://www.example.com/2016-01-01weekly1.0 + diff --git a/lms/urls.py b/lms/urls.py index 41050a0c52..747fad08bb 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -205,9 +205,12 @@ for key, value in settings.MKTG_URL_LINK_MAP.items(): if key == "ROOT" or key == "COURSES": continue - # Make the assumptions that the templates are all in the same dir - # and that they all match the name of the key (plus extension) - template = "%s.html" % key.lower() + # The MKTG_URL_LINK_MAP key specifies the template filename + template = key.lower() + if '.' not in template: + # Append STATIC_TEMPLATE_VIEW_DEFAULT_FILE_EXTENSION if + # no file extension was specified in the key + template = "%s.%s" % (template, settings.STATIC_TEMPLATE_VIEW_DEFAULT_FILE_EXTENSION) # To allow theme templates to inherit from default templates, # prepend a standard prefix