From: jordan Date: Tue, 15 Feb 2011 17:38:22 +0000 (+0000) Subject: OSQA-516, bugfix for the Akismet Module. There was problem with the loading of the... X-Git-Tag: live~447 X-Git-Url: https://git.openstreetmap.org/osqa.git/commitdiff_plain/329c51f0be21c7a0db57614d54ea52de63f2d80e OSQA-516, bugfix for the Akismet Module. There was problem with the loading of the ReCaptcha settings if the ReCaptcha module has been disabled. Now we added a try-except block that fixes the problem. Some improvements made. Better found-spam message: now we hide the Submit button of the found-spam message in case there is no recaptcha field -- we just don't need it. fields={} has been added to the SimpleCaptchaForm. It fixes the error @Nigel mentioned about. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@768 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum/forms/general.py b/forum/forms/general.py index 4b1133e..e0348a8 100644 --- a/forum/forms/general.py +++ b/forum/forms/general.py @@ -7,6 +7,7 @@ from django.http import str_to_unicode from forum.models import User from forum.modules import call_all_handlers import urllib +import logging DEFAULT_NEXT = getattr(settings, 'APP_BASE_URL') def clean_next(next): @@ -156,7 +157,11 @@ class SetPasswordForm(forms.Form): return self.cleaned_data['password2'] class SimpleCaptchaForm(forms.Form): + fields = {} + def __init__(self, *args, **kwargs): + super(SimpleCaptchaForm, self).__init__(*args, **kwargs) + spam_fields = call_all_handlers('create_anti_spam_field') if spam_fields: spam_fields = dict(spam_fields) @@ -166,4 +171,3 @@ class SimpleCaptchaForm(forms.Form): self._anti_spam_fields = spam_fields.keys() else: self._anti_spam_fields = [] - diff --git a/forum_modules/akismet/startup.py b/forum_modules/akismet/startup.py index d587ea1..2107bbb 100644 --- a/forum_modules/akismet/startup.py +++ b/forum_modules/akismet/startup.py @@ -1,5 +1,6 @@ from django.utils.translation import ugettext as _ from django.http import HttpResponse, HttpResponseRedirect +from django.template import RequestContext from django.utils import simplejson from django.utils.encoding import smart_str from django.shortcuts import render_to_response @@ -7,11 +8,14 @@ from forum.modules import decorate from forum import views from lib.akismet import Akismet from forum.settings import APP_URL, OSQA_VERSION -from settings import WORDPRESS_API_KEY, REP_FOR_NO_SPAM_CHECK, RECAPTCHA_PUB_KEY, RECAPTCHA_PRIV_KEY + +from settings import WORDPRESS_API_KEY, REP_FOR_NO_SPAM_CHECK + from forum.models.user import User from forum.forms.general import SimpleCaptchaForm import settings +import logging def can_bypass_spam_check(user): return user.is_authenticated and (user.is_superuser or user.is_staff or cmp(int(user.reputation), REP_FOR_NO_SPAM_CHECK) > 0) @@ -50,17 +54,18 @@ def check_spam(param, comment_type): return HttpResponse(simplejson.dumps(response), mimetype="application/json") else: captcha_checked = False - - if RECAPTCHA_PUB_KEY and RECAPTCHA_PRIV_KEY: - if captcha_form.is_valid(): + try: + if captcha_form.is_valid() and 'recaptcha' in captcha_form.fields.keys(): captcha_checked = True - + except: + pass + if not captcha_checked: return render_to_response('modules/akismet/foundspam.html', { 'action_name': comment_type, 'post_data' : post_data, 'captcha_form' : captcha_form, - }) + }, RequestContext(request)) return origin(request, *args, **kwargs) diff --git a/forum_modules/akismet/templates/foundspam.html b/forum_modules/akismet/templates/foundspam.html index 6b203c0..77251c7 100644 --- a/forum_modules/akismet/templates/foundspam.html +++ b/forum_modules/akismet/templates/foundspam.html @@ -12,6 +12,7 @@ We're sorry, but Akismet believes your {{ action_name }} is spam.
If you believe this is an error, please contact the forum administrator. {% endblocktrans %} +{% if captcha_form.recaptcha %}
@@ -19,7 +20,7 @@ If you believe this is an error, please contact the forum administrator. {% for post_item in post_data.items %} {% endfor %} - + {{ captcha_form.recaptcha }} @@ -29,6 +30,7 @@ If you believe this is an error, please contact the forum administrator.
+{% endif %} {% endblock %}