Example #1
0
def add():
    """ Add book form view """
    form = forms.BookForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            # store actual image in filesystem (not in db !)
            img_filename = images.save(request.files['image'])
            img_url = images.url(img_filename)

            new_book = Item(title=form.title.data,
                            author=form.author.data,
                            genre_id=form.genre.data.id,
                            description=form.description.data,
                            img_url=img_url,
                            owner=current_user.get_id(),
                            img_filename=img_filename)
            db.session.add(new_book)
            db.session.commit()
            return redirect(url_for('show_collection'))
        else:

            return render_template('add_form.html', form=form)

    elif request.method == 'GET':
        return render_template('add_form.html', form=form)
Example #2
0
def new_book():
    form = forms.BookForm()
    if form.validate_on_submit():
        flash('Great, you added a new book.', 'success')
        book = models.Book(
            title=form.title.data.strip(),
            status=form.status.data,
            user_id=g.user._get_current_object().id,
        )
        db.session.add(book)
        db.session.commit()
        return redirect(url_for('books_page', username=current_user.username))
    return render_template('create_book.html', form=form)
Example #3
0
def bookings():
    form = forms.BookForm()
    if form.validate_on_submit():
        # hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        # user = models.User(username=form.username.data, email=form.email.data, password=hashed_password)
        terminal = models.Terminal(username=form.username.data,
                                   trip_date=form.trip_date.data,
                                   destination=form.destination.data)

        db.session.add(terminal)
        db.session.commit()
        flash('Your booking has been saved', 'success')
        return redirect(url_for('home'))
    return render_template('bookings.html', title='Pick Up', form=form)
Example #4
0
def edit_book(id):
    book = models.Book.query.filter_by(id=id).first_or_404()
    form = forms.BookForm(obj=book)
    if book.user == current_user:
        if form.validate_on_submit():
            flash('Book Updated', 'Success')
            book.title = form.title.data
            book.status = form.status.data
            db.session.commit()

            return redirect(
                url_for('books_page', username=current_user.username))
        return render_template('create_book.html', form=form)
    else:
        abort(404)
Example #5
0
def add_book():
    if current_user.is_authenticated:
        bookform = forms.BookForm()
        if bookform.validate_on_submit():
            new_book = Book(title=bookform.title.data,
                            author=bookform.author.data,
                            rating=int(bookform.rating.data),
                            genre=(bookform.genre.data),
                            username=current_user.username,
                            review=(bookform.review.data))
            db.session.add(new_book)
            db.session.commit()
            flash('You successfully added a book', 'error')
            return redirect(
                url_for("user_books", _external=True, _scheme='http'))
        return render_template('add_book.html', template_form=bookform)
    else:
        flash('You have to be logged in to view this option', 'error')
        return render_template('index.html')