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
评论列表
文章目录