def update_model(self, form, model): """ Update model from form. :param form: Form instance :param model: Model instance """ try: form.populate_obj(model) self.session.commit() return True except Exception, ex: flash(gettext('Failed to update model. %(error)s', error=str(ex)), 'error') return False
def create_model(self, form): """ Create model from form. :param form: Form instance """ try: model = self.model() form.populate_obj(model) self.session.add(model) self.session.commit() return True except Exception, ex: flash(gettext('Failed to create model. %(error)s', error=str(ex)), 'error') return False
def update_model(self, form, model): """ Update model from form. :param form: Form instance :param model: Model instance """ try: form.populate_obj(model) self.on_model_change(form, model) self.session.commit() except Exception, ex: flash(gettext('Failed to update model. %(error)s', error=str(ex)), 'error') logging.exception('Failed to update model') self.session.rollback() return False
def create_model(self, form): """ Create model from form. :param form: Form instance """ try: model = self.model() form.populate_obj(model) self.session.add(model) self.session.flush() self.on_model_change(form, model) self.session.commit() return True except Exception, ex: flash(gettext("Failed to create model. %(error)s", error=str(ex)), "error") return False
def create_model(self, form): """ Create model from form. :param form: Form instance """ try: model = self.model() form.populate_obj(model) self.session.add(model) self.on_model_change(form, model) self.session.commit() except Exception as ex: flash(gettext('Failed to create model. %(error)s', error=str(ex)), 'error') logging.exception('Failed to create model') self.session.rollback() return False else: self.after_model_change(form, model, True) return True