def create(): accession, errors = schema_factory(Accession).load(request.params) if errors: if request.prefers_json: return resource.render_json(errors, status=422) return resource.render_html(template_name='new.html.jinja', accession=accession, form=form_factory(accession)) db.session.add(accession) db.session.commit() if request.prefers_json: return resource.render_json(accession, status=201) return resource.render_html(template_name='edit.html.jinja', accession=accession, form=form_factory(accession), status=201)
def create(): plant, errors = schema_factory(Plant).load(request.params) if errors: if request.prefers_json: return resource.render_json(errors, status=422) return resource.render_html(template_name='new.html.jinja', plant=plant, form=form_factory(plant)) db.session.add(plant) db.session.commit() if request.prefers_json: return resource.render_json(plant, status=201) return resource.render_html(template_name='edit.html.jinja', plant=plant, form=form_factory(plant), status=201)
def save_request_params(self, model, form=None): # a flask_wtf.form will get populated from request.form by default # or request.json if the content type is json form = form_factory(model) if form is None else form if form.validate_on_submit(): form.populate_obj(model) # TODO: what happens if an exception is raised...could we have a # resource error handler....or a save_resource() that handles the commit # and transaction...we could probably go one step further and do the # validate on submit, populate and commit and handle error in one # function try: db.session.add(model) db.session.commit() except Exception as exc: db.session.rollback() form.errors['default'] = 'Could not save {}'.format(model.__class__.__name__.lower) current_app.logger.error(exc) return form
def new(plant): return resource.render_html(plant=plant, form=form_factory(plant))
def test_form(session, genus): from bauble.forms import form_factory, BaseModelForm session.add(genus) session.commit() form = form_factory(genus) assert isinstance(form, BaseModelForm)
def edit(id): location = Location.query.get_or_404(id) if request.prefers_json: return resource.render_json(location) return resource.render_html(location=location, form=form_factory(location))
def new(): genus = Genus() return resource.render_html(genus=genus, form=form_factory(genus))
def test_form(session, family): from bauble.forms import form_factory, BaseModelForm session.add(family) session.commit() form = form_factory(family) assert isinstance(form, BaseModelForm)
def edit(id): genus = Genus.query.get_or_404(id) return resource.render_html(genus=genus, form=form_factory(genus))
def test_form(session, vernacular_name): from bauble.forms import form_factory, BaseModelForm session.add(vernacular_name) session.commit() form = form_factory(vernacular_name) assert isinstance(form, BaseModelForm)
def edit(id): family = Family.query.get_or_404(id) return resource.render_html(family=family, form=form_factory(family))
def new(): family = Family() return resource.render_html(family=family, form=form_factory(family))
def edit(id): plant = Plant.query.get_or_404(id) if request.prefers_json: return resource.render_json(plant) return resource.render_html(plant=plant, form=form_factory(plant))
def test_form(session, plant): from bauble.forms import MarshmallowForm, form_factory session.add(plant) session.commit() form = form_factory(plant) assert form is not None
def new(): accession = Accession() return resource.render_html(accession=accession, form=form_factory(accession))
def edit(id): accession = Accession.query.get_or_404(id) if request.prefers_json: return resource.render_json(accession) return resource.render_html(accession=accession, form=form_factory(accession))
def new(location): return resource.render_html(location=location, form=form_factory(location))