diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2011-09-14 15:54:37 -0300 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2011-09-14 15:59:56 -0300 |
commit | 4f2f40eb73294c143014f50292601cdf7a4fd17b (patch) | |
tree | 2ab5e072ae055fcca021a3932122369828591ff7 | |
parent | 69b3fba391ab250a905ccde543727f7d4ed24e48 (diff) | |
download | askbot-4f2f40eb73294c143014f50292601cdf7a4fd17b.tar.gz askbot-4f2f40eb73294c143014f50292601cdf7a4fd17b.tar.bz2 askbot-4f2f40eb73294c143014f50292601cdf7a4fd17b.zip |
maintenance edits - moved more external urls to consts and pylinted a number of files
-rw-r--r-- | askbot/conf/external_keys.py | 52 | ||||
-rw-r--r-- | askbot/const/__init__.py | 62 | ||||
-rw-r--r-- | askbot/doc/source/optional-modules.rst | 8 | ||||
-rw-r--r-- | askbot/startup_procedures.py | 1 | ||||
-rw-r--r-- | askbot/utils/decorators.py | 28 | ||||
-rw-r--r-- | askbot/utils/functions.py | 16 | ||||
-rw-r--r-- | askbot/views/writers.py | 4 | ||||
-rw-r--r-- | askbot_requirements.txt | 1 | ||||
-rw-r--r-- | setup.py | 1 |
9 files changed, 99 insertions, 74 deletions
diff --git a/askbot/conf/external_keys.py b/askbot/conf/external_keys.py index a652d7fb..c5138be0 100644 --- a/askbot/conf/external_keys.py +++ b/askbot/conf/external_keys.py @@ -1,6 +1,7 @@ """ External service key settings """ +from askbot import const from askbot.conf.settings_wrapper import settings from askbot.deps import livesettings from django.utils.translation import ugettext as _ @@ -8,7 +9,8 @@ from django.conf import settings as django_settings EXTERNAL_KEYS = livesettings.ConfigurationGroup( 'EXTERNAL_KEYS', - _('Keys to connect the site with external services like Facebook, etc.') + _('Keys to connect the site with external ' + 'services like Facebook, etc.') ) settings.register( @@ -19,11 +21,12 @@ settings.register( help_text=_( 'This key helps google index your site ' 'please obtain is at ' - '<a href="%(google_webmasters_tools_url)s">' + '<a href="%(url)s?hl=%(lang)s">' 'google webmasters tools site</a>' - ) % {'google_webmasters_tools_url': - 'https://www.google.com/webmasters/tools/home?hl=' \ - + django_settings.LANGUAGE_CODE} + ) % { + 'url': const.DEPENDENCY_URLS['google-webmaster-tools'], + 'lang': django_settings.LANGUAGE_CODE, + } ) ) @@ -33,12 +36,12 @@ settings.register( 'GOOGLE_ANALYTICS_KEY', description=_('Google Analytics key'), help_text=_( - 'Obtain is at <a href="%(ga_site)s">' - 'Google Analytics</a> site, if you ' - 'wish to use Google Analytics to monitor ' - 'your site' - ) % {'ga_site':'http://www.google.com/intl/%s/analytics/' \ - % django_settings.LANGUAGE_CODE } + 'Obtain is at <a href="%(url)s">' + 'Google Analytics</a> site, if you ' + 'wish to use Google Analytics to monitor ' + 'your site' + ) % {'url': 'http://www.google.com/intl/%s/analytics/' \ + % django_settings.LANGUAGE_CODE } ) ) @@ -68,13 +71,11 @@ settings.register( 'Recaptcha is a tool that helps distinguish ' 'real people from annoying spam robots. ' 'Please get this and a public key at ' - 'the <a href="http://google.com/recaptcha">http://google.com/recaptcha</a>' - ) + 'the <a href="%(url)s">%(url)s</a>' + ) % {'url': const.DEPENDENCY_URLS['recaptcha']} ) ) - - settings.register( livesettings.BooleanValue( EXTERNAL_KEYS, @@ -82,8 +83,9 @@ settings.register( description=_('Enable Akismet spam detection(keys below are required)'), default=False, help_text = _( - 'To get an Akismet key please visit <a href="https://akismet.com/signup/">Akismet site</a>' - ) + 'To get an Akismet key please visit ' + '<a href="%(url)s">Akismet site</a>' + ) % {'url': const.DEPENDENCY_URLS['akismet']} ) ) @@ -104,9 +106,9 @@ settings.register( 'Facebook API key and Facebook secret ' 'allow to use Facebook Connect login method ' 'at your site. Please obtain these keys ' - 'at <a href="http://www.facebook.com/developers/createapp.php">' + 'at <a href="%(url)s">' 'facebook create app</a> site' - ) + ) % {'url': const.DEPENDENCY_URLS['facebook-apps']} ) ) @@ -124,9 +126,9 @@ settings.register( 'TWITTER_KEY', description=_('Twitter consumer key'), help_text=_( - 'Please register your forum at <a href="http://dev.twitter.com/apps/">' + 'Please register your forum at <a href="%(url)s">' 'twitter applications site</a>' - ), + ) % {'url': const.DEPENDENCY_URLS['twitter-apps']}, ) ) @@ -145,9 +147,9 @@ settings.register( 'LINKEDIN_KEY', description=_('LinkedIn consumer key'), help_text=_( - 'Please register your forum at <a href="https://www.linkedin.com/secure/developer">' + 'Please register your forum at <a href="%(url)s">' 'LinkedIn developer site</a>' - ), + ) % {'url': const.DEPENDENCY_URLS['linkedin-apps']}, ) ) @@ -166,9 +168,9 @@ settings.register( 'IDENTICA_KEY', description=_('ident.ca consumer key'), help_text=_( - 'Please register your forum at <a href="http://identi.ca/settings/oauthapps">' + 'Please register your forum at <a href="%(url)s">' 'Identi.ca applications site</a>' - ), + ) % {'url': const.DEPENDENCY_URLS['identica-apps']}, ) ) diff --git a/askbot/const/__init__.py b/askbot/const/__init__.py index e62dd2cb..d1449dd8 100644 --- a/askbot/const/__init__.py +++ b/askbot/const/__init__.py @@ -1,10 +1,11 @@ # encoding:utf-8 -from django.utils.translation import ugettext as _ -import re """ All constants could be used in other modules -For reasons that models, views can't have unicode text in this project, all unicode text go here. +For reasons that models, views can't have unicode +text in this project, all unicode text go here. """ +from django.utils.translation import ugettext as _ +import re CLOSE_REASONS = ( (1, _('duplicate question')), (2, _('question is off-topic or not relevant')), @@ -48,7 +49,8 @@ POST_SORT_METHODS = ( ('relevance-desc', _('relevance')), ) #todo: add assertion here that all sort methods are unique -#because they are keys to the hash used in implementations of Q.run_advanced_search +#because they are keys to the hash used in implementations +#of Q.run_advanced_search DEFAULT_POST_SORT_METHOD = 'activity-desc' POST_SCOPE_LIST = ( @@ -91,28 +93,28 @@ TAG_REGEX = r'^[%s]+$' % TAG_CHARS TAG_SPLIT_REGEX = r'[ ,]+' EMAIL_REGEX = re.compile(r'\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b', re.I) -TYPE_ACTIVITY_ASK_QUESTION=1 -TYPE_ACTIVITY_ANSWER=2 -TYPE_ACTIVITY_COMMENT_QUESTION=3 -TYPE_ACTIVITY_COMMENT_ANSWER=4 -TYPE_ACTIVITY_UPDATE_QUESTION=5 -TYPE_ACTIVITY_UPDATE_ANSWER=6 -TYPE_ACTIVITY_PRIZE=7 -TYPE_ACTIVITY_MARK_ANSWER=8 -TYPE_ACTIVITY_VOTE_UP=9 -TYPE_ACTIVITY_VOTE_DOWN=10 -TYPE_ACTIVITY_CANCEL_VOTE=11 -TYPE_ACTIVITY_DELETE_QUESTION=12 -TYPE_ACTIVITY_DELETE_ANSWER=13 -TYPE_ACTIVITY_MARK_OFFENSIVE=14 -TYPE_ACTIVITY_UPDATE_TAGS=15 -TYPE_ACTIVITY_FAVORITE=16 +TYPE_ACTIVITY_ASK_QUESTION = 1 +TYPE_ACTIVITY_ANSWER = 2 +TYPE_ACTIVITY_COMMENT_QUESTION = 3 +TYPE_ACTIVITY_COMMENT_ANSWER = 4 +TYPE_ACTIVITY_UPDATE_QUESTION = 5 +TYPE_ACTIVITY_UPDATE_ANSWER = 6 +TYPE_ACTIVITY_PRIZE = 7 +TYPE_ACTIVITY_MARK_ANSWER = 8 +TYPE_ACTIVITY_VOTE_UP = 9 +TYPE_ACTIVITY_VOTE_DOWN = 10 +TYPE_ACTIVITY_CANCEL_VOTE = 11 +TYPE_ACTIVITY_DELETE_QUESTION = 12 +TYPE_ACTIVITY_DELETE_ANSWER = 13 +TYPE_ACTIVITY_MARK_OFFENSIVE = 14 +TYPE_ACTIVITY_UPDATE_TAGS = 15 +TYPE_ACTIVITY_FAVORITE = 16 TYPE_ACTIVITY_USER_FULL_UPDATED = 17 TYPE_ACTIVITY_EMAIL_UPDATE_SENT = 18 TYPE_ACTIVITY_MENTION = 19 TYPE_ACTIVITY_UNANSWERED_REMINDER_SENT = 20 -#TYPE_ACTIVITY_EDIT_QUESTION=17 -#TYPE_ACTIVITY_EDIT_ANSWER=18 +#TYPE_ACTIVITY_EDIT_QUESTION = 17 +#TYPE_ACTIVITY_EDIT_ANSWER = 18 #todo: rename this to TYPE_ACTIVITY_CHOICES TYPE_ACTIVITY = ( @@ -250,11 +252,21 @@ DEFAULT_USER_STATUS = 'w' #number of items to show in user views USER_VIEW_DATA_SIZE = 50 +#not really dependency, but external links, which it would +#be nice to test for correctness from time to time DEPENDENCY_URLS = { - 'mathjax': 'http://www.mathjax.org/resources/docs/?installation.html', + 'akismet': 'https://akismet.com/signup/', + 'cc-by-sa': 'http://creativecommons.org/licenses/by-sa/3.0/legalcode', + 'embedding-video': \ + 'http://askbot.org/doc/optional-modules.html#embedding-video', 'favicon': 'http://en.wikipedia.org/wiki/Favicon', - 'embedding-video': 'http://askbot.org/doc/optional-modules.html#embedding-video', - 'cc-by-sa': 'http://creativecommons.org/licenses/by-sa/3.0/legalcode' + 'facebook-apps': 'http://www.facebook.com/developers/createapp.php', + 'google-webmaster-tools': 'https://www.google.com/webmasters/tools/home', + 'identica-apps': 'http://identi.ca/settings/oauthapps', + 'linkedin-apps': 'https://www.linkedin.com/secure/developer', + 'mathjax': 'http://www.mathjax.org/resources/docs/?installation.html', + 'recaptcha': 'http://google.com/recaptcha', + 'twitter-apps': 'http://dev.twitter.com/apps/', } PASSWORD_MIN_LENGTH = 8 diff --git a/askbot/doc/source/optional-modules.rst b/askbot/doc/source/optional-modules.rst index c18c6aa2..164f2f8c 100644 --- a/askbot/doc/source/optional-modules.rst +++ b/askbot/doc/source/optional-modules.rst @@ -136,11 +136,3 @@ To enable authentication for self hosted wordpress sites(wordpress.com blogs wil * Upload an icon for display in the login area. After doing this steps you should be able to login with your self hosted wordpress site user/password combination. - -Akismet spam detection tool -=========================== - -To enable Akismet for spam detection you will need to install `akismet <http://pypi.python.org/pypi/akismet/0.2.0>`_ from pypi and in the live settins for -external keys activate click on "Enable Akismet for spam detection" and enter the Akismet keys below. To get an Akismet key signup into `Akismet and select your plan. <https://akismet.com/signup/>`_ - -Currently it will just block every spam positive content of being posted to the site, including, questions, answers and comments. diff --git a/askbot/startup_procedures.py b/askbot/startup_procedures.py index 4fb41eb6..cc7f86c0 100644 --- a/askbot/startup_procedures.py +++ b/askbot/startup_procedures.py @@ -136,6 +136,7 @@ def try_import(module_name, pypi_package_name): def test_modules(): """tests presence of required modules""" + try_import('akismet', 'akismet') try_import('recaptcha_works', 'django-recaptcha-works') def test_postgres(): diff --git a/askbot/utils/decorators.py b/askbot/utils/decorators.py index 6dbf021c..29e92645 100644 --- a/askbot/utils/decorators.py +++ b/askbot/utils/decorators.py @@ -7,7 +7,6 @@ import inspect import logging from django.conf import settings from django.core import exceptions as django_exceptions -from django.core import urlresolvers from django.core.urlresolvers import reverse from django.core.exceptions import ImproperlyConfigured from django.http import HttpResponse, HttpResponseForbidden, Http404 @@ -190,18 +189,27 @@ def check_spam(field): data.update({'comment_author_email': request.user.email}) from akismet import Akismet - api = Akismet(askbot_settings.AKISMET_API_KEY, - smart_str(askbot_settings.APP_URL), - "Askbot/%s" % get_version()) + api = Akismet( + askbot_settings.AKISMET_API_KEY, + smart_str(askbot_settings.APP_URL), + "Askbot/%s" % get_version() + ) if api.comment_check(comment, data, build_data=False): - logging.debug('Spam detected in %s post at: %s' % - (request.user.username, datetime.datetime.now())) - spam_message = _("Spam was detected on your post, sorry \ - for that if you are not a spammer") + logging.debug( + 'Spam detected in %s post at: %s', + request.user.username, + datetime.datetime.now() + ) + spam_message = _( + 'Spam was detected on your post, sorry ' + 'for if this is a mistake' + ) if request.is_ajax(): - return HttpResponseForbidden(spam_message, - mimetype="application/json") + return HttpResponseForbidden( + spam_message, + mimetype="application/json" + ) else: request.user.message_set.create(message=spam_message) return HttpResponseRedirect(reverse('index')) diff --git a/askbot/utils/functions.py b/askbot/utils/functions.py index 3906bb9e..d31d9027 100644 --- a/askbot/utils/functions.py +++ b/askbot/utils/functions.py @@ -8,7 +8,7 @@ def get_from_dict_or_object(source, key): try: return source[key] except: - return getattr(source,key) + return getattr(source, key) def is_iterable(thing): @@ -54,7 +54,7 @@ def not_a_robot_request(request): return False -def diff_date(date, limen=2, use_on_prefix = False): +def diff_date(date, use_on_prefix = False): now = datetime.datetime.now()#datetime(*time.localtime()[0:6])#??? diff = now - date days = diff.days @@ -75,9 +75,17 @@ def diff_date(date, limen=2, use_on_prefix = False): elif days == 1: return _('yesterday') elif minutes >= 60: - return ungettext('%(hr)d hour ago','%(hr)d hours ago',hours) % {'hr':hours} + return ungettext( + '%(hr)d hour ago', + '%(hr)d hours ago', + hours + ) % {'hr':hours} else: - return ungettext('%(min)d min ago','%(min)d mins ago',minutes) % {'min':minutes} + return ungettext( + '%(min)d min ago', + '%(min)d mins ago', + minutes + ) % {'min':minutes} #todo: this function may need to be removed to simplify the paginator functionality LEADING_PAGE_RANGE_DISPLAYED = TRAILING_PAGE_RANGE_DISPLAYED = 5 diff --git a/askbot/views/writers.py b/askbot/views/writers.py index a4ec0bc1..fcc98761 100644 --- a/askbot/views/writers.py +++ b/askbot/views/writers.py @@ -249,7 +249,7 @@ def ask(request):#view used to ask a new question form.initial['title'] = request.GET['title'] else: #attempt to extract title from previous search query - search_state = request.session.get('search_state',None) + search_state = request.session.get('search_state', None) if search_state: query = search_state.query form.initial['title'] = query @@ -262,7 +262,7 @@ def ask(request):#view used to ask a new question form.initial['title'] = request.GET['title'] else: #attempt to extract title from previous search query - search_state = request.session.get('search_state',None) + search_state = request.session.get('search_state', None) if search_state: query = search_state.query form.initial['title'] = query diff --git a/askbot_requirements.txt b/askbot_requirements.txt index 70bc5874..a1d3b603 100644 --- a/askbot_requirements.txt +++ b/askbot_requirements.txt @@ -1,3 +1,4 @@ +akismet django>=1.1.2 Jinja2 Coffin>=0.3 @@ -7,6 +7,7 @@ import sys #you might want to install django-debug-toolbar as well install_requires = [ + 'akismet', 'django>=1.1.2', 'Jinja2', 'Coffin>=0.3', |