Commit af5e6672 by Sander Smits

enabled COMPRESS_VERSION=True and COMPRESS_AUTO=False

parent 99c86bbf
...@@ -5,7 +5,7 @@ from django import template ...@@ -5,7 +5,7 @@ from django import template
from django.conf import settings as django_settings from django.conf import settings as django_settings
from compress.conf import settings from compress.conf import settings
from compress.utils import media_root, media_url, needs_update, filter_css, filter_js, get_output_filename, get_version from compress.utils import media_root, media_url, needs_update, filter_css, filter_js, get_output_filename, get_version, get_version_from_file
register = template.Library() register = template.Library()
...@@ -45,7 +45,11 @@ class CompressedCSSNode(template.Node): ...@@ -45,7 +45,11 @@ class CompressedCSSNode(template.Node):
css['source_filenames']) css['source_filenames'])
if u: if u:
filter_css(css) filter_css(css)
else:
filename_base, filename = os.path.split(css['output_filename'])
path_name = media_root(filename_base)
version = get_version_from_file(path_name, filename)
return render_css(css, css['output_filename'], version) return render_css(css, css['output_filename'], version)
else: else:
# output source files # output source files
...@@ -76,6 +80,10 @@ class CompressedJSNode(template.Node): ...@@ -76,6 +80,10 @@ class CompressedJSNode(template.Node):
js['source_filenames']) js['source_filenames'])
if u: if u:
filter_js(js) filter_js(js)
else:
filename_base, filename = os.path.split(js['output_filename'])
path_name = media_root(filename_base)
version = get_version_from_file(path_name, filename)
return render_js(js, js['output_filename'], version) return render_js(js, js['output_filename'], version)
else: else:
......
...@@ -51,7 +51,7 @@ def needs_update(output_file, source_files, verbosity=0): ...@@ -51,7 +51,7 @@ def needs_update(output_file, source_files, verbosity=0):
if not os.path.exists(compressed_file_full): if not os.path.exists(compressed_file_full):
return True, version return True, version
update_needed = getattr(get_class(settings.COMPRESS_VERSIONING)(verbose=(verbosity >= 2)), 'needs_update')(output_file, source_files, version) update_needed = getattr(get_class(settings.COMPRESS_VERSIONING)(), 'needs_update')(output_file, source_files, version)
return update_needed return update_needed
def media_root(filename): def media_root(filename):
...@@ -90,8 +90,15 @@ def get_output_filename(filename, version): ...@@ -90,8 +90,15 @@ def get_output_filename(filename, version):
return filename.replace(settings.COMPRESS_VERSION_PLACEHOLDER, settings.COMPRESS_VERSION_DEFAULT) return filename.replace(settings.COMPRESS_VERSION_PLACEHOLDER, settings.COMPRESS_VERSION_DEFAULT)
def get_version(source_files, verbosity=0): def get_version(source_files, verbosity=0):
version = getattr(get_class(settings.COMPRESS_VERSIONING)(verbose=(verbosity >= 2)), 'get_version')(source_files) version = getattr(get_class(settings.COMPRESS_VERSIONING)(), 'get_version')(source_files)
return version return version
def get_version_from_file(path, filename):
regex = re.compile(r'^%s$' % (os.path.basename(get_output_filename(settings.COMPRESS_VERSION_PLACEHOLDER.join([re.escape(part) for part in filename.split(settings.COMPRESS_VERSION_PLACEHOLDER)]), r'([A-Za-z0-9]+)'))))
for f in os.listdir(path):
result = regex.match(f)
if result and result.groups():
return result.groups()[0]
def remove_files(path, filename, verbosity=0): def remove_files(path, filename, verbosity=0):
regex = re.compile(r'^%s$' % (os.path.basename(get_output_filename(settings.COMPRESS_VERSION_PLACEHOLDER.join([re.escape(part) for part in filename.split(settings.COMPRESS_VERSION_PLACEHOLDER)]), r'[A-Za-z0-9]+')))) regex = re.compile(r'^%s$' % (os.path.basename(get_output_filename(settings.COMPRESS_VERSION_PLACEHOLDER.join([re.escape(part) for part in filename.split(settings.COMPRESS_VERSION_PLACEHOLDER)]), r'[A-Za-z0-9]+'))))
......
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