Exemple #1
0
def add_owner():
    form = OwnerForm(request.form)
    if form.validate():
        new_owner = Owner(request.form["first_name"],
                          request.form["last_name"])
        db.session.add(new_owner)
        db.session.commit()
        return redirect(url_for("owners.index"))
    return render_template("new.html", form=form)
Exemple #2
0
def edit_owner(id):
    found_owner = Owner.query.get(id)
    form = OwnerForm(request.form)
    if form.validate():
        found_owner.first_name = request.form["first_name"]
        found_owner.last_name = request.form["last_name"]
        db.session.add(found_owner)
        db.session.commit()
        return redirect(url_for("owners.index"))
    return render_template("edit.html", form=form, owner=found_owner)
Exemple #3
0
def index():
    if request.method == 'POST':
        form = OwnerForm()
        from IPython import embed
        embed()
        if form.validate():
            db.session.add(
                Owner(request.form['first_name'], request.form['last_name']))
            db.session.commit()
            return redirect(url_for('owners.index'))
        return render_template('owners/new.html', form=form)
    return render_template('owners/index.html', owners=Owner.query.all())
Exemple #4
0
def show(id):
    found_owner = Owner.query.get(id)
    if request.method == b'PATCH':
        form = OwnerForm(request.form)
        if form.validate():
            found_owner.first_name = request.form['first_name']
            found_owner.last_name = request.form['last_name']
            db.session.add(found_owner)
            db.session.commit()
            return redirect(url_for('owners.index'))
        return render_template('owners/edit.html',
                               form=form,
                               owner=found_owner)
    if request.method == b'DELETE':
        db.session.delete(found_owner)
        db.session.commit()
        return redirect(url_for('owners.index'))
    return render_template('owners/show.html', owner=found_owner)