本文整理汇总了Python中wtforms.compat.iteritems方法的典型用法代码示例。如果您正苦于以下问题:Python compat.iteritems方法的具体用法?Python compat.iteritems怎么用?Python compat.iteritems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wtforms.compat
的用法示例。
在下文中一共展示了compat.iteritems方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate
# 需要导入模块: from wtforms import compat [as 别名]
# 或者: from wtforms.compat import iteritems [as 别名]
def validate(self, extra_validators=None):
"""
Validates the form by calling `validate` on each field.
:param extra_validators:
If provided, is a dict mapping field names to a sequence of
callables which will be passed as extra validators to the field's
`validate` method.
Returns `True` if no errors occur.
"""
self._errors = None
success = True
for name, field in iteritems(self._fields):
if extra_validators is not None and name in extra_validators:
extra = extra_validators[name]
else:
extra = tuple()
if not field.validate(self, extra):
success = False
return success
示例2: html_params
# 需要导入模块: from wtforms import compat [as 别名]
# 或者: from wtforms.compat import iteritems [as 别名]
def html_params(**kwargs):
"""
Generate HTML parameters from inputted keyword arguments.
The output value is sorted by the passed keys, to provide consistent output
each time this function is called with the same parameters. Because of the
frequent use of the normally reserved keywords `class` and `for`, suffixing
these with an underscore will allow them to be used.
>>> html_params(name='text1', id='f', class_='text') == 'class="text" id="f" name="text1"'
True
"""
params = []
for k,v in sorted(iteritems(kwargs)):
if k in ('class_', 'class__', 'for_'):
k = k[:-1]
if v is True:
params.append(k)
else:
params.append('%s="%s"' % (text_type(k), escape(text_type(v), quote=True)))
return ' '.join(params)
示例3: async_validate_extra
# 需要导入模块: from wtforms import compat [as 别名]
# 或者: from wtforms.compat import iteritems [as 别名]
def async_validate_extra(self, extra_validators=None):
"""
Validates the form by calling `async_validate` on each field.
:param extra_validators:
If provided, is a dict mapping field names to a sequence of
callables which will be passed as extra validators to the field's
`validate` method.
Returns `True` if no errors occur.
"""
self._errors = None
success = True
for name, field in iteritems(self._fields):
if extra_validators is not None and name in extra_validators:
extra = extra_validators[name]
else:
extra = tuple()
field_valid = yield field.async_validate(self, extra)
if not field_valid:
success = False
return success
示例4: __init__
# 需要导入模块: from wtforms import compat [as 别名]
# 或者: from wtforms.compat import iteritems [as 别名]
def __init__(self, extra_converters=None, simple_conversions=None):
converters = {}
if simple_conversions is None:
simple_conversions = self.DEFAULT_SIMPLE_CONVERSIONS
for field_type, django_fields in iteritems(simple_conversions):
converter = self.make_simple_converter(field_type)
for name in django_fields:
converters[name] = converter
if extra_converters:
converters.update(extra_converters)
super(ModelConverter, self).__init__(converters)
示例5: populate_obj
# 需要导入模块: from wtforms import compat [as 别名]
# 或者: from wtforms.compat import iteritems [as 别名]
def populate_obj(self, obj):
"""
Populates the attributes of the passed `obj` with data from the form's
fields.
:note: This is a destructive operation; Any attribute with the same name
as a field will be overridden. Use with caution.
"""
for name, field in iteritems(self._fields):
field.populate_obj(obj, name)
示例6: process
# 需要导入模块: from wtforms import compat [as 别名]
# 或者: from wtforms.compat import iteritems [as 别名]
def process(self, formdata=None, obj=None, data=None, **kwargs):
"""
Take form, object data, and keyword arg input and have the fields
process them.
:param formdata:
Used to pass data coming from the enduser, usually `request.POST` or
equivalent.
:param obj:
If `formdata` is empty or not provided, this object is checked for
attributes matching form field names, which will be used for field
values.
:param data:
If provided, must be a dictionary of data. This is only used if
`formdata` is empty or not provided and `obj` does not contain
an attribute named the same as the field.
:param `**kwargs`:
If `formdata` is empty or not provided and `obj` does not contain
an attribute named the same as a field, form will assign the value
of a matching keyword argument to the field, if one exists.
"""
formdata = self.meta.wrap_formdata(self, formdata)
if data is not None:
# XXX we want to eventually process 'data' as a new entity.
# Temporarily, this can simply be merged with kwargs.
kwargs = dict(data, **kwargs)
for name, field, in iteritems(self._fields):
if obj is not None and hasattr(obj, name):
field.process(formdata, getattr(obj, name))
elif name in kwargs:
field.process(formdata, kwargs[name])
else:
field.process(formdata)
示例7: errors
# 需要导入模块: from wtforms import compat [as 别名]
# 或者: from wtforms.compat import iteritems [as 别名]
def errors(self):
if self._errors is None:
self._errors = dict((name, f.errors) for name, f in iteritems(self._fields) if f.errors)
return self._errors
示例8: __init__
# 需要导入模块: from wtforms import compat [as 别名]
# 或者: from wtforms.compat import iteritems [as 别名]
def __init__(self, formdata=None, obj=None, prefix='', data=None, meta=None, **kwargs):
"""
:param formdata:
Used to pass data coming from the enduser, usually `request.POST` or
equivalent. formdata should be some sort of request-data wrapper which
can get multiple parameters from the form input, and values are unicode
strings, e.g. a Werkzeug/Django/WebOb MultiDict
:param obj:
If `formdata` is empty or not provided, this object is checked for
attributes matching form field names, which will be used for field
values.
:param prefix:
If provided, all fields will have their name prefixed with the
value.
:param data:
Accept a dictionary of data. This is only used if `formdata` and
`obj` are not present.
:param meta:
If provided, this is a dictionary of values to override attributes
on this form's meta instance.
:param `**kwargs`:
If `formdata` is empty or not provided and `obj` does not contain
an attribute named the same as a field, form will assign the value
of a matching keyword argument to the field, if one exists.
"""
meta_obj = self._wtforms_meta()
if meta is not None and isinstance(meta, dict):
meta_obj.update_values(meta)
super(Form, self).__init__(self._unbound_fields, meta=meta_obj, prefix=prefix)
for name, field in iteritems(self._fields):
# Set all the fields to attributes so that they obscure the class
# attributes with the same names.
setattr(self, name, field)
self.process(formdata, obj, data=data, **kwargs)
示例9: html_params
# 需要导入模块: from wtforms import compat [as 别名]
# 或者: from wtforms.compat import iteritems [as 别名]
def html_params(**kwargs):
"""
Generate HTML attribute syntax from inputted keyword arguments.
The output value is sorted by the passed keys, to provide consistent output
each time this function is called with the same parameters. Because of the
frequent use of the normally reserved keywords `class` and `for`, suffixing
these with an underscore will allow them to be used.
In order to facilitate the use of ``data-`` attributes, the first underscore
behind the ``data``-element is replaced with a hyphen.
>>> html_params(data_any_attribute='something')
'data-any_attribute="something"'
In addition, the values ``True`` and ``False`` are special:
* ``attr=True`` generates the HTML compact output of a boolean attribute,
e.g. ``checked=True`` will generate simply ``checked``
* ``attr=False`` will be ignored and generate no output.
>>> html_params(name='text1', id='f', class_='text')
'class="text" id="f" name="text1"'
>>> html_params(checked=True, readonly=False, name="text1", abc="hello")
'abc="hello" checked name="text1"'
"""
params = []
for k, v in sorted(iteritems(kwargs)):
if k in ('class_', 'class__', 'for_'):
k = k[:-1]
elif k.startswith('data_'):
k = k.replace('_', '-', 1)
if v is True:
params.append(k)
elif v is False:
pass
else:
params.append('%s="%s"' % (text_type(k), escape(text_type(v), quote=True)))
return ' '.join(params)
示例10: data
# 需要导入模块: from wtforms import compat [as 别名]
# 或者: from wtforms.compat import iteritems [as 别名]
def data(self):
return dict((name, f.data) for name, f in iteritems(self._fields))
示例11: __init__
# 需要导入模块: from wtforms import compat [as 别名]
# 或者: from wtforms.compat import iteritems [as 别名]
def __init__(self, fields, prefix=''):
"""
:param fields:
A dict or sequence of 2-tuples of partially-constructed fields.
:param prefix:
If provided, all fields will have their name prefixed with the
value.
"""
if prefix and prefix[-1] not in '-_;:/.':
prefix += '-'
self._prefix = prefix
self._errors = None
self._fields = {}
if hasattr(fields, 'iteritems'):
fields = fields.iteritems()
elif hasattr(fields, 'items'):
# Python 3.x
fields = fields.items()
translations = self._get_translations()
for name, unbound_field in fields:
field = unbound_field.bind(form=self, name=name, prefix=prefix, translations=translations)
self._fields[name] = field
示例12: process
# 需要导入模块: from wtforms import compat [as 别名]
# 或者: from wtforms.compat import iteritems [as 别名]
def process(self, formdata=None, obj=None, **kwargs):
"""
Take form, object data, and keyword arg input and have the fields
process them.
:param formdata:
Used to pass data coming from the enduser, usually `request.POST` or
equivalent.
:param obj:
If `formdata` is empty or not provided, this object is checked for
attributes matching form field names, which will be used for field
values.
:param `**kwargs`:
If `formdata` is empty or not provided and `obj` does not contain
an attribute named the same as a field, form will assign the value
of a matching keyword argument to the field, if one exists.
"""
if formdata is not None and not hasattr(formdata, 'getlist'):
if hasattr(formdata, 'getall'):
formdata = WebobInputWrapper(formdata)
else:
raise TypeError("formdata should be a multidict-type wrapper that supports the 'getlist' method")
for name, field, in iteritems(self._fields):
if obj is not None and hasattr(obj, name):
field.process(formdata, getattr(obj, name))
elif name in kwargs:
field.process(formdata, kwargs[name])
else:
field.process(formdata)
示例13: html_params
# 需要导入模块: from wtforms import compat [as 别名]
# 或者: from wtforms.compat import iteritems [as 别名]
def html_params(**kwargs):
"""
Generate HTML attribute syntax from inputted keyword arguments.
The output value is sorted by the passed keys, to provide consistent output
each time this function is called with the same parameters. Because of the
frequent use of the normally reserved keywords `class` and `for`, suffixing
these with an underscore will allow them to be used.
In addition, the values ``True`` and ``False`` are special:
* ``attr=True`` generates the HTML compact output of a boolean attribute,
e.g. ``checked=True`` will generate simply ``checked``
* ``attr=`False`` will be ignored and generate no output.
>>> html_params(name='text1', id='f', class_='text')
'class="text" id="f" name="text1"'
>>> html_params(checked=True, readonly=False, name="text1", abc="hello")
'abc="hello" checked name="text1"'
"""
params = []
for k, v in sorted(iteritems(kwargs)):
if k in ('class_', 'class__', 'for_'):
k = k[:-1]
elif k.startswith('data_'):
k = k.replace('_', '-', 1)
if v is True:
params.append(k)
elif v is False:
pass
else:
params.append('%s="%s"' % (text_type(k), escape(text_type(v), quote=True)))
return ' '.join(params)