Skip to content
Snippets Groups Projects
Commit 3c5711bd authored by Michael Drury's avatar Michael Drury
Browse files

added item not found functionality

parent b0fe9fa7
No related branches found
No related tags found
No related merge requests found
......@@ -98,11 +98,11 @@ def shopping():
# renders the shopping page
return render_template('shopping.html', product_table = products_pass, order_by_form = order_by_form, type_form = type_form)
# used to make lists for cart and wishlist
# creates a list for the current user and takes the string of ids which consists of the item
# ids of the items and splits up by spaces. It returns the item_list it adds the rows for the items that are in the
# current users cart as well as the id_list which is a list of ids
def make_lists(item_id_string):
id_list = item_id_string.split()
item_list = []
......@@ -113,11 +113,12 @@ def make_lists(item_id_string):
item_list.append(item)
return item_list, id_list
@app.route('/cart', methods=['GET', 'POST'])
@login_required
def cart():
# creates a cart list and a list of ids in cart using make_list
# creates a cart list and a list of ids in cart using make_lists
make_lists_out = make_lists(current_user.cart)
......@@ -169,11 +170,16 @@ def cart():
@login_required
def wishlist():
# creates a wishlist list and a list of ids in cart using make_lists
make_lists_out = make_lists(current_user.wishlist)
wishlist_list = make_lists_out[0]
wishlist_id_list = make_lists_out[1]
# performs the functionality of the remove from wishlist form. It does it in the same was as the cart does but have
# to repeat code as does it on different columns
remove_form = removeFormWishlist()
if remove_form.validate_on_submit():
remove_item_id = remove_form.item_id_remove.data
......@@ -196,31 +202,40 @@ def wishlist():
@app.route('/item', methods=['GET', 'POST'])
def item_page():
id = request.args.get('id', default='1', type=int)
all_products = product_table.query.all()
for product in all_products:
if product.product_id == id:
product_in = product
cartForm = addToCart()
if cartForm.validate_on_submit():
for c in db.session.query(User).filter_by(id = current_user.get_id()):
if cartForm.choice.data == 'Cart':
c.cart = c.cart + str(product_in.product_id) + ' '
else:
c.wishlist = c.wishlist + str(product_in.product_id) + ' '
db.session.commit()
review_form = reviewForm()
# gets the item id of the item that the link to the page gives and if no id is given it makes the id -1 so that it
# takes you to item not found page and if you enter an id that is invalid it will throw an error and so will take
# you to th except that also takes you to the file not found page
try:
id = request.args.get('id', default='-1', type=int)
all_products = product_table.query.all()
for product in all_products:
if product.product_id == id:
product_in = product
cartForm = addToCart()
if cartForm.validate_on_submit():
for c in db.session.query(User).filter_by(id = current_user.get_id()):
if cartForm.choice.data == 'Cart':
c.cart = c.cart + str(product_in.product_id) + ' '
else:
c.wishlist = c.wishlist + str(product_in.product_id) + ' '
db.session.commit()
review_form = reviewForm()
if review_form.validate_on_submit():
review_in = review_form.review.data
for c in db.session.query(User).filter_by(id=current_user.get_id()):
current_user_username = c.username
review_table.new_review(review_in=review_in, product_id_in=product_in.product_id, author_in = current_user_username)
if review_form.validate_on_submit():
review_in = review_form.review.data
for c in db.session.query(User).filter_by(id=current_user.get_id()):
current_user_username = c.username
review_table.new_review(review_in=review_in, product_id_in=product_in.product_id, author_in = current_user_username)
reviews = review_table.query.filter_by(product_id=product_in.product_id)
reviews = review_table.query.filter_by(product_id=product_in.product_id)
return render_template('item_page.html', product = product_in, cartForm = cartForm, reviewForm = review_form, reviews = reviews)
return render_template('item_page.html', product = product_in, cartForm = cartForm, reviewForm = review_form, reviews = reviews)
except:
return render_template('item_not_found.html')
@app.route('/checkout', methods=['GET', 'POST'])
......
{% extends "layout.html" %}
{% block page_content %}
<h1 class = "thank_you_text">Item Not Found</h1>
<footer id="footer">
<div class = "footer_logo_left_div">
<img class = "footer_logo_left" src = "{{ url_for('static', filename='images/dark_logo.png') }}" alt="logo image"/>
</div>
<div class = "footer_contact">
<p>Contact us:</p>
<p>e-mail: mpdrury15@gmail.com</p>
<p>telephone: 07874810762</p>
</div>
<div class = "footer_logo_right_div">
<img class = "footer_logo_right" src = "{{ url_for('static', filename='images/footer_mtb.png') }}" alt="mtb image"/>
</div>
</footer>
{% endblock %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment