Skip to content
Permalink
Browse files

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.
  • Loading branch information...
piskvorky committed Dec 7, 2011
1 parent a0ef331 commit 0118be48b0272147aa63fd8910b99acbfaa52102
Showing with 23 additions and 14 deletions.
  1. +20 −1 askbot/setup_templates/settings.py
  2. +2 −7 askbot/skins/utils.py
  3. +0 −5 askbot/urls.py
  4. +1 −1 askbot_requirements.txt
@@ -5,7 +5,8 @@
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 @@

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",
]
@@ -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
@@ -36,11 +36,6 @@
{'sitemaps': sitemaps},
name='sitemap'
),
url(
r'^m/(?P<skin>[^/]+)/media/(?P<resource>.*)$',
views.meta.media,
name='askbot_media',
),
url(
r'^%s(?P<path>.*)$' % settings.ASKBOT_UPLOADED_FILES_URL,
'django.views.static.serve',
@@ -1,5 +1,5 @@
akismet
django>=1.1.2
django>=1.3
Jinja2
Coffin>=0.3
South>=0.7.1

1 comment on commit 0118be4

@evgenyfadeev

This comment has been minimized.

Copy link

commented on 0118be4 Dec 7, 2011

I think this is a really good solution, but we need to support Django-1.2 at least and even 1.1 if possible.

what should be done ideally before merging this:

  • function askbot/skins/common/media/js/utils.js: mediaUrl may need to be updated
  • modify the askbot-setup script to create appropriate records in the settings.py
    according to version of django
  • add test to askbot/startup_procedures.py to validate variables in settings.py according to version of django.
  • conditionally on the version of django check presence of the staticfiles app.

Update documentation for askbot deployment: askbot/doc/source/deployment.rst

If you could do it - would be awesome, we'll finish this eventually too.

Thanks.

Please sign in to comment.
You can’t perform that action at this time.