Created
January 10, 2011 05:42
-
-
Save reedobrien/772424 to your computer and use it in GitHub Desktop.
mcdonc's versioned static view from pylonshq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## from http://paste.ofcode.org/39mWESwBQbwasheLuuYjRUv | |
# framework | |
from pyramid.view import static | |
# five year expires time | |
static_view = static('static', cache_max_age=157680000) | |
version_match = re.compile(r'^r\d{1,19}$').match | |
# version number is "r" plus an intified timetime, e.g. r1234567890 | |
def versioning_static_view(context, request): | |
# if the first element in the subpath is the version number, strip | |
# it out of the subpath (see views/api.py static_url) | |
subpath = request.subpath | |
if subpath and version_match(subpath[0]): | |
request.subpath = subpath[1:] | |
return static_view(context, request) | |
# appconfig | |
config.add_route('static', '/static*subpath', view=versioning_static_view) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment