Add dead-simple captcha to show the z3c-form-extender works.
svn path=/plone.app.discussion/trunk/; revision=28371
This commit is contained in:
parent
8e9c75a6fc
commit
ef8e34adbb
44
plone/app/discussion/browser/captcha.py
Normal file
44
plone/app/discussion/browser/captcha.py
Normal file
@ -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")
|
@ -64,6 +64,14 @@
|
|||||||
permission="zope2.View"
|
permission="zope2.View"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<!-- Comment form extender -->
|
||||||
|
<adapter
|
||||||
|
factory=".captcha.Captcha" />
|
||||||
|
|
||||||
|
<adapter
|
||||||
|
factory=".captcha.CaptchaExtender"
|
||||||
|
provides="plone.z3cform.fieldsets.interfaces.IFormExtender" />
|
||||||
|
|
||||||
<!-- Comment view -->
|
<!-- Comment view -->
|
||||||
<browser:view
|
<browser:view
|
||||||
name="view"
|
name="view"
|
||||||
|
Loading…
Reference in New Issue
Block a user