def process_quick_buy(id): if 'user_id' in session: logged_in_user = User.query.get(session['user_id']) items_of_user = logged_in_user.items_for_cart items_in_cart = len(items_of_user) if id == 9: # Grab the order id create_new_order = Order(fkey_order_user_id=session['user_id'], amount=25) db.session.add(create_new_order) db.session.commit() last_order = Order.query.order_by(desc('id')).first() # Appends the items to the order item = Item.query.get(9) last_order.items_for_orders.append(item) db.session.commit() return redirect("/user/receipt/"+str(last_order.id)) else: logged_in_user = User.query.get(session['user_id']) # Grab the order id create_new_order = Order(fkey_order_user_id=session['user_id'], amount=50) db.session.add(create_new_order) db.session.commit() last_order = Order.query.order_by(desc('id')).first() # Appends the items to the order item = Item.query.get(10) last_order.items_for_orders.append(item) db.session.commit() return redirect("/user/receipt/"+str(last_order.id)) else: return render_template('page_not_found.html')
def books(): if 'user_id' in session: return render_template('books.html', book_list=Book.query.order_by(desc(Book.id)), user_list=User.query.all(), logged_in_user=User.query.get( session['user_id'])) else: return render_template('books.html', book_list=Book.query.order_by(desc(Book.id)))
def authors(): if 'user_id' in session: return render_template( 'authors.html', author_list=Author.query.order_by(desc(Author.id)), user_list=User.query.all(), logged_in_user=User.query.get(session['user_id'])) else: return render_template('authors.html', author_list=Author.query.order_by( desc(Author.id)))
def user_list(): if 'user_id' not in session: return render_template('page_not_found.html') logged_in_user = User.query.get(session['user_id']) user_list = User.query.order_by(desc(User.id)) item = Item.query.all() items_of_user = logged_in_user.items_for_cart items_in_cart = len(items_of_user) if logged_in_user.approval_id == 9: return render_template('users_list.html', logged_in_user=logged_in_user, user_list=user_list, items_in_cart=items_in_cart, items_of_user=items_of_user) else: return render_template('page_not_found.html', logged_in_user=logged_in_user, user_list=user_list, items_in_cart=items_in_cart, items_of_user=items_of_user)
def admin_tours_list(): if 'user_id' not in session: return render_template('page_not_found.html') else: logged_in_user = User.query.get(session['user_id']) if logged_in_user.approval_id == 9: items_of_user = logged_in_user.items_for_cart items_in_cart = len(items_of_user) tours = Tour.query.order_by(desc(Tour.id)) print('TOURS: ', tours) return render_template('admin_tours_list.html', logged_in_user=logged_in_user, tours=tours, items_in_cart=items_in_cart, items_of_user=items_of_user )
def process_checkout(): if 'user_id' in session: logged_in_user = User.query.get(session['user_id']) # Grab the order id create_new_order = Order(fkey_order_user_id=session['user_id']) db.session.add(create_new_order) db.session.commit() last_order = Order.query.order_by(desc(Order.id)).all() # Appends the items to the order items_of_user = logged_in_user.items_for_cart for item in items_of_user: last_order.items_for_orders.append(item) db.session.commit() # Clears the Cart logged_in_user.items_for_cart.clear() logged_in_user.items_for_cart = [] db.session.commit() return redirect("user/receipt/"+last_order.id) else: return render_template('page_not_found.html')
def ideas_list(): if 'user_id' in session: logged_in_user = User.query.get(session['user_id']) ideas_list = Idea.query.order_by(desc(Idea.id)) ideas = Idea.query.join(User, Idea.user_id==User.id).add_columns(Idea.id, Idea.content, User.first_name, User.last_name, Idea.created_at, Idea.updated_at).order_by(desc(Idea.id)) user_ideas_list = Idea.query.join(User, User.id==Idea.user_id) current_idea = Idea.query.get(1) # for a in user_ideas_list: # print("USER_IDEAS_LIST: ", a.content) return render_template('partials/ideas_list.html', idea=current_idea, user_ideas_list=user_ideas_list, ideas_list=ideas, user_list=User.query.all(), logged_in_user=User.query.get(session['user_id']) ) else: flash('Register or login to view ideas!') return render_template('login_register.html')
def shopping_cart(): if 'user_id' in session: logged_in_user = User.query.get(session['user_id']) items = Item.query.join(User, Item.fkey_item_user_id == User.id).add_columns( Item.id, Item.name, Item.description, Item.img_url, Item.price, User.first_name, User.last_name, Item.created_at, Item.updated_at).order_by(desc(Item.id)) items_of_user = logged_in_user.items_for_cart items_in_cart = len(items_of_user) sum_items_in_cart = 0 for item in items_of_user: sum_items_in_cart += item.price return render_template('shopping_cart.html', items_of_user=items_of_user, items_in_cart=items_in_cart, logged_in_user=logged_in_user, items=items, sum_items_in_cart=sum_items_in_cart) else: return render_template('page_not_found.html')
def ideas(): if 'user_id' in session: logged_in_user=User.query.get(session['user_id']) ideas = Idea.query.order_by(desc(Idea.id)) user_ideas_list = Idea.query.join(User, User.id==Idea.user_id) current_idea = Idea.query.get(1) # for idea in ideas: # print(idea.user_id.liked_ideas) # liked_ideas = logged_in_user.liked_ideas # print(liked_ideas) # for a in user_ideas_list: # print("USER_IDEAS_LIST: ", a.content) return render_template('ideas.html', idea=current_idea, user_ideas_list=user_ideas_list, ideas_list=ideas, user_list=User.query.all(), logged_in_user=logged_in_user ) else: flash('Register or login to view ideas!') return render_template('login_register.html')
def admin_orders_list(): if 'user_id' not in session: return render_template('page_not_found.html') else: logged_in_user = User.query.get(session['user_id']) items_of_user = logged_in_user.items_for_cart items_in_cart = len(items_of_user) if logged_in_user.approval_id == 9: orders = Order.query.join(User, Order.fkey_order_user_id==User.id).add_columns(Order.id, Order.amount, User.first_name, User.last_name, Order.created_at, Order.updated_at).order_by(desc(Order.id)) # orders = Order.query.order_by(desc(Order.id)).all() print('ORDERS', orders) return render_template('admin_orders_list.html', logged_in_user=logged_in_user, items_in_cart=items_in_cart, items_of_user=items_of_user, orders=orders, )
def items(): items = Item.query.join(User, Item.fkey_item_user_id==User.id).add_columns(Item.id, Item.name, Item.description, Item.img_url, Item.price, User.first_name, User.last_name, Item.created_at, Item.updated_at).order_by(desc(Item.id)) if 'user_id' in session: logged_in_user = User.query.get(session['user_id']) items_of_user = logged_in_user.items_for_cart items_in_cart = len(items_of_user) return render_template('items_list.html', logged_in_user=logged_in_user, items=items, items_in_cart=items_in_cart, items_of_user=items_of_user) else: return render_template('items_list.html', items=items)
def admin_items_list(): if 'user_id' not in session: return render_template('page_not_found.html') else: logged_in_user = User.query.get(session['user_id']) items_of_user = logged_in_user.items_for_cart items_in_cart = len(items_of_user) if logged_in_user.approval_id == 9: itemList = Item.query.join(User, Item.fkey_item_user_id==User.id).add_columns(Item.id, Item.name, Item.description, Item.img_url, Item.price, User.first_name, User.last_name, Item.created_at, Item.updated_at).order_by(desc(Item.id)) # items = User.query.join(Item.fkey_item_user_id) # print('ITEMS: ', itemList) # for item in itemList: # print(item) return render_template('admin_items_list.html', logged_in_user=logged_in_user, items=itemList, items_of_user=items_of_user, items_in_cart=items_in_cart )
def quick_buy(): if 'user_id' in session: logged_in_user = User.query.get(session['user_id']) items = Item.query.join(User, Item.fkey_item_user_id==User.id).add_columns(Item.id, Item.name, Item.description, Item.img_url, Item.price, User.first_name, User.last_name, Item.created_at, Item.updated_at).order_by(desc(Item.id)) items_of_user = logged_in_user.items_for_cart items_in_cart = len(items_of_user) return render_template('quick_buy.html', logged_in_user=logged_in_user, items=items, items_in_cart=items_in_cart, items_of_user=items_of_user) else: # flash('Please sign-in or register to proceed!') return render_template('quick_buy.html')