1.started removal of CDNs.\n 2. Improved modular structure for all parts of project including database.
This commit is contained in:
0
routing/__init__.py
Normal file
0
routing/__init__.py
Normal file
BIN
routing/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
routing/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
routing/__pycache__/core.cpython-312.pyc
Normal file
BIN
routing/__pycache__/core.cpython-312.pyc
Normal file
Binary file not shown.
BIN
routing/__pycache__/legal.cpython-312.pyc
Normal file
BIN
routing/__pycache__/legal.cpython-312.pyc
Normal file
Binary file not shown.
BIN
routing/__pycache__/store.cpython-312.pyc
Normal file
BIN
routing/__pycache__/store.cpython-312.pyc
Normal file
Binary file not shown.
BIN
routing/__pycache__/store_product_category.cpython-312.pyc
Normal file
BIN
routing/__pycache__/store_product_category.cpython-312.pyc
Normal file
Binary file not shown.
BIN
routing/__pycache__/store_product_permutation.cpython-312.pyc
Normal file
BIN
routing/__pycache__/store_product_permutation.cpython-312.pyc
Normal file
Binary file not shown.
BIN
routing/__pycache__/store_stock_item.cpython-312.pyc
Normal file
BIN
routing/__pycache__/store_stock_item.cpython-312.pyc
Normal file
Binary file not shown.
BIN
routing/__pycache__/store_supplier.cpython-312.pyc
Normal file
BIN
routing/__pycache__/store_supplier.cpython-312.pyc
Normal file
Binary file not shown.
BIN
routing/__pycache__/user.cpython-312.pyc
Normal file
BIN
routing/__pycache__/user.cpython-312.pyc
Normal file
Binary file not shown.
90
routing/core.py
Normal file
90
routing/core.py
Normal file
@@ -0,0 +1,90 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: App Routing
|
||||
Feature: Core Routes
|
||||
|
||||
Description:
|
||||
Initializes the Flask application, sets the configuration based on the environment, and defines two routes (/ and /about) that render templates with the specified titles.
|
||||
"""
|
||||
|
||||
# IMPORTS
|
||||
# internal
|
||||
from forms import Form_Contact
|
||||
from models.model_view_admin_home import Model_View_Admin_Home
|
||||
from models.model_view_contact import Model_View_Contact
|
||||
from models.model_view_home import Model_View_Home
|
||||
from models.model_view_services import Model_View_Services
|
||||
import lib.argument_validation as av
|
||||
# external
|
||||
from flask import Flask, render_template, jsonify, request, render_template_string, send_from_directory, redirect, url_for, session, Blueprint, current_app
|
||||
from flask_mail import Mail, Message
|
||||
from extensions import db, oauth, mail
|
||||
from urllib.parse import quote_plus, urlencode
|
||||
from authlib.integrations.flask_client import OAuth
|
||||
from authlib.integrations.base_client import OAuthError
|
||||
from urllib.parse import quote, urlparse, parse_qs
|
||||
|
||||
|
||||
routes_core = Blueprint('routes_core', __name__)
|
||||
|
||||
|
||||
@routes_core.route(Model_View_Home.HASH_PAGE_HOME, methods=['GET'])
|
||||
def home():
|
||||
try:
|
||||
model = Model_View_Home()
|
||||
print('nips')
|
||||
html_body = render_template('_page_home.html', model = model)
|
||||
except Exception as e:
|
||||
return jsonify(error=str(e)), 403
|
||||
return html_body
|
||||
|
||||
@routes_core.route(Model_View_Contact.HASH_PAGE_CONTACT, methods=['GET'])
|
||||
def contact():
|
||||
try:
|
||||
form = Form_Contact()
|
||||
model = Model_View_Contact(form)
|
||||
html_body = render_template('_page_contact.html', model = model)
|
||||
except Exception as e:
|
||||
return jsonify(error=str(e)), 403
|
||||
return html_body
|
||||
|
||||
@routes_core.route(Model_View_Contact.HASH_PAGE_CONTACT, methods=['POST'])
|
||||
def contact_post():
|
||||
try:
|
||||
form = Form_Contact()
|
||||
if form.validate_on_submit():
|
||||
# Handle form submission
|
||||
email = form.email.data
|
||||
CC = form.CC.data # not in use
|
||||
name = form.name.data
|
||||
message = form.message.data
|
||||
# send email
|
||||
mailItem = Message("PARTS Website Contact Us Message", recipients=[current_app.config['MAIL_CONTACT_PUBLIC']])
|
||||
mailItem.body = f"Dear Lord Edward Middleton-Smith,\n\n{message}\n\nKind regards,\n{name}\n{email}"
|
||||
mail.send(mailItem)
|
||||
return "Submitted."
|
||||
return "Invalid. Failed to submit."
|
||||
# html_body = render_template('_page_contact.html', model = model)
|
||||
except Exception as e:
|
||||
return jsonify(error=str(e)), 403
|
||||
|
||||
@routes_core.route(Model_View_Services.HASH_PAGE_SERVICES, methods=['GET', 'POST'])
|
||||
def services():
|
||||
try:
|
||||
model = Model_View_Services()
|
||||
html_body = render_template('_page_services.html', model = model)
|
||||
except Exception as e:
|
||||
return jsonify(error=str(e)), 403
|
||||
return html_body
|
||||
|
||||
@routes_core.route(Model_View_Admin_Home.HASH_PAGE_ADMIN_HOME, methods=['GET', 'POST'])
|
||||
def admin_home():
|
||||
try:
|
||||
model = Model_View_Admin_Home()
|
||||
html_body = render_template('_page_admin_home.html', model = model)
|
||||
except Exception as e:
|
||||
return jsonify(error=str(e)), 403
|
||||
return html_body
|
||||
69
routing/legal.py
Normal file
69
routing/legal.py
Normal file
@@ -0,0 +1,69 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: App Routing
|
||||
Feature: Legal Routes
|
||||
|
||||
Description:
|
||||
Initializes the Flask application, sets the configuration based on the environment, and defines two routes (/ and /about) that render templates with the specified titles.
|
||||
"""
|
||||
|
||||
# IMPORTS
|
||||
# internal
|
||||
from models.model_view_home import Model_View_Home
|
||||
import lib.argument_validation as av
|
||||
# external
|
||||
from flask import Flask, render_template, jsonify, request, render_template_string, send_from_directory, redirect, url_for, session, Blueprint, current_app
|
||||
from extensions import db, oauth
|
||||
from urllib.parse import quote_plus, urlencode
|
||||
from authlib.integrations.flask_client import OAuth
|
||||
from authlib.integrations.base_client import OAuthError
|
||||
from urllib.parse import quote, urlparse, parse_qs
|
||||
|
||||
routes_legal = Blueprint('routes_legal', __name__)
|
||||
|
||||
|
||||
# snore
|
||||
@routes_legal.route('/license', methods=['GET'])
|
||||
def license():
|
||||
try:
|
||||
model = Model_View_Home()
|
||||
html_body = render_template('_page_license.html', model = model)
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
return html_body
|
||||
@routes_legal.route('/accessibility-statement', methods=['GET'])
|
||||
def accessibility_statement():
|
||||
try:
|
||||
model = Model_View_Home()
|
||||
html_body = render_template('_page_accessibility_statement.html', model = model)
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
return html_body
|
||||
@routes_legal.route('/accessibility-report', methods=['GET'])
|
||||
def accessibility_report():
|
||||
try:
|
||||
model = Model_View_Home()
|
||||
html_body = render_template('_page_accessibility_report.html', model = model)
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
return html_body
|
||||
@routes_legal.route('/retention-schedule', methods=['GET'])
|
||||
def retention_schedule():
|
||||
try:
|
||||
model = Model_View_Home()
|
||||
html_body = render_template('_page_retention_schedule.html', model = model)
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
return html_body
|
||||
@routes_legal.route('/privacy-notice', methods=['GET'])
|
||||
def privacy_notice():
|
||||
try:
|
||||
model = Model_View_Home()
|
||||
html_body = render_template('_page_privacy_notice.html', model = model)
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
return html_body
|
||||
|
||||
0
routing/store/__init__.py
Normal file
0
routing/store/__init__.py
Normal file
BIN
routing/store/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
routing/store/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
routing/store/__pycache__/product_category.cpython-312.pyc
Normal file
BIN
routing/store/__pycache__/product_category.cpython-312.pyc
Normal file
Binary file not shown.
BIN
routing/store/__pycache__/product_permutation.cpython-312.pyc
Normal file
BIN
routing/store/__pycache__/product_permutation.cpython-312.pyc
Normal file
Binary file not shown.
BIN
routing/store/__pycache__/stock_item.cpython-312.pyc
Normal file
BIN
routing/store/__pycache__/stock_item.cpython-312.pyc
Normal file
Binary file not shown.
BIN
routing/store/__pycache__/supplier.cpython-312.pyc
Normal file
BIN
routing/store/__pycache__/supplier.cpython-312.pyc
Normal file
Binary file not shown.
95
routing/store/product_category.py
Normal file
95
routing/store/product_category.py
Normal file
@@ -0,0 +1,95 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: App Routing
|
||||
Feature: Store Product Category Routes
|
||||
|
||||
Description:
|
||||
Initializes the Flask application, sets the configuration based on the environment, and defines two routes (/ and /about) that render templates with the specified titles.
|
||||
"""
|
||||
|
||||
# internal
|
||||
from business_objects.store.product import Product, Product_Filters, Product_Permutation
|
||||
from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters
|
||||
from forms import Form_Supplier, Form_Filters_Permutation, Form_Filters_Stock_Item
|
||||
from models.model_view_base import Model_View_Base
|
||||
from models.model_view_store import Model_View_Store
|
||||
from models.model_view_store_supplier import Model_View_Store_Supplier
|
||||
from models.model_view_store_product_category import Model_View_Store_Product_Category
|
||||
from models.model_view_store_product_permutation import Model_View_Store_Product_Permutation
|
||||
from models.model_view_store_stock_items import Model_View_Store_Stock_Items
|
||||
from helpers.helper_app import Helper_App
|
||||
import lib.argument_validation as av
|
||||
# external
|
||||
from flask import Flask, render_template, jsonify, request, render_template_string, send_from_directory, redirect, url_for, session, Blueprint, current_app
|
||||
from extensions import db, oauth
|
||||
from urllib.parse import quote_plus, urlencode
|
||||
from authlib.integrations.flask_client import OAuth
|
||||
from authlib.integrations.base_client import OAuthError
|
||||
from urllib.parse import quote, urlparse, parse_qs
|
||||
|
||||
|
||||
routes_store_product_category = Blueprint('routes_store_product_category', __name__)
|
||||
|
||||
|
||||
@routes_store_product_category.route('/store/categories', methods=['GET'])
|
||||
def category():
|
||||
# filters = Product_Filters.get_default()
|
||||
model = Model_View_Store_Product_Category()
|
||||
return render_template('_page_store_product_categories.html', model = model)
|
||||
|
||||
@routes_store_product_category.route('/store/category_filter', methods=['POST'])
|
||||
def category_filter():
|
||||
data = Helper_App.get_request_data(request)
|
||||
# form_filters = None
|
||||
try:
|
||||
"""
|
||||
form_filters = get_Form_Filters_Permutation(data)
|
||||
if not form_filters.validate_on_submit():
|
||||
return jsonify({'status': 'failure', 'Message': f'Form invalid.\n{form_filters.errors}'})
|
||||
# ToDo: manually validate category, product
|
||||
filters_form = Product_Filters.from_form(form_filters)
|
||||
"""
|
||||
model = Model_View_Store_Product_Category()
|
||||
return jsonify({'status': 'success', 'Success': True, 'data': model.category_list.to_list()})
|
||||
except Exception as e:
|
||||
return jsonify({'status': 'failure', 'Message': f'Bad data received by controller.\n{e}'})
|
||||
|
||||
"""
|
||||
def get_Form_Filters_Product_Category(data_request):
|
||||
data_form = data_request[Model_View_Store_Product_Permutation.KEY_FORM]
|
||||
form_filters = Form_Filters_Permutation(**data_form)
|
||||
form_filters.is_out_of_stock.data = av.input_bool(data_form['is_out_of_stock'], 'is_out_of_stock', 'permutations_post')
|
||||
return form_filters
|
||||
"""
|
||||
|
||||
@routes_store_product_category.route('/store/category_save', methods=['POST'])
|
||||
def category_save():
|
||||
data = Helper_App.get_request_data(request)
|
||||
# form_filters = None
|
||||
try:
|
||||
"""
|
||||
form_filters = get_Form_Filters_Permutation(data)
|
||||
if not form_filters.validate_on_submit():
|
||||
return jsonify({'status': 'failure', 'Message': f'Filters form invalid.\n{form_filters.errors}'})
|
||||
|
||||
# ToDo: manually validate category, product
|
||||
filters_form = Product_Filters.from_form(form_filters)
|
||||
"""
|
||||
|
||||
categories = data[Model_View_Store_Product_Permutation.FLAG_PRODUCT_CATEGORY]
|
||||
if len(categories) == 0:
|
||||
return jsonify({'status': 'failure', 'Message': f'No categories.'})
|
||||
objsCategory = []
|
||||
for category in categories:
|
||||
objsCategory.append(Product_Permutation.from_json(category))
|
||||
model_save = Model_View_Store_Product_Category() # filters_product=filters_form)
|
||||
model_save.save_categories(data.comment, objsCategory)
|
||||
|
||||
model_return = Model_View_Store_Product_Permutation() # filters_product=filters_form)
|
||||
return jsonify({'status': 'success', 'Success': True, 'data': model_return.category_list.to_list_rows_permutation()})
|
||||
except Exception as e:
|
||||
return jsonify({'status': 'failure', 'Message': f'Bad data received by controller.\n{e}'})
|
||||
|
||||
90
routing/store/product_permutation.py
Normal file
90
routing/store/product_permutation.py
Normal file
@@ -0,0 +1,90 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: App Routing
|
||||
Feature: Store Product Permutation Routes
|
||||
|
||||
Description:
|
||||
Initializes the Flask application, sets the configuration based on the environment, and defines two routes (/ and /about) that render templates with the specified titles.
|
||||
"""
|
||||
|
||||
|
||||
# internal
|
||||
from business_objects.store.product import Product, Product_Filters, Product_Permutation
|
||||
from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters
|
||||
from forms import Form_Supplier, Form_Filters_Permutation, Form_Filters_Stock_Item
|
||||
from models.model_view_base import Model_View_Base
|
||||
from models.model_view_store import Model_View_Store
|
||||
from models.model_view_store_supplier import Model_View_Store_Supplier
|
||||
from models.model_view_store_product_category import Model_View_Store_Product_Category
|
||||
from models.model_view_store_product_permutation import Model_View_Store_Product_Permutation
|
||||
from models.model_view_store_stock_items import Model_View_Store_Stock_Items
|
||||
from helpers.helper_app import Helper_App
|
||||
import lib.argument_validation as av
|
||||
# external
|
||||
from flask import Flask, render_template, jsonify, request, render_template_string, send_from_directory, redirect, url_for, session, Blueprint, current_app
|
||||
from extensions import db, oauth
|
||||
from urllib.parse import quote_plus, urlencode
|
||||
from authlib.integrations.flask_client import OAuth
|
||||
from authlib.integrations.base_client import OAuthError
|
||||
from urllib.parse import quote, urlparse, parse_qs
|
||||
|
||||
|
||||
routes_store_product_permutation = Blueprint('routes_store_product_permutation', __name__)
|
||||
|
||||
|
||||
@routes_store_product_permutation.route('/store/permutations', methods=['GET'])
|
||||
def permutation():
|
||||
filters = Product_Filters.get_default()
|
||||
model = Model_View_Store_Product_Permutation(filters_product=filters)
|
||||
return render_template('_page_store_product_permutations.html', model = model)
|
||||
|
||||
@routes_store_product_permutation.route('/store/permutation_filter', methods=['POST'])
|
||||
def permutation_filter():
|
||||
data = Helper_App.get_request_data(request)
|
||||
form_filters = None
|
||||
try:
|
||||
form_filters = get_Form_Filters_Permutation(data)
|
||||
if not form_filters.validate_on_submit():
|
||||
return jsonify({'status': 'failure', 'Message': f'Form invalid.\n{form_filters.errors}'})
|
||||
# ToDo: manually validate category, product
|
||||
filters_form = Product_Filters.from_form(form_filters)
|
||||
model = Model_View_Store_Product_Permutation(filters_product=filters_form)
|
||||
return jsonify({'status': 'success', 'Success': True, 'data': model.category_list.to_list_rows_permutation()})
|
||||
except Exception as e:
|
||||
return jsonify({'status': 'failure', 'Message': f'Bad data received by controller.\n{e}'})
|
||||
|
||||
def get_Form_Filters_Permutation(data_request):
|
||||
data_form = data_request[Model_View_Store_Product_Permutation.KEY_FORM]
|
||||
form_filters = Form_Filters_Permutation(**data_form)
|
||||
form_filters.is_out_of_stock.data = av.input_bool(data_form['is_out_of_stock'], 'is_out_of_stock', 'permutations_post')
|
||||
return form_filters
|
||||
|
||||
@routes_store_product_permutation.route('/store/permutation_save', methods=['POST'])
|
||||
def permutation_save():
|
||||
data = Helper_App.get_request_data(request)
|
||||
form_filters = None
|
||||
try:
|
||||
form_filters = get_Form_Filters_Permutation(data)
|
||||
if not form_filters.validate_on_submit():
|
||||
return jsonify({'status': 'failure', 'Message': f'Filters form invalid.\n{form_filters.errors}'})
|
||||
|
||||
permutations = data[Model_View_Store_Product_Permutation.KEY_PERMUTATIONS]
|
||||
if len(permutations) == 0:
|
||||
return jsonify({'status': 'failure', 'Message': f'No permutations.'})
|
||||
objsPermutation = []
|
||||
for permutation in permutations:
|
||||
objsPermutation.append(Product_Permutation.from_json(permutation))
|
||||
|
||||
# ToDo: manually validate category, product
|
||||
filters_form = Product_Filters.from_form(form_filters)
|
||||
model_save = Model_View_Store_Product_Permutation(filters_product=filters_form)
|
||||
model_save.save_permutations(data.comment, objsPermutation)
|
||||
|
||||
model_return = Model_View_Store_Product_Permutation(filters_product=filters_form)
|
||||
return jsonify({'status': 'success', 'Success': True, 'data': model_return.category_list.to_list_rows_permutation()})
|
||||
except Exception as e:
|
||||
return jsonify({'status': 'failure', 'Message': f'Bad data received by controller.\n{e}'})
|
||||
|
||||
92
routing/store/stock_item.py
Normal file
92
routing/store/stock_item.py
Normal file
@@ -0,0 +1,92 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: App Routing
|
||||
Feature: Store Stock Item Routes
|
||||
|
||||
Description:
|
||||
Initializes the Flask application, sets the configuration based on the environment, and defines two routes (/ and /about) that render templates with the specified titles.
|
||||
"""
|
||||
|
||||
# internal
|
||||
from business_objects.store.product import Product, Product_Filters, Product_Permutation
|
||||
from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters
|
||||
from forms import Form_Supplier, Form_Filters_Permutation, Form_Filters_Stock_Item
|
||||
from models.model_view_base import Model_View_Base
|
||||
from models.model_view_store import Model_View_Store
|
||||
from models.model_view_store_supplier import Model_View_Store_Supplier
|
||||
from models.model_view_store_product_category import Model_View_Store_Product_Category
|
||||
from models.model_view_store_product_permutation import Model_View_Store_Product_Permutation
|
||||
from models.model_view_store_stock_items import Model_View_Store_Stock_Items
|
||||
from helpers.helper_app import Helper_App
|
||||
import lib.argument_validation as av
|
||||
# external
|
||||
from flask import Flask, render_template, jsonify, request, render_template_string, send_from_directory, redirect, url_for, session, Blueprint, current_app
|
||||
from extensions import db, oauth
|
||||
from urllib.parse import quote_plus, urlencode
|
||||
from authlib.integrations.flask_client import OAuth
|
||||
from authlib.integrations.base_client import OAuthError
|
||||
from urllib.parse import quote, urlparse, parse_qs
|
||||
|
||||
|
||||
routes_store_stock_item = Blueprint('routes_store_stock_item', __name__)
|
||||
|
||||
|
||||
@routes_store_stock_item.route('/store/stock_items', methods=['GET'])
|
||||
def stock():
|
||||
filters = Stock_Item_Filters.get_default()
|
||||
model = Model_View_Store_Stock_Items(filters_stock_item=filters)
|
||||
return render_template('_page_store_stock_items.html', model = model)
|
||||
|
||||
@routes_store_stock_item.route('/store/stock_item_filter', methods=['POST'])
|
||||
def stock_filter():
|
||||
data = Helper_App.get_request_data(request)
|
||||
form_filters = None
|
||||
try:
|
||||
form_filters = get_form_filters_stock_items(data)
|
||||
if not form_filters.validate_on_submit():
|
||||
return jsonify({'status': 'failure', 'Message': f'Form invalid.\n{form_filters.errors}'})
|
||||
# ToDo: manually validate category, product
|
||||
filters_form = Stock_Item_Filters.from_form(form_filters)
|
||||
model = Model_View_Store_Stock_Items(filters_stock_item=filters_form)
|
||||
return jsonify({'status': 'success', 'Success': True, 'data': model.category_list.to_list_rows_permutation()})
|
||||
except Exception as e:
|
||||
return jsonify({'status': 'failure', 'Message': f'Bad data received by controller.\n{e}'})
|
||||
|
||||
def get_form_filters_stock_items(data_request):
|
||||
data_form = data_request[Model_View_Store_Stock_Items.KEY_FORM]
|
||||
form_filters = Form_Filters_Stock_Item(**data_form)
|
||||
form_filters.is_out_of_stock.data = av.input_bool(data_form['is_out_of_stock'], 'is_out_of_stock', 'permutations_post')
|
||||
return form_filters
|
||||
|
||||
@routes_store_stock_item.route('/store/stock_item_save', methods=['POST'])
|
||||
def stock_save():
|
||||
data = Helper_App.get_request_data(request)
|
||||
"""
|
||||
form_filters = None
|
||||
try:
|
||||
form_filters = get_form_filters_stock_items(data)
|
||||
if not form_filters.validate_on_submit():
|
||||
return jsonify({'status': 'failure', 'Message': f'Filters form invalid.\n{form_filters.errors}'})
|
||||
|
||||
stock_items = data[Model_View_Store_Stock.KEY_PERMUTATIONS]
|
||||
print(f'stock_items: {stock_items}')
|
||||
if len(stock_items) == 0:
|
||||
return jsonify({'status': 'failure', 'Message': f'No stock items.'})
|
||||
objsStockItem = []
|
||||
for stock_item in stock_items:
|
||||
objsStockItem.append(Product_Permutation.from_json(stock_item))
|
||||
print(f'objsStockItem: {objsStockItem}')
|
||||
|
||||
# ToDo: manually validate category, product
|
||||
filters_form = Stock_Filters.from_form(form_filters)
|
||||
model_save = Model_View_Store_Stock(filters_product=filters_form)
|
||||
model_save.save_stock_items(data.comment, objsPermutation)
|
||||
|
||||
model_return = Model_View_Store_Stock(filters_product=filters_form)
|
||||
return jsonify({'status': 'success', 'Success': True, 'data': model_return.category_list.to_list_rows_permutation()})
|
||||
except Exception as e:
|
||||
return jsonify({'status': 'failure', 'Message': f'Bad data received by controller.\n{e}'})
|
||||
"""
|
||||
68
routing/store/supplier.py
Normal file
68
routing/store/supplier.py
Normal file
@@ -0,0 +1,68 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: App Routing
|
||||
Feature: Store Supplier Routes
|
||||
|
||||
Description:
|
||||
Initializes the Flask application, sets the configuration based on the environment, and defines two routes (/ and /about) that render templates with the specified titles.
|
||||
"""
|
||||
|
||||
|
||||
# internal
|
||||
from business_objects.store.product import Product, Product_Filters, Product_Permutation
|
||||
from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters
|
||||
from forms import Form_Supplier, Form_Filters_Permutation, Form_Filters_Stock_Item
|
||||
from models.model_view_base import Model_View_Base
|
||||
from models.model_view_store import Model_View_Store
|
||||
from models.model_view_store_supplier import Model_View_Store_Supplier
|
||||
from models.model_view_store_product_category import Model_View_Store_Product_Category
|
||||
from models.model_view_store_product_permutation import Model_View_Store_Product_Permutation
|
||||
from models.model_view_store_stock_items import Model_View_Store_Stock_Items
|
||||
from helpers.helper_app import Helper_App
|
||||
import lib.argument_validation as av
|
||||
# external
|
||||
from flask import Flask, render_template, jsonify, request, render_template_string, send_from_directory, redirect, url_for, session, Blueprint, current_app
|
||||
from extensions import db, oauth
|
||||
from urllib.parse import quote_plus, urlencode
|
||||
from authlib.integrations.flask_client import OAuth
|
||||
from authlib.integrations.base_client import OAuthError
|
||||
from urllib.parse import quote, urlparse, parse_qs
|
||||
|
||||
|
||||
routes_store_supplier= Blueprint('routes_store_supplier', __name__)
|
||||
|
||||
|
||||
@routes_store_supplier.route('/supplier', methods=['GET'])
|
||||
def supplier():
|
||||
try:
|
||||
data = request.json
|
||||
except:
|
||||
data = {}
|
||||
print(f'data={data}')
|
||||
form_data = data[Model_View_Store_Supplier.key_form]
|
||||
print(f'form_data: {form_data}')
|
||||
form = Form_Supplier(**form_data)
|
||||
print('form acquired')
|
||||
print(form.__repr__)
|
||||
if form.validate_on_submit():
|
||||
print('valid form')
|
||||
# model = input_JSON_basket(model, data)
|
||||
# if not logged in:
|
||||
try:
|
||||
model = Model_View_Store_Supplier(form)
|
||||
# print('importing basket')
|
||||
# model.import_JSON_basket(data)
|
||||
model.get_basket(data)
|
||||
permutation_id, quantity = model.import_JSON_basket_item(data, form)
|
||||
model.basket_item_edit(permutation_id, quantity, False) # new_basket =
|
||||
except Exception as e:
|
||||
return jsonify({'status': 'failure', 'Message': f'Bad data received by controller.\n{e}'})
|
||||
# return jsonify(Success = True, data = { html_block: render_template(), Model_View_Store.key_basket: new_basket })
|
||||
# html_block = render_template('_block_store_basket.html', model = model)
|
||||
# print(f'html_block:\n{html_block}')
|
||||
# return jsonify(Success = True, data = { 'html_block': html_block, 'basket': {'items': model.basket.to_json_list()}})
|
||||
return render_template('_page_supplier.html', model = model)
|
||||
return jsonify({'status': 'failure', 'Message': f'Invalid supplier details.\n{form.errors}'})
|
||||
169
routing/user.py
Normal file
169
routing/user.py
Normal file
@@ -0,0 +1,169 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: App Routing
|
||||
Feature: User Routes
|
||||
|
||||
Description:
|
||||
Initializes the Flask application, sets the configuration based on the environment, and defines two routes (/ and /about) that render templates with the specified titles.
|
||||
"""
|
||||
|
||||
# IMPORTS
|
||||
# internal
|
||||
from models.model_view_base import Model_View_Base
|
||||
from models.model_view_user import Model_View_User
|
||||
from business_objects.user import User, User_Filters
|
||||
from datastores.datastore_user import DataStore_User
|
||||
from helpers.helper_app import Helper_App
|
||||
import lib.argument_validation as av
|
||||
# external
|
||||
from flask import Flask, render_template, jsonify, request, render_template_string, send_from_directory, redirect, url_for, session, Blueprint, current_app
|
||||
from extensions import db, oauth
|
||||
from urllib.parse import quote_plus, urlencode
|
||||
from authlib.integrations.flask_client import OAuth
|
||||
from authlib.integrations.base_client import OAuthError
|
||||
from urllib.parse import quote, urlparse, parse_qs
|
||||
|
||||
routes_user = Blueprint('routes_user', __name__)
|
||||
|
||||
# User authentication
|
||||
@routes_user.route("/login", methods=['POST'])
|
||||
def login():
|
||||
try:
|
||||
data = request.json
|
||||
except:
|
||||
data = {}
|
||||
print(f'data={data}')
|
||||
# callback_login = F'{Model_View_Base.HASH_CALLBACK_LOGIN}{data.get(Model_View_Base.KEY_CALLBACK, Model_View_Base.HASH_PAGE_HOME)}'
|
||||
|
||||
# encoded_path = quote(data.get(Model_View_Base.KEY_CALLBACK, Model_View_Base.HASH_PAGE_HOME))
|
||||
uri_redirect = url_for('routes_user.login_callback', _external=True) # , subpath=encoded_path
|
||||
|
||||
# uri_redirect = f'{current_app.URL_HOST}/login_callback?subpath={data.get(Model_View_Base.KEY_CALLBACK, Model_View_Base.HASH_PAGE_HOME)}'
|
||||
print(f'redirect uri: {uri_redirect}')
|
||||
hash_callback = data.get(Model_View_Base.KEY_CALLBACK, Model_View_Base.HASH_PAGE_HOME)
|
||||
print(f'hash_callback: {hash_callback}')
|
||||
|
||||
red = oauth.auth0.authorize_redirect(
|
||||
redirect_uri = uri_redirect,
|
||||
state = quote(hash_callback)
|
||||
)
|
||||
print(f'redirect: {red}')
|
||||
headers = red.headers['Location']
|
||||
print(f'headers: {headers}')
|
||||
parsed_url = urlparse(headers)
|
||||
query_params = parse_qs(parsed_url.query)
|
||||
print(f"""
|
||||
OAuth Authorize Redirect URL:
|
||||
|
||||
Base URL: {parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path}
|
||||
{parsed_url}
|
||||
|
||||
Query Parameters: {query_params}
|
||||
""")
|
||||
return jsonify({'Success': True, 'status': 'success', f'{Model_View_Base.KEY_CALLBACK}': headers})
|
||||
|
||||
@routes_user.route("/login_callback") # <path:subpath>/<code>
|
||||
def login_callback():
|
||||
try:
|
||||
# print(f'code: {code}')
|
||||
token = None
|
||||
try:
|
||||
token = oauth.auth0.authorize_access_token()
|
||||
except Exception as e:
|
||||
# Log the error for debugging
|
||||
print(f"Error: {str(e)}")
|
||||
session[current_app.config['ID_TOKEN_USER']] = token
|
||||
# import user id
|
||||
print(f'str(type(token)) = {str(type(token))}')
|
||||
print(f'token = {token}')
|
||||
userinfo = token.get('userinfo')
|
||||
print(f'user info: {userinfo}')
|
||||
# id_user = token.get('sub')
|
||||
id_user = userinfo.get('sub')
|
||||
print(f'user ID: {id_user}')
|
||||
|
||||
datastore_user = DataStore_User()
|
||||
user = datastore_user.get_user_auth0()
|
||||
user_filters = User_Filters.from_user(user)
|
||||
users, errors = datastore_user.get_many_user(user_filters, user)
|
||||
try:
|
||||
user = users[0]
|
||||
print('User logged in')
|
||||
print(f'user ({str(type(user))}): {user}')
|
||||
print(f'user key: {Model_View_Base.KEY_USER}')
|
||||
user_json = user.to_json()
|
||||
session[Model_View_Base.KEY_USER] = user_json
|
||||
print(f'user stored on session')
|
||||
except:
|
||||
print(f'User not found: {user_filters}\nDatabase query error: {errors}')
|
||||
|
||||
try:
|
||||
hash_callback = token.get('hash_callback')
|
||||
if hash_callback is None:
|
||||
print('hash is none')
|
||||
state = request.args.get('state')
|
||||
print(f'state: {state}')
|
||||
hash_callback = state # .get('hash_callback')
|
||||
print(f'hash_callback: {hash_callback}')
|
||||
except:
|
||||
print("get hash callback failed")
|
||||
# id_user = get_id_user()
|
||||
# add user to database
|
||||
# DataStore_Store().add_new_user(id_user) # this is part of get basket - should occur on page load
|
||||
|
||||
print(f'user session: {session[Model_View_Base.KEY_USER]}')
|
||||
return redirect(f'{current_app.config['URL_HOST']}{hash_callback}')
|
||||
except Exception as e:
|
||||
return jsonify({'status': 'failure', 'Message': f'Controller error.\n{e}'})
|
||||
|
||||
@routes_user.route("/logout")
|
||||
def logout():
|
||||
session.clear()
|
||||
url_logout = "https://" + current_app.config['DOMAIN_AUTH0'] + "/v2/logout?" + urlencode(
|
||||
{
|
||||
"returnTo": url_for("routes_user.logout_callback", _external=True),
|
||||
"client_id": current_app.config['ID_AUTH0_CLIENT'],
|
||||
}# ,
|
||||
# quote_via=quote_plus,
|
||||
)
|
||||
current_app.logger.debug(f"Redirecting to {url_logout}")
|
||||
print(f"Redirecting to {url_logout}")
|
||||
return redirect(url_logout)
|
||||
|
||||
@routes_user.route("/logout_callback") # <path:subpath>/<code>
|
||||
def logout_callback():
|
||||
return redirect(url_for('routes_core.home'))
|
||||
try:
|
||||
session[current_app.ID_TOKEN_USER] = None
|
||||
user = User()
|
||||
try:
|
||||
hash_callback = token.get('hash_callback')
|
||||
if hash_callback is None:
|
||||
print('hash is none')
|
||||
state = request.args.get('state')
|
||||
print(f'state: {state}')
|
||||
hash_callback = state # .get('hash_callback')
|
||||
print(f'hash_callback: {hash_callback}')
|
||||
except:
|
||||
print("get hash callback failed")
|
||||
# id_user = get_id_user()
|
||||
# add user to database
|
||||
# DataStore_Store().add_new_user(id_user) # this is part of get basket - should occur on page load
|
||||
|
||||
print(f'user session: {session[Model_View_Base.KEY_USER]}')
|
||||
return redirect(f'{current_app.URL_HOST}{hash_callback}')
|
||||
except Exception as e:
|
||||
return jsonify({'status': 'failure', 'Message': f'Controller error.\n{e}'})
|
||||
|
||||
|
||||
@routes_user.route("/user")
|
||||
def user():
|
||||
try:
|
||||
model = Model_View_User(current_app, db)
|
||||
html_body = render_template('_page_user.html', model = model)
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
return html_body
|
||||
Reference in New Issue
Block a user