source: products/quintagroup.pfg.captcha/trunk/quintagroup/pfg/captcha/field.py @ 2091

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

#174: minor updateds

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1from zope.event import notify
2from zope.lifecycleevent import ObjectCreatedEvent, ObjectModifiedEvent
3from Products.CMFCore.permissions import View
4
5from Products.Archetypes.atapi import *
6from Products.ATContentTypes.content.base import registerATCT
7
8from Products.PloneFormGen.content.fields import FGStringField
9from Products.PloneFormGen.content.fieldsBase import BareFieldSchema
10from Products.PloneFormGen.content.fieldsBase import BaseFormField
11from Products.PloneFormGen.content.fieldsBase import BaseFieldSchemaStringDefault
12
13from quintagroup.pfg.captcha.config import PROJECTNAME
14from quintagroup.pfg.captcha.widget import CaptchaWidget
15
16CAPTCHA_ID = 'key'
17
18def finalizeCaptchaFieldSchema( schema ):
19    schema['title'].default= 'key'
20    for field in ('title', 
21                  'description',
22                  'required', 
23                  'hidden', 
24                  'fgTDefault', 
25                  'fgTEnabled', 
26                  'fgDefault',
27                  'fgTValidator'):
28        schema[field].widget.visible = {'view':'invisible','edit':'invisible'}
29
30CaptchaFieldSchema = BaseFieldSchemaStringDefault.copy()
31finalizeCaptchaFieldSchema( CaptchaFieldSchema )
32
33def addCaptchaField(self, id, **kwargs):
34    id = CAPTCHA_ID
35    obj = CaptchaField(id)
36    notify(ObjectCreatedEvent(obj))
37    self._setObject(id, obj)
38    obj = self._getOb(id)
39    obj.initializeArchetype(**kwargs)
40    notify(ObjectModifiedEvent(obj))
41    return obj.getId()
42
43class CaptchaField(FGStringField):
44
45    _at_rename_after_creation = False
46    schema = CaptchaFieldSchema
47
48    def __init__(self, oid, **kwargs):
49        """ initialize class """
50        BaseFormField.__init__(self, oid, **kwargs)
51
52        # set a preconfigured field as an instance attribute
53        self.fgField = StringField('fg_string_field',
54            searchable=0,
55            required=1,
56            write_permission = View,
57            validators=('isCaptchaCorrect',),
58            widget=CaptchaWidget(),
59            )
60
61registerATCT(CaptchaField, PROJECTNAME)
Note: See TracBrowser for help on using the repository browser.