#3 Added ability for images to be uploaded to the site
This commit is contained in:
@ -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'),
|
||||
|
Reference in New Issue
Block a user