source: products/quintagroup.formlib.captcha/trunk/quintagroup/formlib/captcha/README.txt @ 2805

Last change on this file since 2805 was 2805, checked in by mylan, 14 years ago

#195: Cleanup code, doctest

  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1============================
2 quintagroup.formlib.captcha
3============================
4
5This package allows to add captcha to zope.formlib form.
6As a result such forms are prevented from automatic submit.
7
8 *example.py* module provides example of usage the *Captcha*
9 field from the package in formlib forms.
10
11What you have to do
12-------------------
13
141. You should add a *Captcha* field to your schema:
15
16  >>> from zope.interface import Interface
17  >>> from quintagroup.formlib.captcha import Captcha
18  >>> class ICaptchaFormlibFormSchema(Interface):
19  ...     # ... your schema definition
20  ...     captcha = Captcha(title=u'Type the code')
21
222. If your form define Schema adapter (ICaptchaFormlibFormSchema
23adapter in our case), just add *captcha* property.
24
25  >>> from zope.component import adapts
26  >>> from zope.interface import implements
27  >>> class CaptchaFormlibFormAdapter(object):
28  ...     adapts(Interface)
29  ...     implements(ICaptchaFormlibFormSchema)
30  ...     # ... your adapter code
31  ...     captcha = None
32 
33And away we go.
34
35In tests/tests.zcml we have registered a adapter and page view for test form,
36named @@formlib-captcha-form.
37
38Get browser object .
39   
40    >>> from Products.Five.testbrowser import Browser
41    >>> from Products.PloneTestCase import PloneTestCase as ptc
42    >>> user, pwd = ptc.default_user, ptc.default_password
43    >>> browser = Browser()
44
45Now check if captcha presented on the mentioned form.
46
47    >>> browser.open(self.portal.absolute_url() + '/@@formlib-captcha-form')
48    >>> open("/tmp/test.html", 'w').write(browser.contents)
49    >>> "Type the code" in browser.contents
50    True
51
Note: See TracBrowser for help on using the repository browser.