Commit eb7ae354 by Bridger Maxwell

Added a simple, specific cache for the static_template_pages.

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