Updated line endings to be in line with UNIX style

This commit is contained in:
2024-01-28 11:59:04 +00:00
parent 3eea1d946a
commit 5a20a8d7c0
46 changed files with 2536 additions and 2536 deletions

View File

@ -1,46 +1,46 @@
import os
import uuid
import pathlib
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
def allowed_file(filename) -> bool:
""" Ensures only filenames ending with the correct extension are allowed.
Note: This does not verify that the content inside of the file
matches the type specified
"""
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
def save_image(file) -> str | None:
""" Saves a given file to disk with a random UUID4 generated
filename. Returns the filename as a string.
"""
# Ensure that the correct file type is uploaded
if file is None or not allowed_file(file.filename):
return None
# Create the product object and push to database
filename = str(uuid.uuid4()) + pathlib.Path(file.filename).suffix
path = os.environ.get('FILESTORE')
file.save(os.path.join(path, filename))
return filename
def create_directory(dir: str):
""" Creates the given directory string is not alreay made """
try:
os.makedirs(dir)
except FileExistsError:
pass
def remove_file(dir: str):
""" Removes a given file if it is present at the given dir """
try:
os.remove(dir)
except FileNotFoundError:
pass
import os
import uuid
import pathlib
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
def allowed_file(filename) -> bool:
""" Ensures only filenames ending with the correct extension are allowed.
Note: This does not verify that the content inside of the file
matches the type specified
"""
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
def save_image(file) -> str | None:
""" Saves a given file to disk with a random UUID4 generated
filename. Returns the filename as a string.
"""
# Ensure that the correct file type is uploaded
if file is None or not allowed_file(file.filename):
return None
# Create the product object and push to database
filename = str(uuid.uuid4()) + pathlib.Path(file.filename).suffix
path = os.environ.get('FILESTORE')
file.save(os.path.join(path, filename))
return filename
def create_directory(dir: str):
""" Creates the given directory string is not alreay made """
try:
os.makedirs(dir)
except FileExistsError:
pass
def remove_file(dir: str):
""" Removes a given file if it is present at the given dir """
try:
os.remove(dir)
except FileNotFoundError:
pass

View File

@ -1,26 +1,26 @@
from flask import session
from models.users.user import User
from controllers.database.user import UserController
def is_logged_in() -> User | None:
""" Returns the user object if the user is logged in
Otherwise returns a None type
"""
user_id = session.get('user_id')
if user_id is not None:
db = UserController()
return db.read_id(user_id)
return None
def is_role(role: str) -> bool:
""" Function that returns true if the user is logged in as"""
user = is_logged_in()
if user is not None:
return user.role == role
# User isn't logged in
return False
from flask import session
from models.users.user import User
from controllers.database.user import UserController
def is_logged_in() -> User | None:
""" Returns the user object if the user is logged in
Otherwise returns a None type
"""
user_id = session.get('user_id')
if user_id is not None:
db = UserController()
return db.read_id(user_id)
return None
def is_role(role: str) -> bool:
""" Function that returns true if the user is logged in as"""
user = is_logged_in()
if user is not None:
return user.role == role
# User isn't logged in
return False