當前位置: 首頁>>代碼示例>>Python>>正文


Python fields.SelectField方法代碼示例

本文整理匯總了Python中wtforms.fields.SelectField方法的典型用法代碼示例。如果您正苦於以下問題:Python fields.SelectField方法的具體用法?Python fields.SelectField怎麽用?Python fields.SelectField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在wtforms.fields的用法示例。


在下文中一共展示了fields.SelectField方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: conv_Enum

# 需要導入模塊: from wtforms import fields [as 別名]
# 或者: from wtforms.fields import SelectField [as 別名]
def conv_Enum(self, column, field_args, **extra):
        if 'choices' not in field_args:
            field_args['choices'] = [(e, e) for e in column.type.enums]
        return f.SelectField(**field_args) 
開發者ID:jpush,項目名稱:jbox,代碼行數:6,代碼來源:orm.py

示例2: convert

# 需要導入模塊: from wtforms import fields [as 別名]
# 或者: from wtforms.fields import SelectField [as 別名]
def convert(self, model, field, field_args):
        kwargs = {
            'label': field.verbose_name,
            'description': field.help_text,
            'validators': [],
            'filters': [],
            'default': field.default,
        }
        if field_args:
            kwargs.update(field_args)

        if field.blank:
            kwargs['validators'].append(validators.Optional())
        if field.max_length is not None and field.max_length > 0:
            kwargs['validators'].append(validators.Length(max=field.max_length))

        ftype = type(field).__name__
        if field.choices:
            kwargs['choices'] = field.choices
            return f.SelectField(**kwargs)
        elif ftype in self.converters:
            return self.converters[ftype](model, field, kwargs)
        else:
            converter = getattr(self, 'conv_%s' % ftype, None)
            if converter is not None:
                return converter(model, field, kwargs) 
開發者ID:jpush,項目名稱:jbox,代碼行數:28,代碼來源:orm.py

示例3: conv_NullBooleanField

# 需要導入模塊: from wtforms import fields [as 別名]
# 或者: from wtforms.fields import SelectField [as 別名]
def conv_NullBooleanField(self, model, field, kwargs):
        from django.db.models.fields import NOT_PROVIDED

        def coerce_nullbool(value):
            d = {'None': None, None: None, 'True': True, 'False': False}
            if isinstance(value, NOT_PROVIDED):
                return None
            elif value in d:
                return d[value]
            else:
                return bool(int(value))

        choices = ((None, 'Unknown'), (True, 'Yes'), (False, 'No'))
        return f.SelectField(choices=choices, coerce=coerce_nullbool, **kwargs) 
開發者ID:jpush,項目名稱:jbox,代碼行數:16,代碼來源:orm.py

示例4: convert

# 需要導入模塊: from wtforms import fields [as 別名]
# 或者: from wtforms.fields import SelectField [as 別名]
def convert(self, model, prop, field_args):
        """
        Returns a form field for a single model property.

        :param model:
            The ``db.Model`` class that contains the property.
        :param prop:
            The model property: a ``db.Property`` instance.
        :param field_args:
            Optional keyword arguments to construct the field.
        """
        prop_type_name = type(prop).__name__
        kwargs = {
            'label': prop.name.replace('_', ' ').title(),
            'default': prop.default_value(),
            'validators': [],
        }
        if field_args:
            kwargs.update(field_args)

        if prop.required and prop_type_name not in self.NO_AUTO_REQUIRED:
            kwargs['validators'].append(validators.required())

        if prop.choices:
            # Use choices in a select field if it was not provided in field_args
            if 'choices' not in kwargs:
                kwargs['choices'] = [(v, v) for v in prop.choices]
            return f.SelectField(**kwargs)
        else:
            converter = self.converters.get(prop_type_name, None)
            if converter is not None:
                return converter(model, prop, kwargs) 
開發者ID:jpush,項目名稱:jbox,代碼行數:34,代碼來源:db.py

示例5: __init__

# 需要導入模塊: from wtforms import fields [as 別名]
# 或者: from wtforms.fields import SelectField [as 別名]
def __init__(self, label=None, validators=None, coerce=nullable_text,
                 **kwargs):
        # self._choices = kwargs.pop('choices')
        super(SelectField, self).__init__(label, validators, coerce, **kwargs) 
開發者ID:opendatateam,項目名稱:udata,代碼行數:6,代碼來源:fields.py

示例6: iter_choices

# 需要導入模塊: from wtforms import fields [as 別名]
# 或者: from wtforms.fields import SelectField [as 別名]
def iter_choices(self):
        localized_choices = [
            (value, _(label) if label else '', selected)
            for value, label, selected
            in super(SelectField, self).iter_choices()
        ]
        for value, label, selected in sorted(localized_choices,
                                             key=lambda c: c[1]):
            yield (value, label, selected) 
開發者ID:opendatateam,項目名稱:udata,代碼行數:11,代碼來源:fields.py

示例7: conv_Enum

# 需要導入模塊: from wtforms import fields [as 別名]
# 或者: from wtforms.fields import SelectField [as 別名]
def conv_Enum(self, column, field_args, **extra):
        field_args['choices'] = [(e, e) for e in column.type.enums]
        return f.SelectField(**field_args) 
開發者ID:google,項目名稱:googleapps-message-recall,代碼行數:5,代碼來源:orm.py

示例8: conv_NullBooleanField

# 需要導入模塊: from wtforms import fields [as 別名]
# 或者: from wtforms.fields import SelectField [as 別名]
def conv_NullBooleanField(self, model, field, kwargs):
        from django.db.models.fields import NOT_PROVIDED
        def coerce_nullbool(value):
            d = {'None': None, None: None, 'True': True, 'False': False}
            if isinstance(value, NOT_PROVIDED):
                return None
            elif value in d:
                return d[value]
            else:
                return bool(int(value))

        choices = ((None, 'Unknown'), (True, 'Yes'), (False, 'No'))
        return f.SelectField(choices=choices, coerce=coerce_nullbool, **kwargs) 
開發者ID:google,項目名稱:googleapps-message-recall,代碼行數:15,代碼來源:orm.py

示例9: convert

# 需要導入模塊: from wtforms import fields [as 別名]
# 或者: from wtforms.fields import SelectField [as 別名]
def convert(self, model, prop, field_args):
        """
        Returns a form field for a single model property.

        :param model:
            The ``db.Model`` class that contains the property.
        :param prop:
            The model property: a ``db.Property`` instance.
        :param field_args:
            Optional keyword arguments to construct the field.
        """

        prop_type_name = type(prop).__name__

        # Check for generic property
        if(prop_type_name == "GenericProperty"):
            # Try to get type from field args
            generic_type = field_args.get("type")
            if generic_type:
                prop_type_name = field_args.get("type")

            # If no type is found, the generic property uses string set in convert_GenericProperty

        kwargs = {
            'label': prop._code_name.replace('_', ' ').title(),
            'default': prop._default,
            'validators': [],
        }
        if field_args:
            kwargs.update(field_args)

        if prop._required and prop_type_name not in self.NO_AUTO_REQUIRED:
            kwargs['validators'].append(validators.required())

        if kwargs.get('choices', None):
            # Use choices in a select field.
            kwargs['choices'] = [(v, v) for v in kwargs.get('choices')]
            return f.SelectField(**kwargs)

        if prop._choices:
            # Use choices in a select field.
            kwargs['choices'] = [(v, v) for v in prop._choices]
            return f.SelectField(**kwargs)

        else:
            converter = self.converters.get(prop_type_name, None)
            if converter is not None:
                return converter(model, prop, kwargs)
            else:
                return self.fallback_converter(model, prop, kwargs) 
開發者ID:jpush,項目名稱:jbox,代碼行數:52,代碼來源:ndb.py

示例10: convert

# 需要導入模塊: from wtforms import fields [as 別名]
# 或者: from wtforms.fields import SelectField [as 別名]
def convert(self, model, prop, field_args):
        """
        Returns a form field for a single model property.

        :param model:
            The ``db.Model`` class that contains the property.
        :param prop:
            The model property: a ``db.Property`` instance.
        :param field_args:
            Optional keyword arguments to construct the field.
        """

        prop_type_name = type(prop).__name__

        #check for generic property
        if(prop_type_name == "GenericProperty"):
            #try to get type from field args
            generic_type = field_args.get("type")
            if generic_type:
                prop_type_name = field_args.get("type")
            #if no type is found, the generic property uses string set in convert_GenericProperty

        kwargs = {
            'label': prop._code_name.replace('_', ' ').title(),
            'default': prop._default,
            'validators': [],
        }
        if field_args:
            kwargs.update(field_args)

        if prop._required and prop_type_name not in self.NO_AUTO_REQUIRED:
            kwargs['validators'].append(validators.required())

        if kwargs.get('choices', None):
            # Use choices in a select field.
            kwargs['choices'] = [(v, v) for v in kwargs.get('choices')]
            return f.SelectField(**kwargs)

        if prop._choices:
            # Use choices in a select field.
            kwargs['choices'] = [(v, v) for v in prop._choices]
            return f.SelectField(**kwargs)

        else:
            converter = self.converters.get(prop_type_name, None)
            if converter is not None:
                return converter(model, prop, kwargs)
            else:
                return self.fallback_converter(model, prop, kwargs) 
開發者ID:google,項目名稱:googleapps-message-recall,代碼行數:51,代碼來源:ndb.py


注:本文中的wtforms.fields.SelectField方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。