Пример #1
0
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)
Пример #2
0
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)
Пример #3
0
    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
Пример #4
0
def new(plant):
    return resource.render_html(plant=plant, form=form_factory(plant))
Пример #5
0
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)
Пример #6
0
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))
Пример #7
0
def new():
    genus = Genus()
    return resource.render_html(genus=genus, form=form_factory(genus))
Пример #8
0
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)
Пример #9
0
def edit(id):
    genus = Genus.query.get_or_404(id)
    return resource.render_html(genus=genus, form=form_factory(genus))
Пример #10
0
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)
Пример #11
0
def edit(id):
    family = Family.query.get_or_404(id)
    return resource.render_html(family=family, form=form_factory(family))
Пример #12
0
def new():
    family = Family()
    return resource.render_html(family=family, form=form_factory(family))
Пример #13
0
def edit(id):
    family = Family.query.get_or_404(id)
    return resource.render_html(family=family, form=form_factory(family))
Пример #14
0
def new():
    family = Family()
    return resource.render_html(family=family, form=form_factory(family))
Пример #15
0
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))
Пример #16
0
def new():
    genus = Genus()
    return resource.render_html(genus=genus, form=form_factory(genus))
Пример #17
0
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
Пример #18
0
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)
Пример #19
0
def new():
    accession = Accession()
    return resource.render_html(accession=accession, form=form_factory(accession))
Пример #20
0
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
Пример #21
0
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))
Пример #22
0
def edit(id):
    genus = Genus.query.get_or_404(id)
    return resource.render_html(genus=genus, form=form_factory(genus))
Пример #23
0
def new(location):
    return resource.render_html(location=location, form=form_factory(location))