diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2011-11-25 15:22:23 -0300 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2011-11-25 15:24:38 -0300 |
commit | 7c789bc39c01a9fd3a57e1119a3cd430afcb7386 (patch) | |
tree | 6dbd23ebcdfbc7424e157e0110b39158e5249117 /askbot/startup_procedures.py | |
parent | 350d8b9aa7849a86fcbd97667703df834184d511 (diff) | |
download | askbot-7c789bc39c01a9fd3a57e1119a3cd430afcb7386.tar.gz askbot-7c789bc39c01a9fd3a57e1119a3cd430afcb7386.tar.bz2 askbot-7c789bc39c01a9fd3a57e1119a3cd430afcb7386.zip |
added support for LOGIN_REDIRECT_URL to django_authopenid submodule
Diffstat (limited to 'askbot/startup_procedures.py')
-rw-r--r-- | askbot/startup_procedures.py | 78 |
1 files changed, 57 insertions, 21 deletions
diff --git a/askbot/startup_procedures.py b/askbot/startup_procedures.py index b6a97f22..7ca06e1b 100644 --- a/askbot/startup_procedures.py +++ b/askbot/startup_procedures.py @@ -8,6 +8,7 @@ question: why not run these from askbot/__init__.py? the main function is run_startup_tests """ import sys +import os from django.db import transaction from django.conf import settings as django_settings from django.core.exceptions import ImproperlyConfigured @@ -113,17 +114,6 @@ the list of MIDDLEWARE_CLASSES in your settings.py - these are not used any more middleware_text = format_as_text_tuple_entries(remove_middleware_set) raise ImproperlyConfigured(PREAMBLE + error_message + middleware_text) - - -def test_i18n(): - """askbot requires use of USE_I18N setting""" - if getattr(django_settings, 'USE_I18N', False) == False: - raise ImproperlyConfigured( - 'Please set USE_I18N = True in settings.py and ' - 'set the LANGUAGE_CODE parameter correctly ' - 'it is very important for askbot.' - ) - def try_import(module_name, pypi_package_name): """tries importing a module and advises to install A corresponding Python package in the case import fails""" @@ -219,14 +209,44 @@ def test_celery(): "in your settings.py file" ) -def test_cache(): - """Tests cache settings""" - if not hasattr(django_settings, 'CACHE_MIDDLEWARE_ANONYMOUS_ONLY'): - raise ImproperlyConfigured(PREAMBLE + \ - "\nPlease set\n" - "CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True\n" - "in your settings.py file" - ) +class SettingsTester(object): + """class to test contents of the settings.py file""" + + def __init__(self, requirements = None): + """loads the settings module and inits some variables + parameter `requirements` is a dictionary with keys + as setting names and values - another dictionary, which + has keys (optional, if noted and required otherwise):: + + * required_value (optional) + * error_message + """ + self.settings = load_module(os.environ['DJANGO_SETTINGS_MODULE']) + self.messages = list() + self.requirements = requirements + + + def test_setting(self, name, value = None, message = 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) + + def run(self): + for setting_name in self.requirements: + self.test_setting( + setting_name, + **self.requirements[setting_name] + ) + if len(self.messages) != 0: + raise ImproperlyConfigured( + PREAMBLE + + '\n\nTime to do some maintenance of your settings.py:\n\n* ' + + '\n\n* '.join(self.messages) + ) def run_startup_tests(): """function that runs @@ -238,11 +258,27 @@ def run_startup_tests(): test_encoding() test_modules() test_askbot_url() - test_i18n() test_postgres() test_middleware() test_celery() - test_cache() + settings_tester = SettingsTester({ + 'CACHE_MIDDLEWARE_ANONYMOUS_ONLY': { + 'value': True, + 'message': "add line CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True" + }, + 'USE_I18N': { + 'value': True, + 'message': 'Please set USE_I18N = True and\n' + 'set the LANGUAGE_CODE parameter correctly' + }, + 'LOGIN_REDIRECT_URL': { + 'message': 'add setting LOGIN_REDIRECT_URL - an url\n' + 'where you want to send users after they log in\n' + 'a reasonable default is\n' + 'LOGIN_REDIRECT_URL = ASKBOT_URL' + } + }) + settings_tester.run() @transaction.commit_manually def run(): |