From 0118be48b0272147aa63fd8910b99acbfaa52102 Mon Sep 17 00:00:00 2001 From: piskvorky Date: Wed, 7 Dec 2011 02:21:06 +0100 Subject: added support for django.contrib.staticfiles * staticfiles used to be a separate Python package, before being integrated into django 1.3 * this patch ignores the legacy package and references only the built-in django.contrib.staticfiles, so it requires django >= 1.3 * with staticfiles, serving media in development (runserver) vs. production is handled automatically, so i completely removed the /m/ media view. --- askbot/setup_templates/settings.py | 21 ++++++++++++++++++++- askbot/skins/utils.py | 9 ++------- askbot/urls.py | 5 ----- askbot_requirements.txt | 2 +- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/askbot/setup_templates/settings.py b/askbot/setup_templates/settings.py index 9e847eba..7964368b 100644 --- a/askbot/setup_templates/settings.py +++ b/askbot/setup_templates/settings.py @@ -5,7 +5,8 @@ import sys import askbot #this line is added so that we can import pre-packaged askbot dependencies -sys.path.append(os.path.join(os.path.dirname(askbot.__file__), 'deps')) +ASKBOT_ROOT = os.path.abspath(os.path.dirname(askbot.__file__)) +sys.path.append(os.path.join(ASKBOT_ROOT, 'deps')) DEBUG = False#set to True to enable debugging TEMPLATE_DEBUG = False#keep false when debugging jinja2 templates @@ -222,3 +223,21 @@ djcelery.setup_loader() CSRF_COOKIE_NAME = 'askbot_csrf' CSRF_COOKIE_DOMAIN = ''#enter domain name here - e.g. example.com + +# === Settings for django.contrib.staticfiles +STATIC_ROOT = os.path.join(PROJECT_ROOT, "site_media", "static") + +STATIC_URL = "/site_media/static/" + +# Additional directories which hold static files +STATICFILES_DIRS = [ + os.path.join(PROJECT_ROOT, "static"), + os.path.join(ASKBOT_ROOT, 'skins'), +] + +STATICFILES_FINDERS = [ + "django.contrib.staticfiles.finders.FileSystemFinder", + "django.contrib.staticfiles.finders.AppDirectoriesFinder", +# "django.contrib.staticfiles.finders.LegacyAppDirectoriesFinder", + "compressor.finders.CompressorFinder", +] diff --git a/askbot/skins/utils.py b/askbot/skins/utils.py index da3a8a06..64f11c75 100644 --- a/askbot/skins/utils.py +++ b/askbot/skins/utils.py @@ -149,13 +149,8 @@ def get_media_url(url, ignore_missing = False): logging.critical(log_message) return None - url = use_skin + '/media/' + url - url = '///' + django_settings.ASKBOT_URL + 'm/' + url - url = os.path.normpath(url).replace( - '\\', '/' - ).replace( - '///', '/' - ) + url = django_settings.STATIC_URL + use_skin + '/media/' + url + url = os.path.normpath(url).replace('\\', '/') if resource_revision: url += '?v=%d' % resource_revision diff --git a/askbot/urls.py b/askbot/urls.py index 2c3d143d..235973d0 100644 --- a/askbot/urls.py +++ b/askbot/urls.py @@ -36,11 +36,6 @@ urlpatterns = patterns('', {'sitemaps': sitemaps}, name='sitemap' ), - url( - r'^m/(?P[^/]+)/media/(?P.*)$', - views.meta.media, - name='askbot_media', - ), url( r'^%s(?P.*)$' % settings.ASKBOT_UPLOADED_FILES_URL, 'django.views.static.serve', diff --git a/askbot_requirements.txt b/askbot_requirements.txt index fc11d9d1..6f7a170c 100644 --- a/askbot_requirements.txt +++ b/askbot_requirements.txt @@ -1,5 +1,5 @@ akismet -django>=1.1.2 +django>=1.3 Jinja2 Coffin>=0.3 South>=0.7.1 -- cgit v1.2.3-1-g7c22