Esempio n. 1
0
    def __init__(self, *args, **kwargs):
        ''' Initialize the obect.  On init, generates all the WTForms from the ModelClasses.

        _param_form_lookup = dictionary of all modelclass parameters of form {'SQLalchemy ModelClass parameter name': WTForm Class}
        '''

        self._release = kwargs.get('release', config.release)
        self._modelclasses = marvindb.buildUberClassDict(release=self._release)
        self._param_form_lookup = ParamFormLookupDict(**kwargs)
        self._param_fxn_lookup = ParamFxnLookupDict()
        self._paramtree = tree()
        self._generateFormClasses(self._modelclasses)
        self._generateFxns()
        self.SearchForm = SearchForm
        self._cleanParams(**kwargs)
Esempio n. 2
0
    def __init__(self, *args, **kwargs):
        ''' Initializes a Marvin Form

        Generates all the WTForms from the SQLAlchemy ModelClasses defined in the MaNGA DB.

        _param_form_lookup = dictionary of all modelclass parameters
        of form {'SQLalchemy ModelClass parameter name': WTForm Class}
        '''

        self._release = kwargs.get('release', config.release)
        self.verbose = kwargs.get('verbose', False)
        if marvindb:
            self._modelclasses = FuzzyDict(
                marvindb.buildUberClassDict(release=self._release))
            self._param_form_lookup = ParamFormLookupDict(**kwargs)
            self._param_fxn_lookup = ParamFxnLookupDict()
            self._paramtree = tree()
            self._generateFormClasses(self._modelclasses)
            self._generateFxns()
            self.SearchForm = SearchForm
            self._cleanParams(**kwargs)
Esempio n. 3
0
# Base form class
BaseModelForm = model_form_factory(Form)


class ModelForm(BaseModelForm):
    ''' sub class a new WTF ModelForm so it works with Flask-WTF in APP mode;
    for auto CSRF tokens...who knows...
    '''
    @classmethod
    def get_session(self):
        return marvindb.session


# Builds a dictionary for modelclasses with key ClassName and value SQLalchemy model class
modelclasses = marvindb.buildUberClassDict()


# Class factory
def formClassFactory(name, model, baseclass):
    ''' Generates a new WTForm Class based on SQLalchemy Model Class.

    Subclasses a base WTF Form class that also contains the SQLAlchemy
    Model Class information inside it.

    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