本文整理匯總了Python中plone.autoform.supermodel.FormSchema類的典型用法代碼示例。如果您正苦於以下問題:Python FormSchema類的具體用法?Python FormSchema怎麽用?Python FormSchema使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了FormSchema類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_read_parameterized_widget_default
def test_read_parameterized_widget_default(self):
from plone.autoform.widgets import ParameterizedWidget
param_node = etree.Element('klass')
param_node.text = 'custom'
param2_node = etree.Element('placeholder')
param2_node.text = 'help'
widget_node = etree.Element(ns('widget', self.namespace))
widget_node.append(param_node)
widget_node.append(param2_node)
field_node = etree.Element('field')
field_node.append(widget_node)
class IDummy(Interface):
foo = zope.schema.TextLine(title=u'foo')
handler = FormSchema()
handler.read(field_node, IDummy, IDummy['foo'])
widgets = IDummy.queryTaggedValue(WIDGETS_KEY)
self.assertTrue(isinstance(widgets['foo'], ParameterizedWidget))
self.assertTrue(widgets['foo'].widget_factory is None)
self.assertIn('klass', widgets['foo'].params)
self.assertEqual(widgets['foo'].params['klass'], 'custom')
self.assertIn('placeholder', widgets['foo'].params)
self.assertEqual(widgets['foo'].params['placeholder'], 'help')
示例2: test_read_multiple
def test_read_multiple(self):
field_node1 = ElementTree.Element('field')
field_node1.set(ns("widget", self.namespace), "z3c.form.browser.password.PasswordFieldWidget")
field_node1.set(ns("mode", self.namespace), "hidden")
field_node1.set(ns("omitted", self.namespace), "true")
field_node1.set(ns("before", self.namespace), "somefield")
field_node2 = ElementTree.Element('field')
field_node2.set(ns("mode", self.namespace), "display")
field_node2.set(ns("omitted", self.namespace), "yes")
class IDummy(Interface):
dummy1 = zope.schema.TextLine(title=u"dummy1")
dummy2 = zope.schema.TextLine(title=u"dummy2")
handler = FormSchema()
handler.read(field_node1, IDummy, IDummy['dummy1'])
handler.read(field_node2, IDummy, IDummy['dummy2'])
self.assertEquals({'dummy1': 'z3c.form.browser.password.PasswordFieldWidget'},
IDummy.getTaggedValue(WIDGETS_KEY))
self.assertEquals([(Interface, 'dummy1', 'true'), (Interface, 'dummy2', 'yes')],
IDummy.getTaggedValue(OMITTED_KEY))
self.assertEquals([(Interface, 'dummy1', 'hidden'), (Interface, 'dummy2', 'display')],
IDummy.getTaggedValue(MODES_KEY))
self.assertEquals([('dummy1', 'before', 'somefield',)], IDummy.getTaggedValue(ORDER_KEY))
示例3: test_write_no_data
def test_write_no_data(self):
field_node = etree.Element('field')
class IDummy(Interface):
dummy = zope.schema.TextLine(title=u'dummy1')
handler = FormSchema()
handler.write(field_node, IDummy, IDummy['dummy'])
self.assertEqual(None, field_node.find(ns('widget', self.namespace)))
self.assertEqual(None, field_node.get(ns('omitted', self.namespace)))
self.assertEqual(None, field_node.get(ns('mode', self.namespace)))
self.assertEqual(None, field_node.get(ns('before', self.namespace)))
示例4: test_read_no_data
def test_read_no_data(self):
field_node = etree.Element('field')
class IDummy(Interface):
dummy = zope.schema.TextLine(title=u'dummy1')
handler = FormSchema()
handler.read(field_node, IDummy, IDummy['dummy'])
self.assertEqual(None, IDummy.queryTaggedValue(WIDGETS_KEY))
self.assertEqual(None, IDummy.queryTaggedValue(OMITTED_KEY))
self.assertEqual(None, IDummy.queryTaggedValue(MODES_KEY))
self.assertEqual(None, IDummy.queryTaggedValue(ORDER_KEY))
示例5: test_write_no_data
def test_write_no_data(self):
field_node = ElementTree.Element('field')
class IDummy(Interface):
dummy = zope.schema.TextLine(title=u"dummy1")
handler = FormSchema()
handler.write(field_node, IDummy, IDummy['dummy'])
self.assertEquals(None, field_node.get(ns("widget", self.namespace)))
self.assertEquals(None, field_node.get(ns("omitted", self.namespace)))
self.assertEquals(None, field_node.get(ns("mode", self.namespace)))
self.assertEquals(None, field_node.get(ns("before", self.namespace)))
示例6: test_write_parameterized_widget_default
def test_write_parameterized_widget_default(self):
from plone.autoform.widgets import ParameterizedWidget
pw = ParameterizedWidget(None)
class IDummy(Interface):
dummy1 = zope.schema.Text(title=u'dummy1')
IDummy.setTaggedValue(WIDGETS_KEY, {'dummy1': pw})
fieldNode = etree.Element('field')
handler = FormSchema()
handler.write(fieldNode, IDummy, IDummy['dummy1'])
self.assertEquals(etree.tostring(fieldNode),
'<field/>')
示例7: test_read_values_with_interfaces
def test_read_values_with_interfaces(self):
field_node1 = etree.Element('field')
field_node1.set(
ns('mode', self.namespace),
'z3c.form.interfaces.IForm:hidden'
)
field_node1.set(
ns('omitted', self.namespace),
'z3c.form.interfaces.IForm:true'
)
field_node2 = etree.Element('field')
field_node2.set(
ns('mode', self.namespace),
'z3c.form.interfaces.IForm:hidden '
'z3c.form.interfaces.IEditForm:display'
)
field_node2.set(
ns('omitted', self.namespace),
'z3c.form.interfaces.IForm:true '
'z3c.form.interfaces.IEditForm:false'
)
class IDummy(Interface):
dummy1 = zope.schema.TextLine(title=u'dummy1')
dummy2 = zope.schema.TextLine(title=u'dummy2')
handler = FormSchema()
handler.read(field_node1, IDummy, IDummy['dummy1'])
handler.read(field_node2, IDummy, IDummy['dummy2'])
expected_modes = [
(IForm, u'dummy1', 'hidden'),
(IForm, u'dummy2', 'hidden'),
(IEditForm, u'dummy2', 'display')
]
self.assertEqual(
expected_modes,
IDummy.queryTaggedValue(MODES_KEY)
)
expected_omitted = [
(IForm, u'dummy1', 'true'),
(IForm, u'dummy2', 'true'),
(IEditForm, u'dummy2', 'false')
]
self.assertEqual(
expected_omitted,
IDummy.queryTaggedValue(OMITTED_KEY)
)
示例8: test_write_parameterized_widget_default_with_handler
def test_write_parameterized_widget_default_with_handler(self):
from plone.autoform.widgets import ParameterizedWidget
pw = ParameterizedWidget(None, klass='custom')
class IDummy(Interface):
dummy1 = zope.schema.Text(title=u'dummy1')
IDummy.setTaggedValue(WIDGETS_KEY, {'dummy1': pw})
fieldNode = etree.Element('field')
handler = FormSchema()
handler.write(fieldNode, IDummy, IDummy['dummy1'])
self.assertEquals(etree.tostring(fieldNode),
'<field><ns0:widget xmlns:ns0="http://namespaces.plone.org/supermodel/form">'
'<klass>custom</klass></ns0:widget></field>')
示例9: test_write_parameterized_widget_string
def test_write_parameterized_widget_string(self):
from plone.autoform.widgets import ParameterizedWidget
pw = ParameterizedWidget('foo')
class IDummy(Interface):
dummy1 = zope.schema.Text(title=u'dummy1')
IDummy.setTaggedValue(WIDGETS_KEY, {'dummy1': pw})
fieldNode = etree.Element('field')
handler = FormSchema()
handler.write(fieldNode, IDummy, IDummy['dummy1'])
self.assertEqual(
etree.tostring(fieldNode),
'<field><ns0:widget'
' xmlns:ns0="http://namespaces.plone.org/supermodel/form"'
' type="foo"/></field>'
)
示例10: test_write_partial
def test_write_partial(self):
field_node = ElementTree.Element('field')
class IDummy(Interface):
dummy = zope.schema.TextLine(title=u"dummy1")
IDummy.setTaggedValue(WIDGETS_KEY, {'dummy': 'SomeWidget'})
IDummy.setTaggedValue(OMITTED_KEY, [(Interface, 'dummy2', 'true')])
IDummy.setTaggedValue(MODES_KEY, [(Interface, 'dummy', 'display'), (Interface, 'dummy2', 'hidden')])
IDummy.setTaggedValue(ORDER_KEY, [])
handler = FormSchema()
handler.write(field_node, IDummy, IDummy['dummy'])
self.assertEquals("SomeWidget", field_node.get(ns("widget", self.namespace)))
self.assertEquals(None, field_node.get(ns("omitted", self.namespace)))
self.assertEquals("display", field_node.get(ns("mode", self.namespace)))
self.assertEquals(None, field_node.get(ns("before", self.namespace)))
示例11: test_write_values_with_interfaces
def test_write_values_with_interfaces(self):
field_node1 = etree.Element('field')
field_node2 = etree.Element('field')
class IDummy(Interface):
dummy1 = zope.schema.TextLine(title=u'dummy1')
dummy2 = zope.schema.TextLine(title=u'dummy2')
modes_values = [
(IForm, u'dummy1', 'hidden'),
(IForm, u'dummy2', 'hidden'),
(IEditForm, u'dummy2', 'display')
]
IDummy.setTaggedValue(MODES_KEY, modes_values)
omitted_values = [
(IForm, u'dummy1', 'true'),
(IForm, u'dummy2', 'true'),
(IEditForm, u'dummy2', 'false')
]
IDummy.setTaggedValue(OMITTED_KEY, omitted_values)
handler = FormSchema()
handler.write(field_node1, IDummy, IDummy['dummy1'])
handler.write(field_node2, IDummy, IDummy['dummy2'])
self.assertEqual(
'z3c.form.interfaces.IForm:hidden',
field_node1.get(ns('mode', self.namespace))
)
self.assertEqual(
'z3c.form.interfaces.IForm:true',
field_node1.get(ns('omitted', self.namespace))
)
self.assertEqual(
'z3c.form.interfaces.IForm:hidden '
'z3c.form.interfaces.IEditForm:display',
field_node2.get(ns('mode', self.namespace))
)
self.assertEqual(
'z3c.form.interfaces.IForm:true '
'z3c.form.interfaces.IEditForm:false',
field_node2.get(ns('omitted', self.namespace))
)
示例12: test_write
def test_write(self):
field_node = etree.Element('field')
class IDummy(Interface):
dummy = zope.schema.TextLine(title=u"dummy1")
IDummy.setTaggedValue(WIDGETS_KEY, {'dummy': 'SomeWidget'})
IDummy.setTaggedValue(OMITTED_KEY, [(Interface, 'dummy', 'true')])
IDummy.setTaggedValue(MODES_KEY, [(Interface, 'dummy', 'hidden')])
IDummy.setTaggedValue(ORDER_KEY, [('dummy', 'before', 'somefield',)])
handler = FormSchema()
handler.write(field_node, IDummy, IDummy['dummy'])
widget_node = field_node.find(ns('widget', self.namespace))
self.assertEquals("SomeWidget", widget_node.get('type'))
self.assertEquals("true", field_node.get(ns("omitted", self.namespace)))
self.assertEquals("hidden", field_node.get(ns("mode", self.namespace)))
self.assertEquals("somefield", field_node.get(ns("before", self.namespace)))
示例13: test_read
def test_read(self):
field_node = etree.Element('field')
field_node.set(
ns('widget', self.namespace),
'z3c.form.browser.password.PasswordFieldWidget'
)
field_node.set(ns('mode', self.namespace), 'hidden')
field_node.set(ns('omitted', self.namespace), 'true')
field_node.set(ns('before', self.namespace), 'somefield')
field_node.set(
ns('validator', self.namespace),
'plone.autoform.tests.test_utils.TestValidator'
)
class IDummy(Interface):
dummy = zope.schema.TextLine(title=u'dummy')
handler = FormSchema()
handler.read(field_node, IDummy, IDummy['dummy'])
self.assertEqual(
{'dummy': 'z3c.form.browser.password.PasswordFieldWidget'},
IDummy.getTaggedValue(WIDGETS_KEY)
)
self.assertEqual(
[(Interface, 'dummy', 'true')],
IDummy.getTaggedValue(OMITTED_KEY)
)
self.assertEqual(
[(Interface, 'dummy', 'hidden')],
IDummy.getTaggedValue(MODES_KEY)
)
self.assertEqual(
[('dummy', 'before', 'somefield',)],
IDummy.getTaggedValue(ORDER_KEY)
)
validator = getMultiAdapter(
(None, None, None, IDummy['dummy'], None),
IValidator
)
from plone.autoform.tests.test_utils import TestValidator
assert isinstance(validator, TestValidator)
示例14: test_read_multiple
def test_read_multiple(self):
field_node1 = etree.Element('field')
field_node1.set(
ns('widget', self.namespace),
'z3c.form.browser.password.PasswordFieldWidget'
)
field_node1.set(ns('mode', self.namespace), 'hidden')
field_node1.set(ns('omitted', self.namespace), 'true')
field_node1.set(ns('before', self.namespace), 'somefield')
field_node2 = etree.Element('field')
field_node2.set(ns('mode', self.namespace), 'display')
field_node2.set(ns('omitted', self.namespace), 'yes')
class IDummy(Interface):
dummy1 = zope.schema.TextLine(title=u'dummy1')
dummy2 = zope.schema.TextLine(title=u'dummy2')
handler = FormSchema()
handler.read(field_node1, IDummy, IDummy['dummy1'])
handler.read(field_node2, IDummy, IDummy['dummy2'])
self.assertEqual(
{'dummy1': 'z3c.form.browser.password.PasswordFieldWidget'},
IDummy.getTaggedValue(WIDGETS_KEY)
)
self.assertEqual(
[(Interface, 'dummy1', 'true'), (Interface, 'dummy2', 'yes')],
IDummy.getTaggedValue(OMITTED_KEY)
)
self.assertEqual(
[(Interface, 'dummy1', 'hidden'),
(Interface, 'dummy2', 'display')],
IDummy.getTaggedValue(MODES_KEY)
)
self.assertEqual(
[('dummy1', 'before', 'somefield',)],
IDummy.getTaggedValue(ORDER_KEY)
)
示例15: test_write_partial
def test_write_partial(self):
field_node = etree.Element('field')
class IDummy(Interface):
dummy = zope.schema.TextLine(title=u'dummy1')
IDummy.setTaggedValue(WIDGETS_KEY, {'dummy': 'SomeWidget'})
IDummy.setTaggedValue(OMITTED_KEY, [(Interface, 'dummy2', 'true')])
IDummy.setTaggedValue(
MODES_KEY,
[(Interface, 'dummy', 'display'), (Interface, 'dummy2', 'hidden')]
)
IDummy.setTaggedValue(ORDER_KEY, [])
handler = FormSchema()
handler.write(field_node, IDummy, IDummy['dummy'])
widget_node = field_node.find(ns('widget', self.namespace))
self.assertEqual('SomeWidget', widget_node.get('type'))
self.assertEqual(None, field_node.get(ns('omitted', self.namespace)))
self.assertEqual('display', field_node.get(ns('mode', self.namespace)))
self.assertEqual(None, field_node.get(ns('before', self.namespace)))