Permalink
Browse files

* only try to resolve http urls; other schemes are not served from fi…

…ler (like the data scheme which is quite common in css)

* hash the path before generating the cache key; this is due to the fact that paths might be longer than the max size allowed by memcached
  • Loading branch information...
1 parent c7cd2af commit 2dcd3bd3ce09c9d06c47c68a4e6f088bf08619c2 @kux kux committed Dec 7, 2012
Showing with 9 additions and 4 deletions.
  1. +5 −3 filertags/signals.py
  2. +4 −1 filertags/templatetags/filertags.py
View
@@ -64,7 +64,7 @@ def _is_css(filer_file):
def resolve_resource_urls(instance, **kwargs):
- """Post save hook for css files uploaded to filer.
+ """Pre save hook for css files uploaded to filer.
It's purpose is to resolve the actual urls of resources referenced
in css files.
@@ -116,8 +116,10 @@ def change_urls(match):
# strip spaces and quotes
url = match.group(1).strip('\'\" ')
parsed_url = urlparse.urlparse(url)
- if parsed_url.netloc:
- # if the url is absolute, leave it unchaged
+ if parsed_url.netloc or parsed_url.scheme not in ['', 'http']:
+ # ignore everyghing which is not served through http
+ # or explicitly specifies a hostname; these are resources
+ # not served from filer
return match.group()
relative_path = url
logical_file_path = os.path.normpath(
@@ -1,4 +1,5 @@
import logging
+import hashlib
from django import template
from django.db.models import Q
@@ -34,7 +35,9 @@ def filerthumbnail(path):
def get_filerfile_cache_key(path):
- return 'filer-%s' % slugify(path)
+ # since the path might be longer than 250 characters
+ # (max lenght allowed by memcached), we use a md5 hash of the path
+ return '%s-%d-%s' % ('filer-', len(path), hashlib.md5(path).hexdigest())
def filerfile(path):

0 comments on commit 2dcd3bd

Please sign in to comment.