naro

SchemaForm, fieldsets and updateWidgets

Jan 28th, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1. from zope import schema
  2. from five import grok
  3. from plone.directives import form
  4. from Products.CMFPlone.interfaces import IPloneSiteRoot
  5. from plone.supermodel.model import Fieldset
  6. from plone.supermodel.interfaces import FIELDSETS_KEY
  7.  
  8.  
  9. class IMySchema(form.Schema):
  10.  
  11.     field_one = schema.TextLine(title=u"Field one")
  12.     field_two = schema.TextLine(title=u"Field two")
  13.     field_three = schema.TextLine(title=u"Field three")
  14.  
  15. IMySchema.setTaggedValue(FIELDSETS_KEY,
  16.                                  [
  17.                                     # Fieldset('fieldset-one', fields=['field_one'],
  18.                                     #        label=u"Fieldset 1"),
  19.                                     Fieldset('fieldset-two', fields=['field_two', 'field_three'],
  20.                                            label=u"Fieldset 2")
  21.                                  ])
  22.  
  23.  
  24. class MyForm(form.SchemaForm):
  25.     ignoreContext = False
  26.  
  27.     schema = IMySchema
  28.  
  29.     grok.name('test-form')
  30.     grok.require('zope.Public')
  31.     grok.context(IPloneSiteRoot)
  32.  
  33.     def getContent(self):
  34.         return {'field_one': u'A',
  35.                 'field_two': u'B',
  36.                 'field_three': u'C'
  37.                 }
  38.  
  39.     def updateWidgets(self):
  40.         super(MyForm, self).updateWidgets()
  41.         # if there is no default fieldset, self.widgets._data is empty
  42.         # if there is default fieldset, self.widgets._data
  43.         # contains only fields from default fieldset
  44.         print "self.widgets: ", self.widgets._data
Advertisement
Add Comment
Please, Sign In to add comment