def login(): """Login route.""" form = LoginForm(request.form) # Handle logging in if request.method == 'POST': if form.validate_on_submit(): login_user(form.user) flash('You are logged in.', 'success') redirect_url = request.args.get('next') or url_for('user.members') return redirect(redirect_url) else: flash_errors(form) return render_template('user/login.html', form=form)
def register(): """Register new user.""" form = RegisterForm(request.form, csrf_enabled=False) if form.validate_on_submit(): User.create(id=form.username.data, email=form.email.data, password=form.password.data, active=True) flash('Thank you for registering. You can now log in.', 'success') return redirect(url_for('public.home')) else: flash_errors(form) return render_template('user/register.html', form=form)
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)
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)