本文整理汇总了Python中wtforms.compat.string_types方法的典型用法代码示例。如果您正苦于以下问题:Python compat.string_types方法的具体用法?Python compat.string_types怎么用?Python compat.string_types使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wtforms.compat
的用法示例。
在下文中一共展示了compat.string_types方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from wtforms import compat [as 别名]
# 或者: from wtforms.compat import string_types [as 别名]
def __init__(self, label=None, validators=None, query_factory=None,
get_pk=None, get_label=None, allow_blank=False,
blank_text='', **kwargs):
super(QuerySelectField, self).__init__(label, validators, **kwargs)
self.query_factory = query_factory
if get_pk is None:
if not has_identity_key:
raise Exception('The sqlalchemy identity_key function could not be imported.')
self.get_pk = get_pk_from_identity
else:
self.get_pk = get_pk
if get_label is None:
self.get_label = lambda x: x
elif isinstance(get_label, string_types):
self.get_label = operator.attrgetter(get_label)
else:
self.get_label = get_label
self.allow_blank = allow_blank
self.blank_text = blank_text
self.query = None
self._object_list = None
示例2: __init__
# 需要导入模块: from wtforms import compat [as 别名]
# 或者: from wtforms.compat import string_types [as 别名]
def __init__(self, label=None, validators=None, reference_class=None,
get_label=None, allow_blank=False,
blank_text='', **kwargs):
super(ReferencePropertyField, self).__init__(label, validators,
**kwargs)
if get_label is None:
self.get_label = lambda x: x
elif isinstance(get_label, string_types):
self.get_label = operator.attrgetter(get_label)
else:
self.get_label = get_label
self.allow_blank = allow_blank
self.blank_text = blank_text
self._set_data(None)
if reference_class is not None:
self.query = reference_class.all()
示例3: __call__
# 需要导入模块: from wtforms import compat [as 别名]
# 或者: from wtforms.compat import string_types [as 别名]
def __call__(self, form, field):
if isinstance(field.data, Model):
return
if isinstance(field.data, string_types) and UUID_REGEXP.search(field.data):
try:
obj = self.model.get(uuid=field.data)
except self.model.DoesNotExist:
raise ValidationError(self.message)
field.data = obj
return
try:
obj = self.model.get(id=field.data)
except self.model.DoesNotExist:
raise ValidationError(self.message)
field.data = obj
return
示例4: __init__
# 需要导入模块: from wtforms import compat [as 别名]
# 或者: from wtforms.compat import string_types [as 别名]
def __init__(self, label=None, validators=None, reference_class=None,
label_attr=None, get_label=None, allow_blank=False,
blank_text='', **kwargs):
super(ReferencePropertyField, self).__init__(label, validators,
**kwargs)
if label_attr is not None:
warnings.warn('label_attr= will be removed in WTForms 1.1, use get_label= instead.', DeprecationWarning)
self.get_label = operator.attrgetter(label_attr)
elif get_label is None:
self.get_label = lambda x: x
elif isinstance(get_label, string_types):
self.get_label = operator.attrgetter(get_label)
else:
self.get_label = get_label
self.allow_blank = allow_blank
self.blank_text = blank_text
self._set_data(None)
if reference_class is not None:
self.query = reference_class.all()
示例5: __call__
# 需要导入模块: from wtforms import compat [as 别名]
# 或者: from wtforms.compat import string_types [as 别名]
def __call__(self, form, field):
empty_form = True
for formfield in form:
has_raw_data = hasattr(formfield, 'raw_data')
is_empty = has_raw_data and len(formfield.raw_data) == 0
is_blank = has_raw_data and len(formfield.raw_data) >= 1 \
and isinstance(formfield.raw_data[0], string_types) and not formfield.raw_data[0]
# By default we'll receive empty arrays for values not posted, so need to allow empty lists
empty_field = True if is_empty else is_blank
empty_form &= empty_field
if empty_form:
raise validators.StopValidation()
示例6: __call__
# 需要导入模块: from wtforms import compat [as 别名]
# 或者: from wtforms.compat import string_types [as 别名]
def __call__(self, form, field):
if not field.raw_data or isinstance(field.raw_data[0], string_types) and not self.string_check(field.raw_data[0]):
field.errors[:] = []
raise StopValidation()
示例7: __init__
# 需要导入模块: from wtforms import compat [as 别名]
# 或者: from wtforms.compat import string_types [as 别名]
def __init__(self, regex, flags=0, message=None):
if isinstance(regex, string_types):
regex = re.compile(regex, flags)
self.regex = regex
self.message = message
示例8: convert_KeyProperty
# 需要导入模块: from wtforms import compat [as 别名]
# 或者: from wtforms.compat import string_types [as 别名]
def convert_KeyProperty(self, model, prop, kwargs):
"""Returns a form field for a ``ndb.KeyProperty``."""
if 'reference_class' not in kwargs:
try:
reference_class = prop._kind
except AttributeError:
reference_class = prop._reference_class
if isinstance(reference_class, string_types):
# reference class is a string, try to retrieve the model object.
mod = __import__(model.__module__, None, None, [reference_class], 0)
reference_class = getattr(mod, reference_class)
kwargs['reference_class'] = reference_class
kwargs.setdefault('allow_blank', not prop._required)
return KeyPropertyField(**kwargs)