python类Field()的实例源码

forms.py 文件源码 项目:marvin 作者: sdss 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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
forms.py 文件源码 项目:plexivity 作者: mutschler 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
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')
forms.py 文件源码 项目:marvin 作者: sdss 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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
forms.py 文件源码 项目:marvin 作者: sdss 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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
test_wtforms.py 文件源码 项目:opwen-webapp 作者: ascoderu 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def create_field(self) -> Field:
            raise NotImplementedError


问题


面经


文章

微信
公众号

扫码关注公众号