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

Last change on this file since 3606 was 3606, checked in by vmaksymiv, 7 years ago

PPP fixes

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