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

Last change on this file since 3430 was 3430, checked in by vmaksymiv, 10 years ago

merged changes from http://svn.quintagroup.com/products/quintagroup.pfg.captcha/branches/broken_types.

  • Property svn:eol-style set to native
File size: 1.9 KB
RevLine 
[263]1from zope.event import notify
2from zope.lifecycleevent import ObjectCreatedEvent, ObjectModifiedEvent
[1]3from Products.CMFCore.permissions import View
4
[3168]5from Products.Archetypes.atapi import StringField
[1]6from Products.ATContentTypes.content.base import registerATCT
7
8from Products.PloneFormGen.content.fields import FGStringField
[2091]9from Products.PloneFormGen.content.fieldsBase import BaseFormField
[3168]10from Products.PloneFormGen.content.fieldsBase \
11        import BaseFieldSchemaStringDefault
[1]12
[1973]13from quintagroup.pfg.captcha.config import PROJECTNAME
[2085]14from quintagroup.pfg.captcha.widget import CaptchaWidget
[1]15
[263]16CAPTCHA_ID = 'key'
[2098]17HIDDEN_FIELDS = [
[3168]18    'title',
[2098]19    'description',
[3168]20    'required',
21    'hidden',
22    'fgTDefault',
23    'fgTEnabled',
[2098]24    'fgDefault',
25    'fgTValidator']
[263]26
[3168]27
28def finalizeCaptchaFieldSchema(schema):
29    schema['title'].default = 'key'
[2098]30    for field in HIDDEN_FIELDS:
[3168]31        schema[field].widget.visible = {'view': 'invisible',
32                                        'edit': 'invisible'}
[263]33
34CaptchaFieldSchema = BaseFieldSchemaStringDefault.copy()
[3168]35finalizeCaptchaFieldSchema(CaptchaFieldSchema)
[263]36
[3168]37
[263]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
[3168]47
[1]48class CaptchaField(FGStringField):
49
[3430]50    _at_rename_after_creation = True
[263]51    schema = CaptchaFieldSchema
[1]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,
[3168]61            write_permission=View,
[1]62            validators=('isCaptchaCorrect',),
63            widget=CaptchaWidget(),
64            )
65
[263]66registerATCT(CaptchaField, PROJECTNAME)
Note: See TracBrowser for help on using the repository browser.