diff options
-rw-r--r-- | askbot/management/commands/askbot_add_test_content.py | 2 | ||||
-rw-r--r-- | askbot/migrations/0133_apply_global_group_to_posts_and_users.py | 12 | ||||
-rw-r--r-- | askbot/setup_templates/settings.py | 2 | ||||
-rw-r--r-- | askbot/setup_templates/settings.py.mustache | 2 | ||||
-rw-r--r-- | askbot/setup_templates/tinymce_sample_config.py | 26 | ||||
-rw-r--r-- | askbot/startup_procedures.py | 62 | ||||
-rw-r--r-- | askbot/tests/__init__.py | 1 | ||||
-rw-r--r-- | askbot/tests/utils_tests.py | 17 | ||||
-rw-r--r-- | askbot/utils/url_utils.py | 33 |
9 files changed, 150 insertions, 7 deletions
diff --git a/askbot/management/commands/askbot_add_test_content.py b/askbot/management/commands/askbot_add_test_content.py index 722a44b7..ca250339 100644 --- a/askbot/management/commands/askbot_add_test_content.py +++ b/askbot/management/commands/askbot_add_test_content.py @@ -14,7 +14,7 @@ NUM_COMMENTS = 20 # karma. This can be calculated dynamically - max of MIN_REP_TO_... settings INITIAL_REPUTATION = 500 -BAD_STUFF = ''#"<script>alert('hohoho')</script>" +BAD_STUFF = "<script>alert('hohoho')</script>" # Defining template inputs. USERNAME_TEMPLATE = BAD_STUFF + "test_user_%s" diff --git a/askbot/migrations/0133_apply_global_group_to_posts_and_users.py b/askbot/migrations/0133_apply_global_group_to_posts_and_users.py index 733c4c73..8c14b55d 100644 --- a/askbot/migrations/0133_apply_global_group_to_posts_and_users.py +++ b/askbot/migrations/0133_apply_global_group_to_posts_and_users.py @@ -82,7 +82,8 @@ class Migration(DataMigration): thread.groups.add(group) done_count += 1 - print 'Added global group to %d threads.\n' % done_count + if items.count(): + print 'Added global group to %d threads.\n' % done_count post_types = ('question', 'answer') posts = orm['askbot.Post'].objects.filter(post_type__in=post_types) @@ -93,7 +94,8 @@ class Migration(DataMigration): post.groups.add(group) done_count += 1 - print 'Added global group to %d posts.\n' % done_count + if posts.count(): + print 'Added global group to %d posts.\n' % done_count comments = orm['askbot.Post'].objects.filter(post_type='comment') message = 'Copying group information from answers ' +\ @@ -105,7 +107,8 @@ class Migration(DataMigration): comment.groups.add(*parent_post_groups) done_count += 1 - print 'Added global group to %d comments.\n' % done_count + if comments.count(): + print 'Added global group to %d comments.\n' % done_count users = orm['auth.User'].objects.all() message = 'Adding all users to the global group' @@ -117,7 +120,8 @@ class Migration(DataMigration): membership.save() done_count += 1 - print 'Added global group to %d users.' % done_count + if users.count(): + print 'Added global group to %d users.' % done_count def backwards(self, orm): diff --git a/askbot/setup_templates/settings.py b/askbot/setup_templates/settings.py index 7e65c833..71f49505 100644 --- a/askbot/setup_templates/settings.py +++ b/askbot/setup_templates/settings.py @@ -248,7 +248,7 @@ TINYMCE_DEFAULT_CONFIG = { 'plugins': 'askbot_imageuploader,askbot_attachment', 'theme_advanced_toolbar_location' : 'top', 'theme_advanced_toolbar_align': 'left', - 'theme_advanced_buttons1': 'bold,italic,underline,|,bullist,numlist,|,undo,redo,|,link,unlink,askbot_imageuploader,askbot_attachment' + 'theme_advanced_buttons1': 'bold,italic,underline,|,bullist,numlist,|,undo,redo,|,link,unlink,askbot_imageuploader,askbot_attachment', 'theme_advanced_buttons2': '', 'theme_advanced_buttons3' : '', 'theme_advanced_path': False, diff --git a/askbot/setup_templates/settings.py.mustache b/askbot/setup_templates/settings.py.mustache index 56b15da0..e9d9245e 100644 --- a/askbot/setup_templates/settings.py.mustache +++ b/askbot/setup_templates/settings.py.mustache @@ -249,7 +249,7 @@ TINYMCE_DEFAULT_CONFIG = { 'plugins': 'askbot_imageuploader,askbot_attachment', 'theme_advanced_toolbar_location' : 'top', 'theme_advanced_toolbar_align': 'left', - 'theme_advanced_buttons1': 'bold,italic,underline,|,bullist,numlist,|,undo,redo,|,link,unlink,askbot_imageuploader,askbot_attachment' + 'theme_advanced_buttons1': 'bold,italic,underline,|,bullist,numlist,|,undo,redo,|,link,unlink,askbot_imageuploader,askbot_attachment', 'theme_advanced_buttons2': '', 'theme_advanced_buttons3' : '', 'theme_advanced_path': False, diff --git a/askbot/setup_templates/tinymce_sample_config.py b/askbot/setup_templates/tinymce_sample_config.py new file mode 100644 index 00000000..c75170b0 --- /dev/null +++ b/askbot/setup_templates/tinymce_sample_config.py @@ -0,0 +1,26 @@ +TINYMCE_COMPRESSOR = True +TINYMCE_SPELLCHECKER = False +TINYMCE_JS_ROOT = os.path.join(STATIC_ROOT, 'common/media/js/tinymce/') +TINYMCE_URL = STATIC_URL + 'common/media/js/tinymce/' +TINYMCE_DEFAULT_CONFIG = { + 'plugins': 'askbot_imageuploader,askbot_attachment', + 'theme': 'advanced', + 'content_css': STATIC_URL + 'default/media/style/tinymce/content.css', + 'force_br_newlines': True, + 'force_p_newlines': False, + 'forced_root_block': '', + 'mode' : 'textareas', + 'oninit': "function(){ tinyMCE.activeEditor.setContent(askbot['data']['editorContent'] || ''); }", + 'plugins': 'askbot_imageuploader,askbot_attachment', + 'theme_advanced_toolbar_location' : 'top', + 'theme_advanced_toolbar_align': 'left', + 'theme_advanced_buttons1': 'bold,italic,underline,|,bullist,numlist,|,undo,redo,|,link,unlink,askbot_imageuploader,askbot_attachment', + 'theme_advanced_buttons2': '', + 'theme_advanced_buttons3' : '', + 'theme_advanced_path': False, + 'theme_advanced_resizing': True, + 'theme_advanced_resize_horizontal': False, + 'theme_advanced_statusbar_location': 'bottom', + 'width': '723', + 'height': '250' +} diff --git a/askbot/startup_procedures.py b/askbot/startup_procedures.py index 0fec6d5f..33c33da4 100644 --- a/askbot/startup_procedures.py +++ b/askbot/startup_procedures.py @@ -18,6 +18,7 @@ from django.conf import settings as django_settings from django.core.exceptions import ImproperlyConfigured from askbot.utils.loading import load_module from askbot.utils.functions import enumerate_string_list +from askbot.utils.url_utils import urls_equal from urlparse import urlparse PREAMBLE = """\n @@ -512,6 +513,66 @@ def test_custom_user_profile_tab(): footer = 'Please carefully read about adding a custom user profile tab.' print_errors(errors, header = header, footer = footer) +def get_tinymce_sample_config(): + """returns the sample configuration for TinyMCE + as string""" + askbot_root = askbot.get_install_directory() + file_path = os.path.join( + askbot_root, 'setup_templates', 'tinymce_sample_config.py' + ) + config_file = open(file_path, 'r') + sample_config = config_file.read() + config_file.close() + return sample_config + +def test_tinymce(): + """tests the tinymce editor setup""" + errors = list() + if 'tinymce' not in django_settings.INSTALLED_APPS: + errors.append("add 'tinymce', to the INSTALLED_APPS") + + required_attrs = ( + 'TINYMCE_COMPRESSOR', + 'TINYMCE_JS_ROOT', + 'TINYMCE_URL', + 'TINYMCE_DEFAULT_CONFIG' + ) + + missing_attrs = list() + for attr in required_attrs: + if not hasattr(django_settings, attr): + missing_attrs.append(attr) + + if missing_attrs: + errors.append('add missing settings: %s' % ', '.join(missing_attrs)) + + #check compressor setting + compressor_on = getattr(django_settings, 'TINYMCE_COMPRESSOR', False) + if compressor_on is False: + errors.append('add line: TINYMCE_COMPRESSOR = True') + + #check js root setting + js_root = getattr(django_settings, 'TINYMCE_JS_ROOT', '') + relative_js_path = 'common/media/js/tinymce/' + expected_js_root = os.path.join(django_settings.STATIC_ROOT, relative_js_path) + if os.path.normpath(js_root) != os.path.normpath(expected_js_root): + js_root_template = "add line: TINYMCE_JS_ROOT = os.path.join(STATIC_ROOT, '%s')" + errors.append(js_root_template % relative_js_path) + + #check url setting + url = getattr(django_settings, 'TINYMCE_URL', '') + expected_url = django_settings.STATIC_URL + relative_js_path + if urls_equal(url, expected_url) is False: + js_url_template = "add line: TINYMCE_URL = STATIC_URL + '%s'" + errors.append(js_url_template % relative_js_path) + + if errors: + header = 'Please add the tynymce editor configuration ' + \ + 'to your settings.py file.' + footer = 'You might want to use this sample configuration ' + \ + 'as template:\n\n' + get_tinymce_sample_config() + print_errors(errors, header=header, footer=footer) + def run_startup_tests(): """function that runs all startup tests, mainly checking settings config so far @@ -526,6 +587,7 @@ def run_startup_tests(): test_middleware() test_celery() #test_csrf_cookie_domain() + test_tinymce() test_staticfiles() test_avatar() settings_tester = SettingsTester({ diff --git a/askbot/tests/__init__.py b/askbot/tests/__init__.py index 056320f5..6e43940e 100644 --- a/askbot/tests/__init__.py +++ b/askbot/tests/__init__.py @@ -18,3 +18,4 @@ from askbot.tests.reply_by_email_tests import * from askbot.tests.widget_tests import * from askbot.tests.category_tree_tests import CategoryTreeTests from askbot.tests.user_model_tests import UserModelTests +from askbot.tests.utils_tests import * diff --git a/askbot/tests/utils_tests.py b/askbot/tests/utils_tests.py new file mode 100644 index 00000000..7f252b69 --- /dev/null +++ b/askbot/tests/utils_tests.py @@ -0,0 +1,17 @@ +from django.test import TestCase +from askbot.utils.url_utils import urls_equal + +class UrlUtilsTests(TestCase): + + def tests_urls_equal(self): + e = urls_equal + self.assertTrue(e('', '')) + self.assertTrue(e('', '/', True)) + self.assertTrue(e('http://cnn.com', 'http://cnn.com/', True)) + + self.assertFalse(e('https://cnn.com', 'http://cnn.com')) + self.assertFalse(e('http://cnn.com:80', 'http://cnn.com:8000')) + + self.assertTrue(e('http://cnn.com/path', 'http://cnn.com/path/', True)) + self.assertFalse(e('http://cnn.com/path', 'http://cnn.com/path/')) + diff --git a/askbot/utils/url_utils.py b/askbot/utils/url_utils.py index 6027d096..c58239c5 100644 --- a/askbot/utils/url_utils.py +++ b/askbot/utils/url_utils.py @@ -1,3 +1,4 @@ +import os import urlparse from django.core.urlresolvers import reverse from django.conf import settings @@ -13,6 +14,38 @@ def strip_path(url): ) ) +def append_trailing_slash(urlpath): + """if path is empty - returns slash + if not and path does not end with the slash + appends it + """ + if urlpath == '': + return '/' + elif not urlpath.endswith('/'): + return urlpath + '/' + return urlpath + +def urls_equal(url1, url2, ignore_trailing_slash=False): + """True, if urls are equal""" + purl1 = urlparse.urlparse(url1) + purl2 = urlparse.urlparse(url2) + if purl1.scheme != purl2.scheme: + return False + + if purl1.netloc != purl2.netloc: + return False + + if ignore_trailing_slash is True: + normfunc = append_trailing_slash + else: + normfunc = lambda v: v + + if normfunc(purl1.path) != normfunc(purl2.path): + return False + + #test remaining items in the parsed url + return purl1[3:] == purl2[3:] + def get_login_url(): """returns internal login url if django_authopenid is used, or |