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


Python validators.u函数代码示例

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


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

示例1: test_value_coercion

 def test_value_coercion(self):
     form = self.F(DummyPostData(b=[u('2')]))
     self.assertEqual(form.b.data, 2)
     self.assert_(form.b.validate(form))
     form = self.F(DummyPostData(b=[u('b')]))
     self.assertEqual(form.b.data, None)
     self.assert_(not form.b.validate(form))
开发者ID:webitup,项目名称:python3-wforms,代码行数:7,代码来源:fields.py

示例2: test_defaults

 def test_defaults(self):
     form = self.F()
     self.assertEqual(form.a.data, u('a'))
     self.assertEqual(form.b.data, None)
     self.assertEqual(form.validate(), False)
     self.assertEqual(form.a(), u("""<select id="a" name="a"><option selected="selected" value="a">hello</option><option value="btest">bye</option></select>"""))
     self.assertEqual(form.b(), u("""<select id="b" name="b"><option value="1">Item 1</option><option value="2">Item 2</option></select>"""))
开发者ID:webitup,项目名称:python3-wforms,代码行数:7,代码来源:fields.py

示例3: process_formdata

 def process_formdata(self, valuelist):
     if valuelist:
         try:
             lat, lon = valuelist[0].split(',')
             self.data = u('%s,%s') % (decimal.Decimal(lat.strip()), decimal.Decimal(lon.strip()),)
         except (decimal.InvalidOperation, ValueError):
             raise ValueError(u('Not a valid coordinate location'))
开发者ID:webitup,项目名称:python3-wforms,代码行数:7,代码来源:fields.py

示例4: test_defaults_display

 def test_defaults_display(self):
     f = self.F(a=datetime(2001, 11, 15))
     self.assertEqual(f.a.data, datetime(2001, 11, 15))
     self.assertEqual(f.a._value(), u('2001-11-15 00:00'))
     self.assertEqual(f.b.data, date(2004, 9, 12))
     self.assertEqual(f.b._value(), u('2004-09-12'))
     self.assertEqual(f.c.data, None)
     self.assert_(f.validate())
开发者ID:webitup,项目名称:python3-wforms,代码行数:8,代码来源:ext_dateutil.py

示例5: test

 def test(self):
     form = self.F()
     self.assertEqual(form.a.data, u('a'))
     self.assertEqual(form.b.data, None)
     self.assertEqual(form.validate(), False)
     self.assertEqual(form.a(), u("""<ul id="a"><li><input checked="checked" id="a-0" name="a" type="radio" value="a" /> <label for="a-0">hello</label></li><li><input id="a-1" name="a" type="radio" value="b" /> <label for="a-1">bye</label></li></ul>"""))
     self.assertEqual(form.b(), u("""<ul id="b"><li><input id="b-0" name="b" type="radio" value="1" /> <label for="b-0">Item 1</label></li><li><input id="b-1" name="b" type="radio" value="2" /> <label for="b-1">Item 2</label></li></ul>"""))
     self.assertEqual([unicode(x) for x in form.a], [u('<input checked="checked" id="a-0" name="a" type="radio" value="a" />'), u('<input id="a-1" name="a" type="radio" value="b" />')])
开发者ID:webitup,项目名称:python3-wforms,代码行数:8,代码来源:fields.py

示例6: __init__

    def __init__(self, label=u(''), validators=None, filters=tuple(),
                 description=u(''), id=None, default=None, widget=None,
                 _form=None, _name=None, _prefix='', _translations=None):
        """
        Construct a new field.

        :param label:
            The label of the field. Available after construction through the
            `label` property.
        :param validators:
            A sequence of validators to call when `validate` is called.
        :param filters:
            A sequence of filters which are run on input data by `process`.
        :param description:
            A description for the field, typically used for help text.
        :param id:
            An id to use for the field. A reasonable default is set by the form,
            and you shouldn't need to set this manually.
        :param default:
            The default value to assign to the field, if no form or object
            input is provided. May be a callable.
        :param widget:
            If provided, overrides the widget used to render the field.
        :param _form:
            The form holding this field. It is passed by the form itself during
            construction. You should never pass this value yourself.
        :param _name:
            The name of this field, passed by the enclosing form during its
            construction. You should never pass this value yourself.
        :param _prefix:
            The prefix to prepend to the form name of this field, passed by
            the enclosing form during construction.

        If `_form` and `_name` isn't provided, an :class:`UnboundField` will be
        returned instead. Call its :func:`bind` method with a form instance and
        a name to construct the field.
        """
        self.short_name = _name
        self.name = _prefix + _name
        if _translations is not None:
            self._translations = _translations
        self.id = id or self.name
        self.label = Label(self.id, label or _name.replace('_', ' ').title())
        if validators is None:
            validators = []
        self.validators = validators
        self.filters = filters
        self.description = description
        self.type = type(self).__name__
        self.default = default
        self.raw_data = None
        if widget:
            self.widget = widget
        self.flags = Flags()
        for v in validators:
            flags = getattr(v, 'field_flags', ())
            for f in flags:
                setattr(self.flags, f, True)
开发者ID:webitup,项目名称:python3-wforms,代码行数:58,代码来源:fields.py

示例7: test_single_default_value

 def test_single_default_value(self):
     first_test = self.sess.query(self.Test).get(2)
     class F(Form):
         a = QuerySelectMultipleField(get_label='name', default=[first_test],
             widget=LazySelect(), query_factory=lambda: self.sess.query(self.Test))
     form = F()
     self.assertEqual([v.id for v in form.a.data], [2])
     self.assertEqual(form.a(), [(u('1'), 'apple', False), (u('2'), 'banana', True)])
     self.assert_(form.validate())
开发者ID:webitup,项目名称:python3-wforms,代码行数:9,代码来源:ext_sqlalchemy.py

示例8: test

    def test(self):
        # ListWidget just expects an iterable of field-like objects as its
        # 'field' so that is what we will give it
        field = DummyField([DummyField(x, label='l' + x) for x in ['foo', 'bar']], id='hai')

        self.assertEqual(ListWidget()(field), u('<ul id="hai"><li>lfoo: foo</li><li>lbar: bar</li></ul>'))

        w = ListWidget(html_tag='ol', prefix_label=False)
        self.assertEqual(w(field), u('<ol id="hai"><li>foo lfoo</li><li>bar lbar</li></ol>'))
开发者ID:webitup,项目名称:python3-wforms,代码行数:9,代码来源:widgets.py

示例9: test_prefixes

 def test_prefixes(self):
     form = self.get_form(prefix='foo')
     self.assertEqual(form['test'].name, 'foo-test')
     self.assertEqual(form['test'].short_name, 'test')
     self.assertEqual(form['test'].id, 'foo-test')
     form = self.get_form(prefix='foo.')
     form.process(DummyPostData({'foo.test': [u('hello')], 'test': [u('bye')]}))
     self.assertEqual(form['test'].data, u('hello'))
     self.assertEqual(self.get_form(prefix='foo[')['test'].name, 'foo[-test')
开发者ID:webitup,项目名称:python3-wforms,代码行数:9,代码来源:form.py

示例10: test_quantize

 def test_quantize(self):
     F = make_form(a=DecimalField(places=3, rounding=ROUND_UP), b=DecimalField(places=None))
     form = F(a=Decimal('3.1415926535'))
     self.assertEqual(form.a._value(), u('3.142'))
     form.a.rounding = ROUND_DOWN
     self.assertEqual(form.a._value(), u('3.141'))
     self.assertEqual(form.b._value(), u(''))
     form = F(a=3.14159265, b=72)
     self.assertEqual(form.a._value(), u('3.142'))
     self.assert_(isinstance(form.a.data, float))
     self.assertEqual(form.b._value(), u('72'))
开发者ID:webitup,项目名称:python3-wforms,代码行数:11,代码来源:fields.py

示例11: test_without_factory

 def test_without_factory(self):
     sess = self.Session()
     self._fill(sess)
     class F(Form):
         a = QuerySelectField(get_label='name', widget=LazySelect(), get_pk=lambda x: x.id)
     form = F(DummyPostData(a=['1']))
     form.a.query = sess.query(self.Test)
     self.assert_(form.a.data is not None)
     self.assertEqual(form.a.data.id, 1)
     self.assertEqual(form.a(), [(u('1'), 'apple', True), (u('2'), 'banana', False)])
     self.assert_(form.validate())
开发者ID:webitup,项目名称:python3-wforms,代码行数:11,代码来源:ext_sqlalchemy.py

示例12: test_multiple_values_without_query_factory

    def test_multiple_values_without_query_factory(self):
        form = self.F(DummyPostData(a=['1', '2']))
        form.a.query = self.sess.query(self.Test)
        self.assertEqual([1, 2], [v.id for v in form.a.data])
        self.assertEqual(form.a(), [(u('1'), 'apple', True), (u('2'), 'banana', True)])
        self.assert_(form.validate())

        form = self.F(DummyPostData(a=['1', '3']))
        form.a.query = self.sess.query(self.Test)
        self.assertEqual([x.id for x in form.a.data], [1])
        self.assert_(not form.validate())
开发者ID:webitup,项目名称:python3-wforms,代码行数:11,代码来源:ext_sqlalchemy.py

示例13: test_with_obj

 def test_with_obj(self):
     obj = AttrDict(a=AttrDict(a=u('mmm')))
     form = self.F1(obj=obj)
     self.assertEqual(form.a.form.a.data, u('mmm'))
     self.assertEqual(form.a.form.b.data, None)
     obj_inner = AttrDict(a=None, b='rawr')
     obj2 = AttrDict(a=obj_inner)
     form.populate_obj(obj2)
     self.assert_(obj2.a is obj_inner)
     self.assertEqual(obj_inner.a, u('mmm'))
     self.assertEqual(obj_inner.b, None)
开发者ID:webitup,项目名称:python3-wforms,代码行数:11,代码来源:fields.py

示例14: __init__

    def __init__(self, label=u(''), validators=None, reference_class=None,
                 label_attr=None, allow_blank=False, blank_text=u(''), **kwargs):
        super(ReferencePropertyField, self).__init__(label, validators,
                                                     **kwargs)
        self.label_attr = label_attr
        self.allow_blank = allow_blank
        self.blank_text = blank_text
        self._set_data(None)
        if reference_class is None:
            raise TypeError('Missing reference_class attribute in '
                             'ReferencePropertyField')

        self.query = reference_class.all()
开发者ID:webitup,项目名称:python3-wforms,代码行数:13,代码来源:fields.py

示例15: test_field_adding

 def test_field_adding(self):
     form = self.get_form()
     self.assertEqual(len(list(form)), 1)
     form['foo'] = TextField()
     self.assertEqual(len(list(form)), 2)
     form.process(DummyPostData(foo=[u('hello')]))
     self.assertEqual(form['foo'].data, u('hello'))
     form['test'] = IntegerField()
     self.assert_(isinstance(form['test'], IntegerField))
     self.assertEqual(len(list(form)), 2)
     self.assertRaises(AttributeError, getattr, form['test'], 'data')
     form.process(DummyPostData(test=[u('1')]))
     self.assertEqual(form['test'].data, 1)
     self.assertEqual(form['foo'].data, u(''))
开发者ID:webitup,项目名称:python3-wforms,代码行数:14,代码来源:form.py


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