#7 Added basic set of product orderings.
This commit is contained in:
@ -19,6 +19,33 @@ import os
|
||||
|
||||
blueprint = Blueprint("products", __name__, url_prefix="/products")
|
||||
|
||||
# List of available filters for the user to select
|
||||
FILTERS = {
|
||||
# ANY INFOMRATION PUT INTO THE VALUES HERE WILL BE INTERPRETED AS SQL!!!
|
||||
'Relevance': 'ORDER BY quantityAvailable DESC',
|
||||
'Price: High -> Low': 'ORDER BY cost DESC',
|
||||
'Price: Low -> High': 'ORDER BY cost'
|
||||
}
|
||||
|
||||
|
||||
@blueprint.context_processor
|
||||
def filter_list():
|
||||
""" Places a list of all the available filters in the
|
||||
products context
|
||||
"""
|
||||
return dict(filters=FILTERS)
|
||||
|
||||
|
||||
def get_filter():
|
||||
""" Return any filters that are currently active on the page """
|
||||
filter = request.args.get('filter')
|
||||
if filter is None:
|
||||
filter = 'Relevance'
|
||||
|
||||
if filter in FILTERS:
|
||||
return FILTERS[filter]
|
||||
return FILTERS['Relevance']
|
||||
|
||||
|
||||
@blueprint.context_processor
|
||||
def category_list():
|
||||
@ -44,9 +71,9 @@ 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:
|
||||
products = database.read_all(category, search_term)
|
||||
products = database.read_all(category, search_term, get_filter())
|
||||
else:
|
||||
products = database.read_all(category)
|
||||
products = database.read_all(category, "", get_filter())
|
||||
|
||||
# No Products visible
|
||||
if products is None:
|
||||
|
Reference in New Issue
Block a user