#1 Allow searches to be made from the main page

This commit is contained in:
2024-01-22 10:49:08 +00:00
parent 216d71c15d
commit 897d4ab9aa
6 changed files with 24 additions and 34 deletions

View File

@ -3,9 +3,7 @@
categories and image processing.
"""
from flask import Blueprint
from flask import render_template, session, flash, request, redirect
from flask import render_template, session, flash, request, redirect, Blueprint
from models.products.product import Product
from controllers.database.product import ProductController
@ -13,23 +11,12 @@ from controllers.database.category import CategoryController
from controllers.database.user import UserController
from datetime import datetime
from werkzeug.utils import secure_filename
from utils.file_utils import allowed_file
import os
import uuid
import pathlib
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
def allowed_file(filename):
""" 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
blueprint = Blueprint("products", __name__, url_prefix="/products")
@ -44,17 +31,9 @@ def category_list():
@blueprint.route('/')
def index():
""" The front product page """
database = ProductController()
products = database.read_all()
# No Products visible
if products is None:
flash("No Products available")
return render_template('index.html',
content="content.html",
products=products
)
# Returning an empty category acts the same
# as a generic home page
return category("")
@blueprint.route('/<string:category>')
@ -65,14 +44,13 @@ def category(category: str):
# Check to see if there is a custome search term
search_term = request.args.get("search", type=str)
if search_term is not None:
print(f"Search Term {search_term}")
products = database.read_all(category, search_term)
else:
products = database.read_all(category)
# No Products visible
if products is None:
flash(f"No Products available in {category}")
flash(f"No Products available. Try expanding your search criteria.")
return render_template('index.html',
content="content.html",