Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update filertags to work with the new filer fork (that supports logic…

…al == actual urls):

* trigger css rewrting signals only if the logical == actual url feature is not enabled
* if logical == actual urls filertags uses a faster implementation that performs a single query
* remove url caching as it might cause some issues with the domain that filerfile returns.
  • Loading branch information...
commit 1b7aab28215b8fb23e92b8dddd313ec17594860a 1 parent 8363493
@kux kux authored
View
7 filertags/settings.py
@@ -0,0 +1,7 @@
+from django.conf import settings
+
+filer_storages = getattr(settings, 'FILER_STORAGES', {})
+
+LOGICAL_EQ_ACTUAL_URL = all(
+ storage['main']['UPLOAD_TO'] == 'filer.utils.generate_filename.by_path'
+ for storage in filer_storages.values())
View
25 filertags/signals.py
@@ -3,15 +3,14 @@
import re
import urlparse
-from django.core.cache import cache
from django.core.files.base import ContentFile
from django.core.files.uploadedfile import UploadedFile
from django.db.models import signals
from filer.models.filemodels import File
from filer.models.imagemodels import Image
-
-from templatetags.filertags import filerfile, get_filerfile_cache_key
+from filertags.settings import LOGICAL_EQ_ACTUAL_URL
+from templatetags.filertags import filerfile
_LOGICAL_URL_TEMPLATE = u"/* logicalurl('%s') */"
@@ -251,20 +250,8 @@ def update_referencing_css_files(instance, **kwargs):
update_url_statements_in_css(css, resource_file, logical_file_path)
-def clear_urls_cache(instance, **kwargs):
- """Clears urls cached by the filerfile tag. """
- if _is_in_clipboard(instance):
- return
- logical_file_path = urlparse.urljoin(
- _construct_logical_folder_path(instance),
- instance.original_filename)
- cache_key = get_filerfile_cache_key(logical_file_path)
- cache.delete(cache_key)
-
-
-# signals.pre_save.connect(resolve_resource_urls, sender=File)
-# signals.post_save.connect(update_referencing_css_files, sender=File)
-# signals.post_save.connect(update_referencing_css_files, sender=Image)
+if not LOGICAL_EQ_ACTUAL_URL:
+ signals.pre_save.connect(resolve_resource_urls, sender=File)
+ signals.post_save.connect(update_referencing_css_files, sender=File)
+ signals.post_save.connect(update_referencing_css_files, sender=Image)
-# signals.post_save.connect(clear_urls_cache, sender=File)
-# signals.post_save.connect(clear_urls_cache, sender=Image)
View
35 filertags/templatetags/filertags.py
@@ -1,12 +1,14 @@
import logging
-import hashlib
from django import template
+from django.conf import settings
from django.db.models import Q
-from django.core.cache import cache
-from django.template.defaultfilters import stringfilter, slugify
+from django.template.defaultfilters import stringfilter
from filer.models import File, Folder
+# TODO: this is ugly: the ..settings is because the toplevel package
+# name has the same name as this module; should probably rename the toplevel package?
+from ..settings import LOGICAL_EQ_ACTUAL_URL
logger = logging.getLogger(__name__)
@@ -35,10 +37,9 @@ def filerthumbnail(path):
return None
-def get_filerfile_cache_key(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 get_possible_paths(path):
+ return ['%s/%s' % (storage['main']['UPLOAD_TO_PREFIX'], path)
+ for storage in settings.FILER_STORAGES.values()]
def filerfile(path):
@@ -46,20 +47,16 @@ def filerfile(path):
* the logical path: media/images/foobar.png
* the actual url: filer_public/2012/11/22/foobar.png
This tag returns the actual url associated with the logical path.
-
- Since most of the templates will be referencing the same
- resources (css, js), the returned urls are being cached.
"""
- cache_key = get_filerfile_cache_key(path)
- if cache.has_key(cache_key):
- return cache.get(cache_key)
- file_obj = filerthumbnail(path)
- if file_obj is None or not file_obj:
- url = ''
+ if LOGICAL_EQ_ACTUAL_URL:
+ try:
+ return File.objects.get(file__in=get_possible_paths(path)).url
+ except (File.DoesNotExist, File.MultipleObjectsReturned), e:
+ logger.info('%s on %s' % (e.message, path))
+ return path
else:
- url = file_obj.url
- cache.set(cache_key, url)
- return url
+ file_obj = filerthumbnail(path)
+ return file_obj.url if file_obj else ''
def mustache(path):
Please sign in to comment.
Something went wrong with that request. Please try again.