Exemplo n.º 1
0
def order_book(isbn13, customerid):
    form = AddOrderForm(request.form)
    if request.method == 'POST':
        order = Order.create(customer_id=customerid)
        flash('You, {}, have ordered a book!'.format(
               customerid), 'success')
        # order = Order.query.filter_by(customer_id=customerid)
        # order = order.first()
        OrderConsistsOf.create(consists_order_id=order.id, 
                               consists_isbn13=isbn13, consists_qty=form.qty.data)
        flash('You have ordered the book: {}!'.format(
                isbn13), 'success')
        return "Good job!"
    else:
        flash_errors(form)
    return render_template('orders/addorder.html', form=form)
Exemplo n.º 2
0
def order_book(isbn13):
    customerid = current_user.get_id()
    form = AddOrderForm(request.form)
    if request.method == 'POST':
        order = Order.create(customer_id=customerid)
        flash('You, {}, have ordered a book!'.format(customerid), 'success')
        # order = Order.query.filter_by(customer_id=customerid)
        # order = order.first()
        OrderConsistsOf.create(consists_order_id=order.id,
                               consists_isbn13=isbn13,
                               consists_qty=form.qty.data)
        flash('You have ordered the book: {}!'.format(isbn13), 'success')
        return redirect(url_for('book.browse'))
    else:
        flash_errors(form)

    RECOMMENDATIONS = []
    """Get book recommendation."""
    if current_user.is_authenticated:
        id = current_user.get_id()
        # get the book rec
        q1 = db.session.query(OrderConsistsOf.consists_order_id).filter(OrderConsistsOf.consists_isbn13 == isbn13).\
            filter(OrderConsistsOf.consists_order_id != id).all()

        for q in q1:
            isbn13_list = db.session.query(OrderConsistsOf.consists_isbn13).filter(OrderConsistsOf.consists_order_id == q[0]).\
                filter(OrderConsistsOf.consists_isbn13 != isbn13).all()
            if isbn13_list != []:
                for i in isbn13_list:
                    RECOMMENDATIONS.append(
                        db.session.query(Book).filter(
                            Book.isbn13 == i[0]).first())

    return render_template('orders/addorder.html',
                           form=form,
                           recommendations=RECOMMENDATIONS)