当前位置: 首页>>代码示例>>Python>>正文


Python dx.SelectWidget类代码示例

本文整理汇总了Python中plone.app.widgets.dx.SelectWidget的典型用法代码示例。如果您正苦于以下问题:Python SelectWidget类的具体用法?Python SelectWidget怎么用?Python SelectWidget使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SelectWidget类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_data_converter_tuple

    def test_data_converter_tuple(self):
        from plone.app.widgets.dx import SelectWidget
        from plone.app.widgets.dx import SelectWidgetConverter

        field = Tuple(__name__='tuplefield',
                      value_type=Choice(__name__='selectfield',
                                        values=['one', 'two', 'three']))
        widget = SelectWidget(self.request)
        widget.field = field
        widget.multiple = True
        converter = SelectWidgetConverter(field, widget)

        self.assertEqual(
            converter.toFieldValue(''),
            field.missing_value,
        )

        self.assertEqual(
            converter.toFieldValue('one;two;three'),
            ('one', 'two', 'three'),
        )

        self.assertEqual(
            converter.toWidgetValue(tuple()),
            [],
        )

        self.assertEqual(
            converter.toWidgetValue(('one', 'two', 'three')),
            ['one', 'two', 'three'],
        )
开发者ID:hoka,项目名称:plone.app.widgets,代码行数:31,代码来源:test_dx.py

示例2: test_widget_set_not_orderable

 def test_widget_set_not_orderable(self):
     from plone.app.widgets.dx import SelectWidget
     widget = SelectWidget(self.request)
     # A set is not orderable
     widget.field = Set(
         __name__='selectfield',
         value_type=Choice(values=['one', 'two', 'three'])
     )
     widget.terms = widget.field.value_type.vocabulary
     self.assertEqual(
         {
             'multiple': True,
             'name': None,
             'pattern_options': {
                 'multiple': True, 'separator': ';'},
             'pattern': 'select2',
             'value': (),
             'items': [
                 ('one', 'one'),
                 ('two', 'two'),
                 ('three', 'three')
             ]
         },
         widget._base_args(),
     )
开发者ID:hoka,项目名称:plone.app.widgets,代码行数:25,代码来源:test_dx.py

示例3: test_widget

    def test_widget(self):
        from plone.app.widgets.dx import SelectWidget
        widget = SelectWidget(self.request)
        widget.field = Choice(
            __name__='selectfield',
            values=['one', 'two', 'three']
        )
        widget.terms = widget.field.vocabulary
        self.assertEqual(
            {
                'multiple': False,
                'name': None,
                'pattern_options': {},
                'pattern': 'select2',
                'value': (),
                'items': [
                    ('one', 'one'),
                    ('two', 'two'),
                    ('three', 'three')
                ]
            },
            widget._base_args(),
        )

        widget.multiple = True
        self.assertEqual(
            {
                'multiple': True,
                'name': None,
                'pattern_options': {'separator': ';', 'multiple': True},
                'pattern': 'select2',
                'value': (),
                'items': [
                    ('one', 'one'),
                    ('two', 'two'),
                    ('three', 'three')
                ]
            },
            widget._base_args(),
        )

        widget.value = 'one'
        self.assertEqual(
            {
                'multiple': True,
                'name': None,
                'pattern_options': {'separator': ';', 'multiple': True},
                'pattern': 'select2',
                'value': ('one'),
                'items': [
                    ('one', 'one'),
                    ('two', 'two'),
                    ('three', 'three')
                ]
            },
            widget._base_args(),
        )
开发者ID:hoka,项目名称:plone.app.widgets,代码行数:57,代码来源:test_dx.py

示例4: test_data_converter_list

    def test_data_converter_list(self):
        from plone.app.widgets.dx import SelectWidget
        from plone.app.widgets.dx import SelectWidgetConverter

        field = List(__name__='listfield',
                     value_type=Choice(__name__='selectfield',
                                       values=['one', 'two', 'three']))
        widget = SelectWidget(self.request)
        widget.field = field
        widget.multiple = True
        converter = SelectWidgetConverter(field, widget)

        self.assertEqual(
            converter.toFieldValue(''),
            field.missing_value,
        )

        self.assertEqual(
            converter.toFieldValue('one;two;three'),
            ['one', 'two', 'three'],
        )

        self.assertEqual(
            converter.toWidgetValue([]),
            [],
        )

        widget.separator = ','
        self.assertEqual(
            converter.toFieldValue('one,two,three'),
            ['one', 'two', 'three'],
        )
        self.assertRaises(
            LookupError,
            converter.toFieldValue, 'one;two;three'
        )

        self.assertEqual(
            converter.toWidgetValue(['one', 'two', 'three']),
            ['one', 'two', 'three']
        )
开发者ID:hoka,项目名称:plone.app.widgets,代码行数:41,代码来源:test_dx.py

示例5: test_select

    def test_select(self):
        from plone.app.widgets.dx import SelectWidget
        request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'},
                              example='example-value')
        widget = SelectWidget(request)
        widget.name = 'example'
        widget.field = TextLine(__name__='selectfield')
        widget.field.vocabulary = SimpleVocabulary.fromValues(
            ['option1', 'option2', 'option3'])
        self.assertEqual(
            widget._widget_args(),
            {
                'name': 'example',
                'pattern': 'select2',
                'pattern_options': {},
                'options': [('option1', None),
                            ('option2', None),
                            ('option3', None)],

            },
        )
开发者ID:potzenheimer,项目名称:plone.app.widgets,代码行数:21,代码来源:test_dx.py

示例6: test_widget_extract

 def test_widget_extract(self):
     from plone.app.widgets.dx import SelectWidget
     widget = SelectWidget(self.request)
     widget.field = Choice(
         __name__='selectfield',
         values=['one', 'two', 'three']
     )
     widget.name = 'selectfield'
     self.request.form['selectfield'] = 'one'
     self.assertEquals(widget.extract(), ('one',))
     widget.multiple = True
     self.request.form['selectfield'] = 'one;two'
     self.assertEquals(widget.extract(), ('one;two', ))
开发者ID:hoka,项目名称:plone.app.widgets,代码行数:13,代码来源:test_dx.py


注:本文中的plone.app.widgets.dx.SelectWidget类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。