Esempio n. 1
0
def add_author():
    form = AuthorForm(request.form)
    if request.method == 'POST' and form.validate():
        author = Author(form.name.data)
        db_session.add(author)
        db_session.commit()
        flash('The author was added to the Library.')
        return redirect(url_for('view_author', id=author.id))
    return render_template('library/add_author.html', form=form)
Esempio n. 2
0
def edit_author(id):
    error = None
    author = Author.query.get(id)
    if not author:
        error = 'Sorry, we don\'t have the author with id {0}.'.format(id)
    form = AuthorForm(request.form, obj=author)
    if request.method == 'POST' and form.validate():
        form.populate_obj(author)
        db_session.add(author)
        db_session.commit()
        return redirect(url_for('view_author', id=author.id))
    return render_template('library/edit_author.html', form=form, author=author,
                           error=error)