Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CM1102 shop
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michael Drury
CM1102 shop
Commits
3c5711bd
Commit
3c5711bd
authored
2 years ago
by
Michael Drury
Browse files
Options
Downloads
Patches
Plain Diff
added item not found functionality
parent
b0fe9fa7
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
shop/routes.py
+39
-24
39 additions, 24 deletions
shop/routes.py
shop/templates/item_not_found.html
+21
-0
21 additions, 0 deletions
shop/templates/item_not_found.html
with
60 additions
and
24 deletions
shop/routes.py
+
39
−
24
View file @
3c5711bd
...
...
@@ -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_list
s
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
)
re
views
=
review_table
.
query
.
filter_by
(
product
_id
=
product_in
.
product_id
)
re
turn
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
'
])
...
...
This diff is collapsed.
Click to expand it.
shop/templates/item_not_found.html
0 → 100644
+
21
−
0
View file @
3c5711bd
{% 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 %}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment