Replace links to static in problems with links to fingerprinted data
This commit is contained in:
19
lib/static_replace.py
Normal file
19
lib/static_replace.py
Normal file
@@ -0,0 +1,19 @@
|
||||
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)
|
||||
2
rakefile
2
rakefile
@@ -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"/>">
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<%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'] }">
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
<%!
|
||||
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>
|
||||
|
||||
Reference in New Issue
Block a user