#3 Added basic create product page
This commit is contained in:
parent
b2e32d720c
commit
b821050869
1
app.py
1
app.py
@ -15,7 +15,6 @@ def main():
|
||||
if secret_key == None:
|
||||
# NO Secret Key set!
|
||||
print("No app secret set, please set one before deploying in production")
|
||||
print("This is a test")
|
||||
app.secret_key = "DEFAULTKEY"
|
||||
else:
|
||||
app.secret_key = secret_key
|
||||
|
@ -24,7 +24,6 @@ def get_user() -> dict[User|None]:
|
||||
if user_id != None:
|
||||
db = UserController()
|
||||
user = db.read_id(user_id)
|
||||
print(user)
|
||||
|
||||
return dict(user=user)
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
from flask import Blueprint
|
||||
|
||||
from flask import render_template, session, flash, request
|
||||
from flask import render_template, session, flash, request, redirect
|
||||
from controllers.database.product import ProductController
|
||||
from controllers.database.category import CategoryController
|
||||
from controllers.database.user import UserController
|
||||
|
||||
blueprint = Blueprint("products", __name__, url_prefix="/products")
|
||||
|
||||
@ -50,3 +51,21 @@ def category(category: str):
|
||||
def id(id: int):
|
||||
return "ID: " + str(id)
|
||||
|
||||
|
||||
# Launches the page to add a new product to the site
|
||||
@blueprint.route('/add')
|
||||
def add_product():
|
||||
user_id = session.get('user_id')
|
||||
|
||||
# User must be logged in to view this page
|
||||
if user_id == None:
|
||||
flash("Please Login to view this page")
|
||||
return redirect('/login')
|
||||
|
||||
db = UserController()
|
||||
user = db.read_id(user_id)
|
||||
if user == None or user.role != "Seller":
|
||||
flash("You must be logged in as a Seller to view this page")
|
||||
return redirect('/')
|
||||
|
||||
return render_template('index.html', content='new_product.html')
|
||||
|
@ -86,5 +86,6 @@ def signup():
|
||||
# Function responsible for handling logouts from the site
|
||||
@blueprint.route('/logout')
|
||||
def logout():
|
||||
session.pop('user_id')
|
||||
# Clear the current user from the session if they are logged in
|
||||
session.pop('user_id', None)
|
||||
return redirect("/")
|
@ -39,4 +39,4 @@
|
||||
</label>
|
||||
{% endfor%}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
|
18
templates/new_product.html
Normal file
18
templates/new_product.html
Normal file
@ -0,0 +1,18 @@
|
||||
<div id="login-form-wrap">
|
||||
<h2>Sign Up</h2>
|
||||
<form class="login-form" method="POST">
|
||||
<input type="text" id="name" name="name" placeholder="Product Name" required>
|
||||
<input type="textarea" id="description" name="description" placeholder="Product Description" required>
|
||||
<input type="file" id="image" name="image" required>
|
||||
<select name="category" id="category">
|
||||
{% for category in categories %}
|
||||
<option value="{{category.name}}">{{category.name}}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<input type="submit" id="Sign Up" value="Sign Up">
|
||||
</form>
|
||||
|
||||
<div id="create-account-wrap">
|
||||
<p>Already have an account? <a href="login">Login</a><p>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user