Akismet spam protection plugin support added (collective.akismet).

svn path=/plone.app.discussion/trunk/; revision=37136
This commit is contained in:
Timo Stollenwerk 2010-06-10 13:11:33 +00:00
parent 92766752c4
commit 926314ea49
2 changed files with 20 additions and 4 deletions

View File

@ -6,7 +6,7 @@ from persistent import Persistent
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from z3c.form import validator from z3c.form import interfaces, validator
from z3c.form.field import Fields from z3c.form.field import Fields
from zope import interface, schema from zope import interface, schema
@ -70,4 +70,5 @@ class CaptchaExtender(extensible.FormExtender):
elif self.captcha == 'recaptcha': elif self.captcha == 'recaptcha':
from plone.formwidget.recaptcha import ReCaptchaFieldWidget from plone.formwidget.recaptcha import ReCaptchaFieldWidget
self.form.fields['captcha'].widgetFactory = ReCaptchaFieldWidget self.form.fields['captcha'].widgetFactory = ReCaptchaFieldWidget
elif self.captcha == 'akismet':
self.form.fields['captcha'].mode = interfaces.HIDDEN_MODE

View File

@ -19,6 +19,14 @@ try:
except ImportError: except ImportError:
pass pass
HAS_AKISMET = False
try:
from akismet import Akismet, AkismetError
HAS_AKISMET = True
except ImportError:
pass
def captcha_vocabulary(context): def captcha_vocabulary(context):
"""Vocabulary with all available captcha implementations. """Vocabulary with all available captcha implementations.
""" """
@ -41,6 +49,13 @@ def captcha_vocabulary(context):
value='recaptcha', value='recaptcha',
token='recaptcha', token='recaptcha',
title='ReCaptcha')) title='ReCaptcha'))
if HAS_AKISMET:
terms.append(
zope.schema.vocabulary.SimpleTerm(
value='akismet',
token='akismet',
title='Akismet'))
return zope.schema.vocabulary.SimpleVocabulary(terms) return zope.schema.vocabulary.SimpleVocabulary(terms)
interface.alsoProvides(captcha_vocabulary, interface.alsoProvides(captcha_vocabulary,