#6 Added Database functionality for user to click and load a single item
This commit is contained in:
parent
1f518ff56d
commit
95768f8a8c
@ -55,6 +55,26 @@ class ProductController(DatabaseController):
|
|||||||
|
|
||||||
return products
|
return products
|
||||||
|
|
||||||
|
def read_id(self, id: int) -> Product | None:
|
||||||
|
params = [
|
||||||
|
id
|
||||||
|
]
|
||||||
|
|
||||||
|
cursor = self._conn.execute(
|
||||||
|
"SELECT * FROM Products WHERE id == ?",
|
||||||
|
params
|
||||||
|
)
|
||||||
|
row = cursor.fetchone()
|
||||||
|
|
||||||
|
if row is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Create an object with the row
|
||||||
|
params = dict(zip(self.FIELDS, row))
|
||||||
|
obj = self.new_instance(Product, params)
|
||||||
|
|
||||||
|
return obj
|
||||||
|
|
||||||
def read_all(self, category: str = "",
|
def read_all(self, category: str = "",
|
||||||
search_term: str = "") -> list[Product] | None:
|
search_term: str = "") -> list[Product] | None:
|
||||||
params = [
|
params = [
|
||||||
|
@ -64,6 +64,16 @@ def category(category: str):
|
|||||||
@blueprint.route('/<int:id>')
|
@blueprint.route('/<int:id>')
|
||||||
def id(id: int):
|
def id(id: int):
|
||||||
""" Loads a given product based on ID """
|
""" Loads a given product based on ID """
|
||||||
|
db = ProductController()
|
||||||
|
product = db.read_id(id)
|
||||||
|
|
||||||
|
# Check that a valid product was returned
|
||||||
|
if product is None:
|
||||||
|
flash("No Product available here")
|
||||||
|
return redirect("/")
|
||||||
|
|
||||||
|
print(product.name)
|
||||||
|
return render_template('index.html', content='content.html', products = [product])
|
||||||
return "ID: " + str(id)
|
return "ID: " + str(id)
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ html {
|
|||||||
background-color: var(--bg);
|
background-color: var(--bg);
|
||||||
color: var(--fg);
|
color: var(--fg);
|
||||||
font-size: 160%;
|
font-size: 160%;
|
||||||
font-family: 'Courier New', Courier, monospace;
|
font-family: 'Courier New', Courier, 'Inter';
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,10 @@
|
|||||||
<link rel="stylesheet" href="{{url_for('static', filename='css/loginform.css')}}" />
|
<link rel="stylesheet" href="{{url_for('static', filename='css/loginform.css')}}" />
|
||||||
<link rel="stylesheet" href="{{url_for('static', filename='css/alerts.css')}}" />
|
<link rel="stylesheet" href="{{url_for('static', filename='css/alerts.css')}}" />
|
||||||
<link href="http://fonts.cdnfonts.com/css/uk-number-plate" rel="stylesheet">
|
<link href="http://fonts.cdnfonts.com/css/uk-number-plate" rel="stylesheet">
|
||||||
|
|
||||||
|
<!-- Inter font set used across the whole page -->
|
||||||
|
<link rel="preconnect" href="https://rsms.me/">
|
||||||
|
<link rel="stylesheet" href="https://rsms.me/inter/inter.css">
|
||||||
<title>WMGZON</title>
|
<title>WMGZON</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
Loading…
Reference in New Issue
Block a user