Python wtforms 模块,Field() 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用wtforms.Field()

项目:marvin    作者:sdss    | 项目源码 | 文件源码
def formClassFactory(name, model, baseclass):
    ''' Generates a new WTForm class based on SQLalchemy model class.  Each class contains as attributes
        Meta = a class called Meta.  Meta.model contains the SQLalchemy ModelClass
        data = a dictionary of parameters: form input that gets mapped to the sqlalchemy parameter
        errors = a dictionary of errors returned by invalid form validation
        validate = a method to validate all elements in this form
        parameter_X = a WTForm Field mapped to respective sqlalchemy table column

        e.g.
        The ModelClass IFUDesign mapped to mangadatadb.ifu_design sql table gets transformed into
        WTForm IFUDesignForm, with IFUDesignForm.Meta.model = marvin.db.models.DataModelClasses.IFUDesign
    '''

    Meta = type('Meta', (object,), {'model': model})
    newclass = type(name, (baseclass,), {'Meta': Meta})
    return newclass

# build a wtform select field for operators; tested but no longer used ; can't seem to attach operator field to every individual parameter
项目:plexivity    作者:mutschler    | 项目源码 | 文件源码
def valid_json_check(form, field):
    if type(field.data) != "dict":
        try:
            json_object = json.loads(field.data)
        except ValueError, e:
            raise ValidationError('Field must be valid JSON')
项目:marvin    作者:sdss    | 项目源码 | 文件源码
def _get_matches(self, keySplits):
        ''' Get the matches from a set of key splits '''
        matches = [path for path in self
                   if all([keySplits[-1 - ii] == path.split('.')[-1 - ii]
                           for ii in range(len(keySplits))])]
        return matches


# Custom [Better]TagList Field for Search Parameter Box
项目:marvin    作者:sdss    | 项目源码 | 文件源码
def __init__(self, opstring='[<>=]', message=None):
        self.opstring = opstring
        if not message:
            message = u'Field must contain at least a valid operand of {0}.'.format(self.opstring)
        self.message = message
项目:opwen-webapp    作者:ascoderu    | 项目源码 | 文件源码
def create_field(self) -> Field:
            raise NotImplementedError