From fc02faa2e23bde7f64429bf8d644b379af5aff20 Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Sat, 7 Jan 2012 23:40:00 -0300 Subject: replaced ASKBOT_FILE_UPLOAD_DIR setting with MEDIA_ROOT --- askbot/conf/license.py | 1 - askbot/conf/login_providers.py | 1 - askbot/conf/skin_general_settings.py | 3 --- askbot/conf/user_settings.py | 1 - askbot/deps/livesettings/values.py | 6 +++++- askbot/doc/source/changelog.rst | 1 + askbot/setup_templates/settings.py | 7 +++---- askbot/setup_templates/settings.py.mustache | 6 +++--- askbot/skins/utils.py | 2 +- askbot/startup_procedures.py | 26 +++++++++++++++++++++----- askbot/tests/page_load_tests.py | 4 ++-- askbot/urls.py | 2 +- askbot/views/writers.py | 1 - 13 files changed, 37 insertions(+), 24 deletions(-) diff --git a/askbot/conf/license.py b/askbot/conf/license.py index 20a2743f..dfb18530 100644 --- a/askbot/conf/license.py +++ b/askbot/conf/license.py @@ -76,7 +76,6 @@ settings.register( LICENSE_SETTINGS, 'LICENSE_LOGO_URL', description = _('License logo image'), - upload_directory = django_settings.ASKBOT_FILE_UPLOAD_DIR, upload_url = '/' + django_settings.ASKBOT_UPLOADED_FILES_URL, default = '/images/cc-by-sa.png', url_resolver = skin_utils.get_media_url diff --git a/askbot/conf/login_providers.py b/askbot/conf/login_providers.py index b6073eea..49f568bd 100644 --- a/askbot/conf/login_providers.py +++ b/askbot/conf/login_providers.py @@ -56,7 +56,6 @@ settings.register( livesettings.ImageValue( LOGIN_PROVIDERS, 'WORDPRESS_SITE_ICON', - upload_directory=django_settings.ASKBOT_FILE_UPLOAD_DIR, upload_url='/' + django_settings.ASKBOT_UPLOADED_FILES_URL, default='/images/logo.gif', description=_('Upload your icon'), diff --git a/askbot/conf/skin_general_settings.py b/askbot/conf/skin_general_settings.py index 387ac1f6..f43f45d8 100644 --- a/askbot/conf/skin_general_settings.py +++ b/askbot/conf/skin_general_settings.py @@ -25,7 +25,6 @@ settings.register( 'To change the logo, select new file, ' 'then submit this whole form.' ), - upload_directory = django_settings.ASKBOT_FILE_UPLOAD_DIR, upload_url = django_settings.ASKBOT_URL + '/' + django_settings.ASKBOT_UPLOADED_FILES_URL, default = '/images/logo.gif', url_resolver = skin_utils.get_media_url @@ -58,7 +57,6 @@ settings.register( 'about favicon ' 'at this page.' ) % {'favicon_info_url': const.DEPENDENCY_URLS['favicon']}, - upload_directory = django_settings.ASKBOT_FILE_UPLOAD_DIR, allowed_file_extensions = ('ico',),#only allow .ico files upload_url = '/' + django_settings.ASKBOT_UPLOADED_FILES_URL, default = '/images/favicon.gif', @@ -75,7 +73,6 @@ settings.register( 'An 88x38 pixel image that is used on the login screen ' 'for the password login button.' ), - upload_directory = django_settings.ASKBOT_FILE_UPLOAD_DIR, upload_url = '/' + django_settings.ASKBOT_UPLOADED_FILES_URL, default = '/images/pw-login.gif', url_resolver = skin_utils.get_media_url diff --git a/askbot/conf/user_settings.py b/askbot/conf/user_settings.py index 086f7583..4c5d17db 100644 --- a/askbot/conf/user_settings.py +++ b/askbot/conf/user_settings.py @@ -70,7 +70,6 @@ settings.register( 'To change the avatar image, select new file, ' 'then submit this whole form.' ), - upload_directory = django_settings.ASKBOT_FILE_UPLOAD_DIR, upload_url = '/' + django_settings.ASKBOT_UPLOADED_FILES_URL, default = '/images/nophoto.png', url_resolver = skin_utils.get_media_url diff --git a/askbot/deps/livesettings/values.py b/askbot/deps/livesettings/values.py index 9587a16d..db366465 100644 --- a/askbot/deps/livesettings/values.py +++ b/askbot/deps/livesettings/values.py @@ -4,6 +4,7 @@ http://code.google.com/p/django-values/ """ from decimal import Decimal from django import forms +from django.conf import settings as django_settings from django.core.exceptions import ImproperlyConfigured from django.utils import simplejson from django.utils.datastructures import SortedDict @@ -600,7 +601,10 @@ class ImageValue(StringValue): 'allowed_file_extensions', ('jpg', 'gif', 'png') ) - self.upload_directory = kwargs.pop('upload_directory') + self.upload_directory = kwargs.pop( + 'upload_directory', + django_settings.MEDIA_ROOT + ) self.upload_url = kwargs.pop('upload_url') self.url_resolver = kwargs.pop('url_resolver', None) super(ImageValue, self).__init__(*args, **kwargs) diff --git a/askbot/doc/source/changelog.rst b/askbot/doc/source/changelog.rst index c228e158..cb67a62e 100644 --- a/askbot/doc/source/changelog.rst +++ b/askbot/doc/source/changelog.rst @@ -15,6 +15,7 @@ Development version (not released yet) text to live settings and allowed body-less questions (Radim Řehůřek, Evgeny) * allowed disabling use of gravatar site-wide (Rosandra Cuello Suñol) * when internal login app is disabled - links to login/logout/add-remove-login-methods are gone (Evgeny) +* replaced setting `ASKBOT_FILE_UPLOAD_DIR` with django's `MEDIA_ROOT` (Evgeny) 0.7.36 (Dec 20, 2011) --------------------- diff --git a/askbot/setup_templates/settings.py b/askbot/setup_templates/settings.py index 715e6ce8..2baf3fd6 100644 --- a/askbot/setup_templates/settings.py +++ b/askbot/setup_templates/settings.py @@ -68,7 +68,7 @@ LANGUAGE_CODE = 'en' # Absolute path to the directory that holds media. # Example: "/home/media/media.lawrence.com/" -ASKBOT_FILE_UPLOAD_DIR = os.path.join(os.path.dirname(__file__), 'askbot', 'upfiles') +MEDIA_ROOT = os.path.join(os.path.dirname(__file__), 'askbot', 'upfiles') PROJECT_ROOT = os.path.dirname(__file__) @@ -167,9 +167,8 @@ INSTALLED_APPS = ( 'djkombu', 'followit', #'avatar',#experimental use git clone git://github.com/ericflo/django-avatar.git$ - #requires setting of MEDIA_ROOT and MEDIA_URL - #values of which can be the same as ASKBOT_FILE_UPLOAD_DIR and ASKBOT_UPLOADED_FILES_URL, - #respectively + #requires setting MEDIA_URL + #values of which can be the same as ASKBOT_UPLOADED_FILES_URL, ) diff --git a/askbot/setup_templates/settings.py.mustache b/askbot/setup_templates/settings.py.mustache index 69da823a..95b918f2 100644 --- a/askbot/setup_templates/settings.py.mustache +++ b/askbot/setup_templates/settings.py.mustache @@ -68,7 +68,7 @@ LANGUAGE_CODE = 'en' # Absolute path to the directory that holds media. # Example: "/home/media/media.lawrence.com/" -ASKBOT_FILE_UPLOAD_DIR = os.path.join(os.path.dirname(__file__), 'askbot', 'upfiles') +MEDIA_ROOT = os.path.join(os.path.dirname(__file__), 'askbot', 'upfiles') PROJECT_ROOT = os.path.dirname(__file__) @@ -166,8 +166,8 @@ INSTALLED_APPS = ( 'djkombu', 'followit', #'avatar',#experimental use git clone git://github.com/ericflo/django-avatar.git$ - #requires setting of MEDIA_ROOT and MEDIA_URL - #values of which can be the same as ASKBOT_FILE_UPLOAD_DIR and ASKBOT_UPLOADED_FILES_URL, + #requires setting of MEDIA_URL + #values of which can be the same as ASKBOT_UPLOADED_FILES_URL, #respectively ) diff --git a/askbot/skins/utils.py b/askbot/skins/utils.py index da3a8a06..34bf658f 100644 --- a/askbot/skins/utils.py +++ b/askbot/skins/utils.py @@ -109,7 +109,7 @@ def get_media_url(url, ignore_missing = False): 1 ) file_path = os.path.join( - django_settings.ASKBOT_FILE_UPLOAD_DIR, + django_settings.MEDIA_ROOT, file_path ) if os.path.isfile(file_path): diff --git a/askbot/startup_procedures.py b/askbot/startup_procedures.py index 9c962f2a..b37ac52d 100644 --- a/askbot/startup_procedures.py +++ b/askbot/startup_procedures.py @@ -228,14 +228,25 @@ class SettingsTester(object): self.requirements = requirements - def test_setting(self, name, value = None, message = None): + def test_setting(self, name, + value = None, message = None, + test_for_absence = False, + replace_hint = None + ): """if setting does is not present or if the value != required_value, adds an error message """ - if not hasattr(self.settings, name): - self.messages.append(message) - elif value and getattr(self.settings, name) != value: - self.messages.append(message) + if test_for_absence: + if hasattr(self.settings, name): + if replace_hint: + value = getattr(self.settings, name) + message += replace_hint % value + self.messages.append(message) + else: + if not hasattr(self.settings, name): + self.messages.append(message) + elif value and getattr(self.settings, name) != value: + self.messages.append(message) def run(self): for setting_name in self.requirements: @@ -278,6 +289,11 @@ def run_startup_tests(): 'where you want to send users after they log in\n' 'a reasonable default is\n' 'LOGIN_REDIRECT_URL = ASKBOT_URL' + }, + 'ASKBOT_FILE_UPLOAD_DIR': { + 'message': 'Please replace setting ASKBOT_FILE_UPLOAD_DIR ', + 'test_for_absence': True, + 'replace_hint': "with MEDIA_ROOT = '%s'" } }) settings_tester.run() diff --git a/askbot/tests/page_load_tests.py b/askbot/tests/page_load_tests.py index 3ecc126f..d92d0e0c 100644 --- a/askbot/tests/page_load_tests.py +++ b/askbot/tests/page_load_tests.py @@ -122,11 +122,11 @@ class PageLoadTestCase(AskbotTestCase): self.try_url( 'about', status_code=status_code, - template='about.html') + template='static_page.html') self.try_url( 'privacy', status_code=status_code, - template='privacy.html') + template='static_page.html') self.try_url('logout', template='authopenid/logout.html') #todo: test different tabs self.try_url( diff --git a/askbot/urls.py b/askbot/urls.py index 4bfab225..047ff7ad 100644 --- a/askbot/urls.py +++ b/askbot/urls.py @@ -44,7 +44,7 @@ urlpatterns = patterns('', url( # TODO: replace with django.conf.urls.static ? r'^%s(?P.*)$' % settings.ASKBOT_UPLOADED_FILES_URL, 'django.views.static.serve', - {'document_root': settings.ASKBOT_FILE_UPLOAD_DIR.replace('\\','/')}, + {'document_root': settings.MEDIA_ROOT.replace('\\','/')}, name='uploaded_file', ), #no translation for this url!! diff --git a/askbot/views/writers.py b/askbot/views/writers.py index f8da2181..4b4c011e 100644 --- a/askbot/views/writers.py +++ b/askbot/views/writers.py @@ -79,7 +79,6 @@ def upload(request):#ajax upload file to a question or answer ) + file_extension file_storage = FileSystemStorage( - location = settings.ASKBOT_FILE_UPLOAD_DIR, base_url = reverse('uploaded_file', kwargs = {'path':''}), ) # use default storage to store file -- cgit v1.2.3-1-g7c22