source: products/qPloneCaptchaField/trunk/content/CaptchaField.py @ 3665

Last change on this file since 3665 was 263, checked in by fenix, 15 years ago

create tags for qPloneEpydoc

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