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 From 53cd343ea0f33f3b269ae5fd5e3890a3a3ad934d Mon Sep 17 00:00:00 2001 From: piskvorky Date: Wed, 7 Dec 2011 02:57:32 +0100 Subject: added the staticfiles app itself =) --- askbot/setup_templates/settings.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/askbot/setup_templates/settings.py b/askbot/setup_templates/settings.py index 7964368b..f41500f7 100644 --- a/askbot/setup_templates/settings.py +++ b/askbot/setup_templates/settings.py @@ -142,6 +142,7 @@ TEMPLATE_CONTEXT_PROCESSORS = ( 'askbot.user_messages.context_processors.user_messages',#must be before auth 'django.core.context_processors.auth', #this is required for admin 'django.core.context_processors.csrf', #necessary for csrf protection + "django.core.context_processors.static", ) @@ -150,6 +151,7 @@ INSTALLED_APPS = ( 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', + "django.contrib.staticfiles", #all of these are needed for the askbot 'django.contrib.admin', -- cgit v1.2.3-1-g7c22 From 4a2d5f0ff27a5d993f71bcc3b05cbcf9f8a8f833 Mon Sep 17 00:00:00 2001 From: piskvorky Date: Sun, 18 Dec 2011 08:48:23 +0100 Subject: updated static urls in javascript --- askbot/context.py | 1 + askbot/skins/common/media/js/utils.js | 2 +- askbot/skins/default/templates/meta/bottom_scripts.html | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/askbot/context.py b/askbot/context.py index f3665240..f3819481 100644 --- a/askbot/context.py +++ b/askbot/context.py @@ -15,6 +15,7 @@ def application_settings(request): my_settings = askbot_settings.as_dict() my_settings['LANGUAGE_CODE'] = getattr(request, 'LANGUAGE_CODE', settings.LANGUAGE_CODE) my_settings['ASKBOT_URL'] = settings.ASKBOT_URL + my_settings['STATIC_URL'] = settings.STATIC_URL my_settings['ASKBOT_CSS_DEVEL'] = getattr(settings, 'ASKBOT_CSS_DEVEL', False) my_settings['DEBUG'] = settings.DEBUG my_settings['ASKBOT_VERSION'] = askbot.get_version() diff --git a/askbot/skins/common/media/js/utils.js b/askbot/skins/common/media/js/utils.js index 0afd03a7..60ac8d97 100644 --- a/askbot/skins/common/media/js/utils.js +++ b/askbot/skins/common/media/js/utils.js @@ -1,6 +1,6 @@ //var $, scriptUrl, askbotSkin var mediaUrl = function(resource){ - return scriptUrl + 'm/' + askbotSkin + '/' + resource; + return askbot['settings']['static_url'] + askbotSkin + '/' + resource; }; var cleanUrl = function(url){ diff --git a/askbot/skins/default/templates/meta/bottom_scripts.html b/askbot/skins/default/templates/meta/bottom_scripts.html index 0df25e7c..980059da 100644 --- a/askbot/skins/default/templates/meta/bottom_scripts.html +++ b/askbot/skins/default/templates/meta/bottom_scripts.html @@ -28,6 +28,7 @@ askbot['urls']['follow_user'] = scriptUrl + 'followit/follow/user/{{'{{'}}userId{{'}}'}}/'; askbot['urls']['unfollow_user'] = scriptUrl + 'followit/unfollow/user/{{'{{'}}userId{{'}}'}}/'; askbot['urls']['user_signin'] = '{{ settings.LOGIN_URL }}'; + askbot['settings']['static_url'] = '{{ settings.STATIC_URL }}';