Commit eb7ae354 by Bridger Maxwell

Added a simple, specific cache for the static_template_pages.

parent cd2eacc6
......@@ -45,10 +45,8 @@ def index(request):
if settings.COURSEWARE_ENABLED and request.user.is_authenticated():
return redirect(reverse('dashboard'))
else:
csrf_token = csrf(request)['csrf_token']
# TODO: Clean up how 'error' is done.
return render_to_response('index.html', {'courses': modulestore().get_courses(),
'csrf': csrf_token})
return render_to_response('index.html', {'courses': modulestore().get_courses()})
@login_required
......
......@@ -5,8 +5,10 @@
from mitxmako.shortcuts import render_to_response, render_to_string
from django.shortcuts import redirect
from django.core.context_processors import csrf
from django.conf import settings
from django_future.csrf import ensure_csrf_cookie
from util.cache import cache
valid_templates = []
......@@ -21,23 +23,30 @@ if settings.STATIC_GRAB:
]
def index(request, template):
csrf_token = csrf(request)['csrf_token']
if template in valid_templates:
return render_to_response('static_templates/' + template, {})
else:
return redirect('/')
@ensure_csrf_cookie
def render(request, template):
"""
This view function renders the template sent without checking that it
exists. Do not expose template as a regex part of the url. The user should
not be able to ender any arbitray template name. The correct usage would be:
url(r'^jobs$', 'static_template_view.views.render', {'template': 'jobs'}, name="jobs")
url(r'^jobs$', 'static_template_view.views.render', {'template': 'jobs.html'}, name="jobs")
"""
template = template + '.html'
return render_to_response('static_templates/' + template, {})
cache_key = "static_template_view_render." + template
use_cache = not request.user.is_authenticated()
response = cache.get(cache_key) if use_cache else None
if not response:
response = render_to_response('static_templates/' + template, {})
if use_cache:
cache.set(cache_key, response, 60 * 3)
return response
valid_auth_templates=['help.html']
......
......@@ -219,6 +219,7 @@ ASKBOT_ALLOWED_UPLOAD_FILE_TYPES = ('.jpg', '.jpeg', '.gif', '.bmp', '.png', '.t
ASKBOT_MAX_UPLOAD_FILE_SIZE = 1024 * 1024 # result in bytes
CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True
CACHE_PREFIX = SITE_ID
ASKBOT_URL = 'discussion/'
LOGIN_REDIRECT_URL = MITX_ROOT_URL + '/'
LOGIN_URL = MITX_ROOT_URL + '/'
......
......@@ -48,11 +48,11 @@ urlpatterns = ('',
#Semi-static views (these need to be rendered and have the login bar, but don't change)
url(r'^404$', 'static_template_view.views.render', {'template': '404'}, name="404"),
url(r'^about$', 'static_template_view.views.render', {'template': 'about'}, name="about_edx"),
url(r'^university_profile$', 'static_template_view.views.render', {'template': 'university_profile'}, name="university_profile"),
url(r'^jobs$', 'static_template_view.views.render', {'template': 'jobs'}, name="jobs"),
url(r'^help$', 'static_template_view.views.render', {'template': 'help'}, name="help_edx"),
url(r'^404$', 'static_template_view.views.render', {'template': '404.html'}, name="404"),
url(r'^about$', 'static_template_view.views.render', {'template': 'about.html'}, name="about_edx"),
url(r'^university_profile$', 'static_template_view.views.render', {'template': 'university_profile.html'}, name="university_profile"),
url(r'^jobs$', 'static_template_view.views.render', {'template': 'jobs.html'}, name="jobs"),
url(r'^help$', 'static_template_view.views.render', {'template': 'help.html'}, name="help_edx"),
#TODO: Convert these pages to the new edX layout
# 'tos.html',
......
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