1 | ============================ |
---|
2 | quintagroup.formlib.captcha |
---|
3 | ============================ |
---|
4 | |
---|
5 | This package allows to add captcha to zope.formlib form. |
---|
6 | As 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 | |
---|
11 | What you have to do |
---|
12 | ------------------- |
---|
13 | |
---|
14 | 1. 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 | |
---|
22 | 2. If your form define Schema adapter (ICaptchaFormlibFormSchema |
---|
23 | adapter 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 | |
---|
33 | And away we go. |
---|
34 | |
---|
35 | In tests/tests.zcml we have registered a adapter and page view for test form, |
---|
36 | named @@formlib-captcha-form. |
---|
37 | |
---|
38 | Get 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 | |
---|
45 | Now 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 | |
---|