Replace links to static in problems with links to fingerprinted data

This commit is contained in:
Calen Pennington
2012-04-23 11:42:42 -04:00
parent 5a4d9691d4
commit e8c4d1dbef
6 changed files with 28 additions and 6 deletions

19
lib/static_replace.py Normal file
View 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)