diff --git a/.gitignore b/.gitignore index af5171e..85263a3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ ### SQLite 3 Database ### data/ +static/assets/img/products/ ### CICD Registration files ### cicd/runner-data diff --git a/controllers/web/product.py b/controllers/web/product.py index 64f5d94..c68ea69 100644 --- a/controllers/web/product.py +++ b/controllers/web/product.py @@ -8,7 +8,10 @@ from controllers.database.category import CategoryController from controllers.database.user import UserController from datetime import datetime -from werkzeug import secure_filename +from werkzeug.utils import secure_filename +import os +import uuid +import pathlib ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'} @@ -101,18 +104,17 @@ def add_product(): file = request.files.get('image') # Ensure that the correct file type is uploaded - if file == None OR NOT allowed_file(file.filename): + if file == None or not allowed_file(file.filename): flash("Invalid File Uploaded") return redirect("/add") # Create the product object and push to database - filename = secure_filename(file.filename) - file.save(os.path.join('static/assets/img/products/', secure_filename)) - file.save + filename = str(uuid.uuid4()) + pathlib.Path(file.filename).suffix + file.save(os.path.join('static/assets/img/products/', filename)) product = Product( request.form.get('name'), - filename + filename, request.form.get('description'), request.form.get('cost'), request.form.get('category'), diff --git a/templates/content.html b/templates/content.html index 1b98811..680098e 100644 --- a/templates/content.html +++ b/templates/content.html @@ -7,7 +7,7 @@
{{product.name}}
- Brake Disks + Brake Disks
£{{product.cost}}
diff --git a/templates/new_product.html b/templates/new_product.html index ea2fa2e..59d8184 100644 --- a/templates/new_product.html +++ b/templates/new_product.html @@ -6,7 +6,7 @@