Commit c14f65a2 by Hasnain Committed by Douglas Hall

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
parent d26452de
...@@ -166,8 +166,5 @@ def render_to_response(template_name, dictionary=None, context_instance=None, na ...@@ -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. 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 {} dictionary = dictionary or {}
return HttpResponse(render_to_string(template_name, dictionary, context_instance, namespace), **kwargs) return HttpResponse(render_to_string(template_name, dictionary, context_instance, namespace), **kwargs)
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')
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
# List of valid templates is explicitly managed for (short-term) # List of valid templates is explicitly managed for (short-term)
# security reasons. # security reasons.
import mimetypes
from edxmako.shortcuts import render_to_response, render_to_string from edxmako.shortcuts import render_to_response, render_to_string
from mako.exceptions import TopLevelLookupException from mako.exceptions import TopLevelLookupException
from django.shortcuts import redirect from django.shortcuts import redirect
...@@ -39,7 +41,11 @@ def render(request, template): ...@@ -39,7 +41,11 @@ def render(request, template):
url(r'^jobs$', 'static_template_view.views.render', {'template': 'jobs.html'}, name="jobs") 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 @ensure_csrf_cookie
......
...@@ -1961,11 +1961,14 @@ MKTG_URL_LINK_MAP = { ...@@ -1961,11 +1961,14 @@ MKTG_URL_LINK_MAP = {
'PRESS': 'press', 'PRESS': 'press',
'BLOG': 'blog', 'BLOG': 'blog',
'DONATE': 'donate', 'DONATE': 'donate',
'SITEMAP.XML': 'sitemap_xml',
# Verified Certificates # Verified Certificates
'WHAT_IS_VERIFIED_CERT': 'verified-certificate', 'WHAT_IS_VERIFIED_CERT': 'verified-certificate',
} }
STATIC_TEMPLATE_VIEW_DEFAULT_FILE_EXTENSION = 'html'
SUPPORT_SITE_LINK = '' SUPPORT_SITE_LINK = ''
############################# SOCIAL MEDIA SHARING ############################# ############################# SOCIAL MEDIA SHARING #############################
......
...@@ -352,6 +352,7 @@ MKTG_URL_LINK_MAP = { ...@@ -352,6 +352,7 @@ MKTG_URL_LINK_MAP = {
'PRESS': 'press', 'PRESS': 'press',
'BLOG': 'blog', 'BLOG': 'blog',
'DONATE': 'donate', 'DONATE': 'donate',
'SITEMAP.XML': 'sitemap_xml',
# Verified Certificates # Verified Certificates
'WHAT_IS_VERIFIED_CERT': 'verified-certificate', 'WHAT_IS_VERIFIED_CERT': 'verified-certificate',
......
## This page is not used by edx.org but is left here for possible use by installations of Open edX.
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url><loc>https://www.example.com/</loc><lastmod>2016-01-01</lastmod><changefreq>weekly</changefreq><priority>1.0</priority></url>
</urlset>
...@@ -205,9 +205,12 @@ for key, value in settings.MKTG_URL_LINK_MAP.items(): ...@@ -205,9 +205,12 @@ for key, value in settings.MKTG_URL_LINK_MAP.items():
if key == "ROOT" or key == "COURSES": if key == "ROOT" or key == "COURSES":
continue continue
# Make the assumptions that the templates are all in the same dir # The MKTG_URL_LINK_MAP key specifies the template filename
# and that they all match the name of the key (plus extension) template = key.lower()
template = "%s.html" % 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, # To allow theme templates to inherit from default templates,
# prepend a standard prefix # prepend a standard prefix
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment