Commit e8c4d1db by Calen Pennington

Replace links to static in problems with links to fingerprinted data

parent 5a4d9691
from staticfiles.storage import staticfiles_storage
import re
PREFIX = '/static/'
STATIC_PATTERN = re.compile(r"""
(?P<quote>['"]) # the opening quotes
{prefix} # the prefix
.*? # everything else in the url
(?P=quote) # the first matching closing quote
""".format(prefix=PREFIX), re.VERBOSE)
PREFIX_LEN = len(PREFIX)
def replace(static_url):
quote = static_url[0]
url = staticfiles_storage.url(static_url[1+PREFIX_LEN:-1])
return "".join([quote, url, quote])
def replace_urls(text):
return STATIC_PATTERN.sub(replace, text)
......@@ -40,7 +40,7 @@ task :package do
set -x
chown -R makeitso:makeitso #{INSTALL_DIR_PATH}
service gunicorn stop
rm -f #{LINK_PATH}
ln -s #{INSTALL_DIR_PATH} #{LINK_PATH}
......
......@@ -23,8 +23,10 @@
</script>
<%block name="headextra"/>
<!-- This must appear after all mathjax-config blocks, so it is after the imports from the other templates -->
<script type="text/javascript" src="${static.url('js/mathjax-MathJax-c9db6ac/MathJax.js')}?config=TeX-AMS_HTML-full"></script>
<!-- This must appear after all mathjax-config blocks, so it is after the imports from the other templates.
It can't be run through static.url because MathJax uses crazy url introspection to do lazy loading of
MathJax extension libraries -->
<script type="text/javascript" src="/static/js/mathjax-MathJax-c9db6ac/MathJax.js?config=TeX-AMS_HTML-full"></script>
</head>
<body class="<%block name="bodyclass"/>">
......
<%namespace name='static' file='static_content.html'/>
<h2 class="problem-header">${ problem['name'] }
% if problem['weight']:
: ${ problem['weight'] } points
......@@ -5,7 +6,7 @@
</h2>
<section class="problem">
${ problem['html'] }
${ static.replace_urls(problem['html']) }
<section class="action">
<input type="hidden" name="problem_id" value="${ problem['name'] }">
......
<%!
from staticfiles.storage import staticfiles_storage
from pipeline_mako import compressed_css, compressed_js
from static_replace import replace_urls
%>
<%def name='url(file)'>${staticfiles_storage.url(file)}</%def>
<%def name='css(group)'>${compressed_css(group)}</%def>
<%def name='js(group)'>${compressed_js(group)}</%def>
<%def name='replace_urls(text)'>${replace_urls(text)}</%def>
......@@ -80,5 +80,3 @@ urlpatterns = patterns(*urlpatterns)
if settings.DEBUG:
urlpatterns += staticfiles_urlpatterns()
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