#1 Allow searches to be made from the main page
This commit is contained in:
parent
216d71c15d
commit
897d4ab9aa
@ -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",
|
||||
|
@ -27,14 +27,15 @@
|
||||
.alertText {
|
||||
display: table;
|
||||
margin: 0 auto;
|
||||
padding: 0 5px 0 0;
|
||||
text-align: center;
|
||||
font-size: 16px;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.alertClose {
|
||||
float: right;
|
||||
padding-top: 5px;
|
||||
font-size: 10px;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.clear {
|
||||
|
@ -1,7 +1,7 @@
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/products.css') }}">
|
||||
|
||||
<div class="product-container">
|
||||
{% if products is not None %}
|
||||
{% if products != None %}
|
||||
{% for product in products %}
|
||||
<a href="/products/{{product.id}}" class="product product-link">
|
||||
<div class="product-title">{{product.name}}</div>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<input type="text" name="search" placeholder="Find your favourite products" class="search-bar">
|
||||
<input type="submit" class="search-button">
|
||||
</form>
|
||||
{% if user is not None: %}
|
||||
{% if user != None: %}
|
||||
<a href="/logout">Welcome, {{ user.username }}</a>
|
||||
{% else %}
|
||||
<a href="/login">Login/Signup</a>
|
||||
@ -13,7 +13,7 @@
|
||||
</nav>
|
||||
|
||||
<centre>
|
||||
{% if user is not None and user.role == "Seller" %}
|
||||
{% if user != None and user.role == "Seller" %}
|
||||
<div class="categories">
|
||||
{# List all available seller tools #}
|
||||
<a href="/products/add" class="category">Create Products</a>
|
||||
|
0
utils/__init__.py
Normal file
0
utils/__init__.py
Normal file
11
utils/file_utils.py
Normal file
11
utils/file_utils.py
Normal file
@ -0,0 +1,11 @@
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user