def add_versioned_static_resource(config, path, resource, package='karl'): settings = config.registry.settings static_rev = get_egg_rev(package) settings['static_rev'] = static_rev static_path = '%s/%s' % (path, static_rev) config.add_static_view( static_path, resource, cache_max_age=60 * 60 * 24 * 365) # Add a redirecting static view to all _other_ revisions. def _expired_static_predicate(info, request): # We add a redirecting route to all static/*, # _except_ if it starts with the active revision segment. path = info['match']['path'] return path and path[0] != static_rev config.add_route( 'expired-static', '%s/*path' % path, custom_predicates=(_expired_static_predicate, )) return static_path, static_rev
def add_versioned_static_resource(config, path, resource, package='karl'): settings = config.registry.settings static_rev = get_egg_rev(package) settings['static_rev'] = static_rev static_path = '%s/%s' % (path, static_rev) config.add_static_view(static_path, resource, cache_max_age=60 * 60 * 24 * 365) # Add a redirecting static view to all _other_ revisions. def _expired_static_predicate(info, request): # We add a redirecting route to all static/*, # _except_ if it starts with the active revision segment. path = info['match']['path'] return path and path[0] != static_rev config.add_route('expired-static', '%s/*path' % path, custom_predicates=(_expired_static_predicate, )) return static_path, static_rev
def get_static_url(request): # to avoid cyclical imports app_url = request.application_url static_url = '%s/static/%s' % (app_url, get_egg_rev('karl')) return static_url