Added correct documentation on the product controller... rest to follow
This commit is contained in:
parent
17cb908753
commit
066659c266
@ -1,3 +1,8 @@
|
|||||||
|
"""
|
||||||
|
Product related endpoints. Included contexts for principles such as
|
||||||
|
categories and image processing.
|
||||||
|
"""
|
||||||
|
|
||||||
from flask import Blueprint
|
from flask import Blueprint
|
||||||
|
|
||||||
from flask import render_template, session, flash, request, redirect
|
from flask import render_template, session, flash, request, redirect
|
||||||
@ -17,27 +22,28 @@ ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
|
|||||||
|
|
||||||
|
|
||||||
def allowed_file(filename):
|
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 \
|
return '.' in filename and \
|
||||||
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
||||||
|
|
||||||
|
|
||||||
blueprint = Blueprint("products", __name__, url_prefix="/products")
|
blueprint = Blueprint("products", __name__, url_prefix="/products")
|
||||||
|
|
||||||
# Global context to enable the categories to be accessed
|
|
||||||
# from any view
|
|
||||||
|
|
||||||
|
|
||||||
@blueprint.context_processor
|
@blueprint.context_processor
|
||||||
def category_list():
|
def category_list():
|
||||||
|
""" Places a list of all categories in the products context """
|
||||||
database = CategoryController()
|
database = CategoryController()
|
||||||
categories = database.read_all()
|
categories = database.read_all()
|
||||||
return dict(categories=categories)
|
return dict(categories=categories)
|
||||||
|
|
||||||
# Loads the front product page
|
|
||||||
|
|
||||||
|
|
||||||
@blueprint.route('/')
|
@blueprint.route('/')
|
||||||
def index():
|
def index():
|
||||||
|
""" The front product page """
|
||||||
database = ProductController()
|
database = ProductController()
|
||||||
products = database.read_all()
|
products = database.read_all()
|
||||||
|
|
||||||
@ -50,11 +56,10 @@ def index():
|
|||||||
products=products
|
products=products
|
||||||
)
|
)
|
||||||
|
|
||||||
# Loads a given product category page
|
|
||||||
|
|
||||||
|
|
||||||
@blueprint.route('/<string:category>')
|
@blueprint.route('/<string:category>')
|
||||||
def category(category: str):
|
def category(category: str):
|
||||||
|
""" Loads a given categories page """
|
||||||
database = ProductController()
|
database = ProductController()
|
||||||
|
|
||||||
# Check to see if there is a custome search term
|
# Check to see if there is a custome search term
|
||||||
@ -75,17 +80,16 @@ def category(category: str):
|
|||||||
category=category
|
category=category
|
||||||
)
|
)
|
||||||
|
|
||||||
# Loads a given product based on ID
|
|
||||||
|
|
||||||
|
|
||||||
@blueprint.route('/<int:id>')
|
@blueprint.route('/<int:id>')
|
||||||
def id(id: int):
|
def id(id: int):
|
||||||
|
""" Loads a given product based on ID """
|
||||||
return "ID: " + str(id)
|
return "ID: " + str(id)
|
||||||
|
|
||||||
|
|
||||||
# Launches the page to add a new product to the site
|
|
||||||
@blueprint.route('/add')
|
@blueprint.route('/add')
|
||||||
def display_add_product():
|
def display_add_product():
|
||||||
|
""" Launches the page to add a new product to the site """
|
||||||
user_id = session.get('user_id')
|
user_id = session.get('user_id')
|
||||||
|
|
||||||
# User must be logged in to view this page
|
# User must be logged in to view this page
|
||||||
@ -102,9 +106,11 @@ def display_add_product():
|
|||||||
return render_template('index.html', content='new_product.html')
|
return render_template('index.html', content='new_product.html')
|
||||||
|
|
||||||
|
|
||||||
# Processes a request to add a new product to the site
|
|
||||||
@blueprint.post('/add')
|
@blueprint.post('/add')
|
||||||
def add_product():
|
def add_product():
|
||||||
|
""" Server site processing to handle a request to add a
|
||||||
|
new product to the site
|
||||||
|
"""
|
||||||
user_id = session.get('user_id')
|
user_id = session.get('user_id')
|
||||||
|
|
||||||
# User must be logged in to view this page
|
# User must be logged in to view this page
|
||||||
|
Loading…
Reference in New Issue
Block a user