From a4637405df6574c66e8cfcba2c1cbac5d8825665 Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Sun, 15 Jan 2012 19:45:48 -0300 Subject: staticfiles app seems to work with askbot for django 1.2 and 1.3 --- askbot/context.py | 2 ++ askbot/doc/source/deployment.rst | 29 +++++++++++----- askbot/setup_templates/settings.py | 2 +- askbot/setup_templates/settings.py.mustache | 2 +- askbot/skins/common/templates/debug_header.html | 27 +++++++++++++++ askbot/skins/default/templates/base.html | 1 + askbot/startup_procedures.py | 44 +++++++++++++++++++----- askbot/tests/images/logo.gif | Bin askbot/tests/skin_tests.py | 6 +--- 9 files changed, 89 insertions(+), 24 deletions(-) create mode 100644 askbot/skins/common/templates/debug_header.html mode change 100755 => 100644 askbot/tests/images/logo.gif diff --git a/askbot/context.py b/askbot/context.py index c967931e..41298fc1 100644 --- a/askbot/context.py +++ b/askbot/context.py @@ -2,6 +2,7 @@ from the django settings, all parameters from the askbot livesettings and the application available for the templates """ +import sys from django.conf import settings import askbot from askbot import api @@ -18,6 +19,7 @@ def application_settings(request): 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['USING_RUNSERVER'] = 'runserver' in sys.argv my_settings['ASKBOT_VERSION'] = askbot.get_version() my_settings['LOGIN_URL'] = url_utils.get_login_url() my_settings['LOGOUT_URL'] = url_utils.get_logout_url() diff --git a/askbot/doc/source/deployment.rst b/askbot/doc/source/deployment.rst index 8baa99c0..1ca7553f 100644 --- a/askbot/doc/source/deployment.rst +++ b/askbot/doc/source/deployment.rst @@ -6,18 +6,30 @@ Deploying Askbot Deploying askbot (assuming that it is already installed) entails: +* collecting static media files * setting correct file access permissions * configuring the webserver to work with your application This document currently explains the configuration under Apache and mod_wsgi_. +Collecting static media files +----------------------------- +Static media must be collected into a single location with a command:: + + python manage.py collectstatic + +There are several options on where to put the static files - the simplest is +a local directory, but it is also possible to use a dedicated static files +storage or a CDN, for more information see django documentation about +serving static files. + Setting up file access permissions ---------------------------------- Webserver process must be able to write to the following locations within your project:: - log/ - askbot/upfiles + log/ + askbot/upfiles If you know user name or the group name under which the webserver runs, you can make those directories writable by setting the permissons @@ -26,11 +38,11 @@ accordingly: For example, if you are using Linux installation of apache webserver running under group name 'apache' you could do the following:: - cd /path/to/django-project - cd .. #go one level up - chown -R yourlogin:apache django-project - chmod -R g+w django-project/askbot/upfiles - chmod -R g+w django-project/log + cd /path/to/django-project + cd .. #go one level up + chown -R yourlogin:apache django-project + chmod -R g+w django-project/askbot/upfiles + chmod -R g+w django-project/log If your account somehow limits you from running such commands - please consult your system administrator. @@ -71,9 +83,8 @@ Settings below are not perfect but may be a good starting point:: #aliases to serve static media directly #will probably need adjustment - Alias /m/ /usr/local/lib/python2.6/site-packages/askbot/skins/ + Alias /static/ /path/to/django-project/static/ Alias /upfiles/ /path/to/django-project/askbot/upfiles/ - Alias /admin/media/ /usr/local/lib/python2.6/site-packages/django/contrib/admin/media/ Order deny,allow Allow from all diff --git a/askbot/setup_templates/settings.py b/askbot/setup_templates/settings.py index 1efb4e75..00bbcc11 100644 --- a/askbot/setup_templates/settings.py +++ b/askbot/setup_templates/settings.py @@ -80,7 +80,7 @@ STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')#path to files collected by co # URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a # trailing slash. # Examples: "http://foo.com/media/", "/media/". -ADMIN_MEDIA_PREFIX = '/admin/media/' +ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'#must be this value # Make up some unique string, and don't share it with anybody. SECRET_KEY = 'sdljdfjkldsflsdjkhsjkldgjlsdgfs s ' diff --git a/askbot/setup_templates/settings.py.mustache b/askbot/setup_templates/settings.py.mustache index 5a02cd35..d231bf64 100644 --- a/askbot/setup_templates/settings.py.mustache +++ b/askbot/setup_templates/settings.py.mustache @@ -80,7 +80,7 @@ STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static') # URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a # trailing slash. # Examples: "http://foo.com/media/", "/media/". -ADMIN_MEDIA_PREFIX = '/admin/media/' +ADMIN_MEDIA_PREFIX = STATIC_ROOT + 'admin/' # Make up some unique string, and don't share it with anybody. SECRET_KEY = 'sdljdfjkldsflsdjkhsjkldgjlsdgfs s ' diff --git a/askbot/skins/common/templates/debug_header.html b/askbot/skins/common/templates/debug_header.html new file mode 100644 index 00000000..e1230265 --- /dev/null +++ b/askbot/skins/common/templates/debug_header.html @@ -0,0 +1,27 @@ +{% if settings.USING_RUNSERVER %} + {% if settings.DEBUG == False %} +
+

+ You are seeing this message because you are using Django runserver + and DEBUG_MODE is False. Runserver should not be used in production. +

+

+ To serve static media in production - please run: +

python manage.py collectstatic
+

+

+ If you do not see page styling - set DEBUG_MODE = True. +

+
+ {% endif %} +{% else %} + {% if settings.DEBUG == True %} +
+

+ Debug mode is on, do not use it in production. + To turn it off, use DEBUG = False in your + settings.py file. +

+
+ {% endif %} +{% endif %} diff --git a/askbot/skins/default/templates/base.html b/askbot/skins/default/templates/base.html index 8287f5ba..39b89fe8 100644 --- a/askbot/skins/default/templates/base.html +++ b/askbot/skins/default/templates/base.html @@ -16,6 +16,7 @@ {% endspaceless %} {% include "widgets/system_messages.html" %} + {% include "debug_header.html" %} {% include "custom_header.html" ignore missing %} {% if settings.CUSTOM_HEADER|trim != '' %}
diff --git a/askbot/startup_procedures.py b/askbot/startup_procedures.py index f002c3d5..691f0a03 100644 --- a/askbot/startup_procedures.py +++ b/askbot/startup_procedures.py @@ -309,16 +309,25 @@ class SettingsTester(object): def test_staticfiles(): """tests configuration of the staticfiles app""" errors = list() - if 'django.contrib.staticfiles' not in django_settings.INSTALLED_APPS: + import django + django_version = django.VERSION + if django_version[0] == 1 and django_version[1] < 3: + staticfiles_app_name = 'staticfiles' + try_import('staticfiles', 'django-staticfiles') + import staticfiles + if staticfiles.__version__[0] != 1: + raise AskbotConfigError( + 'Please use the newest available version of ' + 'django-staticfiles app, type\n' + 'pip install --upgrade django-staticfiles' + ) + else: + staticfiles_app_name = 'django.contrib.staticfiles' + + if staticfiles_app_name not in django_settings.INSTALLED_APPS: errors.append( 'Add to the INSTALLED_APPS section of your settings.py:\n' - " 'django.contrib.staticfiles'," - ) - if 'django.core.context_processors.static' not in \ - django_settings.TEMPLATE_CONTEXT_PROCESSORS: - errors.append( - 'Add to the TEMPLATE_CONTEXT_PROCESSORS section of your settings.py:\n' - " 'django.core.context_processors.static'," + " '%s'," % staticfiles_app_name ) static_url = django_settings.STATIC_URL if static_url is None or str(static_url).strip() == '': @@ -333,6 +342,12 @@ def test_staticfiles(): errors.append( 'Path in the STATIC_URL must start and end with the /.' ) + if django_settings.ADMIN_MEDIA_PREFIX != static_url + 'admin/': + errors.append( + 'Set ADMIN_MEDIA_PREFIX as: \n' + " ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'" + ) + askbot_root = os.path.dirname(askbot.__file__) skin_dir = os.path.abspath(os.path.join(askbot_root, 'skins')) if skin_dir not in map(os.path.abspath, django_settings.STATICFILES_DIRS): @@ -355,7 +370,20 @@ def test_staticfiles(): 'ASKBOT_EXTRA_SKINS_DIR just above STATICFILES_DIRS.' ) + if errors: + errors.append( + 'Run command (after fixing the above errors)\n' + ' python manage.py collectstatic\n' + ) print_errors(errors) + if django_settings.DEBUG and django_settings.STATICFILES_STORAGE != \ + 'django.contrib.staticfiles.storage.StaticFilesStorage': + if not os.path.isdir(django_settings.STATIC_ROOT): + askbot_warning( + 'Please run command\n\n' + ' python manage.py collectstatic' + + ) def run_startup_tests(): """function that runs diff --git a/askbot/tests/images/logo.gif b/askbot/tests/images/logo.gif old mode 100755 new mode 100644 diff --git a/askbot/tests/skin_tests.py b/askbot/tests/skin_tests.py index ecbea77d..5226e6d6 100644 --- a/askbot/tests/skin_tests.py +++ b/askbot/tests/skin_tests.py @@ -41,13 +41,9 @@ class SkinTests(TestCase): def assert_default_logo_in_skin(self, skin_name): url = skin_utils.get_media_url(askbot_settings.SITE_LOGO_URL) self.assertTrue('/' + skin_name + '/' in url) - response = self.client.get(url) - self.assertTrue(response.status_code == 200) def test_default_skin_logo(self): - """make sure that default logo - is where it is expected - """ + """make sure that default logo is where it is expected""" self.assert_default_logo_in_skin('default') def test_switch_to_custom_skin_logo(self): -- cgit v1.2.3-1-g7c22