Skip to content
Snippets Groups Projects
Commit 983a20db authored by Ismael Shaukat-Lopez's avatar Ismael Shaukat-Lopez
Browse files

added basket

parent 5391bb07
Branches master
No related tags found
No related merge requests found
from flask import Flask, render_template from flask import Flask, render_template, request, redirect, url_for
import sqlite3
import uuid
app = Flask(__name__) app = Flask(__name__)
technologies = [ connect = sqlite3.connect("eShop_database.db")
{ "name": "AK-47", cursor = connect.cursor()
"price": "£120",
"description": "Russian manufactured rifle with a high fire rate and penetration. This absolute classic is popular amongst our regular customers and we are sure that you will fall in love with it too. 30 rounds per magazine and strong recoil. On the noisy side.", cursor.execute('''DROP TABLE Basket''')
"image_filename": "ak47.png", try:
"volume": "140dB"}, cursor.execute('''CREATE TABLE Items (id integer, name text, price text, description text, image_filename text, volume text)''')
cursor.execute('''INSERT INTO Items (id, name, price, description, image_filename, volume) VALUES (0, 'AK47', '£125', 'Russian manufactured rifle with a high fire rate and penetration. This absolute classic is popular amongst our regular customers and we are sure that you will fall in love with it too. 30 rounds per magazine and strong recoil. On the noisy side.', 'ak47.png', '140dB')''')
{ "name": "M4A4", cursor.execute('''INSERT INTO Items (id, name, price, description, image_filename, volume) VALUES (1, 'M4A4', '£110', 'Accurate rifle with a 70mm barrel and a telescoping stock.', 'm4a4.png', '130dB')''')
"price": "£100", cursor.execute('''INSERT INTO Items (id, name, price, description, image_filename, volume) VALUES (2, 'M4A1S', '£150', 'M4A4 silenced counterpart with less recoil but smaller magazine size.', 'm4a1s.png', '100dB')''')
"description": "Accurate rifle with a 70mm barrel and a telescoping stock", cursor.execute('''INSERT INTO Items (id, name, price, description, image_filename, volume) VALUES (3, 'SSG08', '£220', 'Lightweight sniper rifle with high accuracy and low recoil. 10 rounds per magazine', 'ssg08.png', '140dB')''')
"image_filename": "m4a4.png", except: pass
"volume": "130dB"}, try:
cursor.execute('''CREATE TABLE Basket (id text, AK47 integer, M4A4 integer, M4A1S integer, SSG08 integer)''')
{ "name": "M4A1-S", connect.commit()
"price": "£120", except: pass
"description": "M4A4 silenced counterpart with less recoil but smaller magazine size", global customerID
"image_filename": "m4a1s.png", customerID = str(uuid.uuid4())
"volume": "100dB"} cursor.execute('INSERT INTO Basket (id, AK47, M4A4, M4A1S, SSG08) VALUES (?, 0, 0, 0, 0)', (customerID,))
] connect.commit()
cursor.execute('''SELECT name, price, description, image_filename, volume FROM Items''')
rows = cursor.fetchall()
technologies = []
for row in rows:
current_technology = {
"name": row[0],
"price": row[1],
"description": row[2],
"image_filename": row[3],
"volume": row[4]
}
technologies.append(current_technology)
@app.route('/', methods=["GET", "POST"]) @app.route('/', methods=["GET", "POST"])
def galleryPage(): def galleryPage():
...@@ -30,5 +46,32 @@ def galleryPage(): ...@@ -30,5 +46,32 @@ def galleryPage():
def singleProductPage(techId): def singleProductPage(techId):
return render_template("SingleTech.html", technology = technologies[techId]) return render_template("SingleTech.html", technology = technologies[techId])
@app.route('/basketPage')
def basketPage():
connect = sqlite3.connect("eShop_database.db")
cursor = connect.cursor()
cursor.execute(f'SELECT * FROM Basket WHERE id = ?', (customerID,))
row = cursor.fetchone()
quantities = {
'AK-47': row[1],
'M4A4': row[2],
'M4A1-S': row[3],
'SSG 08': row[4]
}
return render_template("Basket.html", quantities=quantities)
@app.route('/update_basket', methods=['POST'])
def update_basket():
connect = sqlite3.connect("eShop_database.db")
cursor = connect.cursor()
quantity = int(request.form.get("quantity"))
itemName = request.form.get("itemName")
cursor.execute(f'SELECT {itemName} FROM Basket WHERE id = ?', (customerID,))
current_quantity = cursor.fetchone()[0]
new_quantity = current_quantity + quantity
cursor.execute(f'UPDATE Basket SET "{itemName}" = ? WHERE id = ?', (new_quantity, customerID))
connect.commit()
return redirect(url_for('galleryPage'))
if __name__ == '__main__': if __name__ == '__main__':
app.run(debug=True) app.run(debug=True)
...@@ -46,3 +46,19 @@ ul img { ...@@ -46,3 +46,19 @@ ul img {
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
margin-bottom: 10px; margin-bottom: 10px;
} }
.basket-button {
padding: 10px 20px; /* Adjust padding to change button size */
font-size: 16px; /* Adjust font size */
background-color: #4CAF50; /* Green background */
color: white; /* White text color */
border: none; /* Remove border */
border-radius: 5px; /* Rounded corners */
cursor: pointer; /* Change cursor to pointer on hover */
text-decoration: none; /* Remove underline */
transition: background-color 0.3s; /* Smooth transition on hover */
}
.basket-button:hover {
background-color: #45a049; /* Darker green on hover */
}
\ No newline at end of file
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 20px;
}
h1 {
text-align: center;
color: #333;
margin-bottom: 20px;
}
ul {
list-style-type: none;
padding: 0;
}
li {
margin-bottom: 10px;
}
.item {
display: flex;
align-items: center;
}
.item img {
width: 100px; /* Adjust image size */
height: auto;
margin-right: 10px;
}
.quantity {
font-weight: bold;
}
\ No newline at end of file
static/ssg08.png

102 KiB

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Shopping Basket</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/stylesheet3.css') }}">
<script>
function back() {
window.history.back();
}
</script>
</head>
<body>
<h1>Shopping Basket</h1>
<button onclick="back()">BACK</button>
<div class="basket-items">
<div class="basket-item">
<p>AK-47: {{ quantities.get('AK-47', 0) }}</p>
</div>
<div class="basket-item">
<p>M4A4: {{ quantities.get('M4A4', 0) }}</p>
</div>
<div class="basket-item">
<p>M4A1-S: {{ quantities.get('M4A1-S', 0) }}</p>
</div>
<div class="basket-item">
<p>SSG 08: {{ quantities.get('SSG 08', 0) }}</p>
</div>
</div>
</body>
</html>
\ No newline at end of file
...@@ -16,16 +16,22 @@ ...@@ -16,16 +16,22 @@
} }
return true; return true;
} }
function back() {
window.history.back();
}
</script> </script>
</head> </head>
<body> <body>
<h1>{{ technology.name }}</h1> <h1>{{ technology.name }}</h1>
<p><b>{{technology.price + " | " }}{{technology.volume}}</b></p> <p><b>{{technology.price + " | " }}{{technology.volume}}</b></p>
<p>{{ technology.description }}</p> <p>{{ technology.description }}</p>
<form action="/" method="POST" onsubmit="return testInput()"> <form action="/update_basket" method="POST" onsubmit="return testInput()">
<input type="hidden" name="itemName" value="{{ technology.name }}">
<label for="quantity">QUANTITY:</label> <label for="quantity">QUANTITY:</label>
<input type="text" id="quantity" name="quantity" size="2" required> <input type="text" id="quantity" name="quantity" size="1" required>
<input type="submit" value="Add To Basket"> <input type="submit" value="ADD TO BASKET">
<button onclick="back()">BACK</button>
</form> </form>
<img src="{{ url_for("static", filename=technology.image_filename) }}" alt="{{ technology.name }}"> <img src="{{ url_for("static", filename=technology.image_filename) }}" alt="{{ technology.name }}">
</body> </body>
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
</head> </head>
<body> <body>
<h1>THE COUNTER STRIKE ARMS SHOP</h1> <h1>THE COUNTER STRIKE ARMS SHOP</h1>
<a href="{{ url_for("basketPage") }}" size=30 class="basket-button">Go to Basket</a>
<ul> <ul>
{% for tech in technologies %} {% for tech in technologies %}
<a href="{{ url_for("singleProductPage", techId=loop.index0) }}">{{ tech.name+" ["+tech.price+"] "+" ["+tech.volume+"]" }} <a href="{{ url_for("singleProductPage", techId=loop.index0) }}">{{ tech.name+" ["+tech.price+"] "+" ["+tech.volume+"]" }}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment