Add a workaround for django bug 18404 (fixes #204)

This commit is contained in:
Andy Kittner 2012-07-08 18:09:23 +02:00
parent f074cb5bfd
commit 5438b2c318
2 changed files with 41 additions and 0 deletions

View File

@ -84,6 +84,13 @@ STATICFILES_DIRS = (
_fs2unicode(os.path.join(SITE_ROOT, 'static')),
)
#XXX: Note this setting (as well as our workaround finder)
# can be removed again once django-bug-#18404 has been resolved
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'openslides.utils.staticfiles.AppDirectoriesFinder',
)
MESSAGE_STORAGE = 'django.contrib.messages.storage.cookie.CookieStorage'
# List of callables that know how to import templates from various sources.

34
openslides/utils/staticfiles.py Executable file
View File

@ -0,0 +1,34 @@
import os
import sys
from django.core.files.storage import FileSystemStorage
from django.utils.importlib import import_module
from django.contrib.staticfiles.finders import (
AppDirectoriesFinder as _AppDirectoriesFinder)
# This is basically a copy of django.contrib.staticfiles.storage.AppStaticStorage
# with the fix for django bug #18404 applied
# see https://code.djangoproject.com/ticket/18404 for details
class AppStaticStorage(FileSystemStorage):
"""
A file system storage backend that takes an app module and works
for the ``static`` directory of it.
"""
prefix = None
source_dir = 'static'
def __init__(self, app, *args, **kwargs):
"""
Returns a static file storage if available in the given app.
"""
# app is the actual app module
mod = import_module(app)
mod_path = os.path.dirname(mod.__file__)
location = os.path.join(mod_path, self.source_dir)
fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding()
location = location.decode(fs_encoding)
super(AppStaticStorage, self).__init__(location, *args, **kwargs)
class AppDirectoriesFinder(_AppDirectoriesFinder):
storage_class = AppStaticStorage