From ef8e34adbb964c66da1b1e372f4374c67a1e98e9 Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Wed, 5 Aug 2009 09:01:58 +0000 Subject: [PATCH] Add dead-simple captcha to show the z3c-form-extender works. svn path=/plone.app.discussion/trunk/; revision=28371 --- plone/app/discussion/browser/captcha.py | 44 +++++++++++++++++++++ plone/app/discussion/browser/configure.zcml | 8 ++++ 2 files changed, 52 insertions(+) create mode 100644 plone/app/discussion/browser/captcha.py diff --git a/plone/app/discussion/browser/captcha.py b/plone/app/discussion/browser/captcha.py new file mode 100644 index 0000000..787df43 --- /dev/null +++ b/plone/app/discussion/browser/captcha.py @@ -0,0 +1,44 @@ +from persistent import Persistent + +from z3c.form.field import Fields + +from zope import interface, schema + +from zope.annotation import factory +from zope.annotation.attribute import AttributeAnnotations + +from zope.component import adapts, provideAdapter + +from zope.publisher.interfaces.browser import IDefaultBrowserLayer + +from zope.interface import Interface, implements + +from plone.z3cform.fieldsets import extensible +from plone.z3cform.fieldsets.interfaces import IFormExtender + +from plone.app.discussion.comment import Comment + +class ICaptcha(Interface): + captcha = schema.TextLine(title=u"Type the word 'human' in all capital letters.", + required=False) + +class Captcha(Persistent): + interface.implements(ICaptcha) + adapts(Comment) + captcha = u"" + +Captcha = factory(Captcha) +provideAdapter(Captcha) +provideAdapter(AttributeAnnotations) + +class CaptchaExtender(extensible.FormExtender): + adapts(Interface, IDefaultBrowserLayer, Interface) # context, request, form + + def __init__(self, context, request, form): + self.context = context + self.request = request + self.form = form + + def update(self): + # Add all fields from the captcha interface + self.add(ICaptcha, prefix="extra") \ No newline at end of file diff --git a/plone/app/discussion/browser/configure.zcml b/plone/app/discussion/browser/configure.zcml index 19f4589..0d35e35 100644 --- a/plone/app/discussion/browser/configure.zcml +++ b/plone/app/discussion/browser/configure.zcml @@ -64,6 +64,14 @@ permission="zope2.View" /> + + + + +