1. PostgreSQL copy of all MySQL created and tested.\n 2. Purchase Orders and Sales Orders and stock level management added to MySQL, PostgreSQL, and server and front end code.
This commit is contained in:
101
app.py
101
app.py
@@ -18,11 +18,13 @@ Initializes the Flask application, sets the configuration based on the environme
|
||||
# internal
|
||||
from config import app_config, Config
|
||||
# from routes import bp_home
|
||||
from forms import Form_Contact
|
||||
from forms import Form_Contact, Form_Supplier, Form_Filters_Permutations
|
||||
from models.model_view_base import Model_View_Base
|
||||
from models.model_view_home import Model_View_Home
|
||||
from models.model_view_contact import Model_View_Contact
|
||||
from business_objects.product import Product # , Product_Image_Filters, Resolution_Level_Enum
|
||||
from models.model_view_supplier import Model_View_Supplier
|
||||
from models.model_view_store_permutations import Model_View_Store_Permutations
|
||||
from business_objects.product import Product, Product_Filters # , Product_Image_Filters, Resolution_Level_Enum
|
||||
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
|
||||
@@ -54,6 +56,12 @@ app.TESTING = Config.TESTING
|
||||
app.SECRET_KEY = "007cfbdaaf6d1eb27209720e8a5fc8ba0a334ae0be6fcac132b0a471549cde7c" # Config.SECRET_KEY
|
||||
app.config['SECRET_KEY'] = app.SECRET_KEY
|
||||
|
||||
app.DB_NAME = Config.DB_NAME
|
||||
app.DB_USER = Config.DB_USER
|
||||
app.DB_PASSWORD = Config.DB_PASSWORD
|
||||
app.DB_HOST = Config.DB_HOST
|
||||
# app.DB_PORT = Config.DB_PORT
|
||||
|
||||
app.SQLALCHEMY_DATABASE_URI = Config.SQLALCHEMY_DATABASE_URI
|
||||
app.SQLALCHEMY_TRACK_MODIFICATIONS = Config.SQLALCHEMY_TRACK_MODIFICATIONS
|
||||
app.ID_AUTH0_CLIENT = Config.ID_AUTH0_CLIENT
|
||||
@@ -110,12 +118,7 @@ app.config['RECAPTCHA_PRIVATE_KEY'] = Config.RECAPTCHA_PRIVATE_KEY
|
||||
|
||||
# db = SQLAlchemy(app)
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = Config.SQLALCHEMY_DATABASE_URI
|
||||
db = SQLAlchemy()
|
||||
db.init_app(app)
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
db.engine.url = app.config.SQLALCHEMY_DATABASE_URI
|
||||
|
||||
|
||||
"""
|
||||
oauth = OAuth(app)
|
||||
oauth.register(
|
||||
@@ -130,10 +133,16 @@ oauth.register(
|
||||
# session[app.ID_TOKEN_USER] = {'userinfo': {'sub': ''}}
|
||||
"""
|
||||
|
||||
mail = Mail(app)
|
||||
db = SQLAlchemy()
|
||||
db.init_app(app)
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
db.engine.url = app.config.SQLALCHEMY_DATABASE_URI
|
||||
|
||||
mail = Mail(app) # ToDo: move to helper
|
||||
|
||||
# METHODS
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
sys.path.insert(0, os.path.dirname(__file__)) # Todo: why?
|
||||
|
||||
@app.route('/hello')
|
||||
def hello():
|
||||
@@ -162,7 +171,7 @@ def application(environ, start_response):
|
||||
@app.route('/', methods=['GET'])
|
||||
def home():
|
||||
try:
|
||||
model = Model_View_Home(db, get_info_user(), app)
|
||||
model = Model_View_Home(app)
|
||||
html_body = render_template('_page_home.html', model = model)
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
@@ -208,6 +217,70 @@ def services():
|
||||
return jsonify(error=str(e)), 403
|
||||
return html_body
|
||||
|
||||
# shop management
|
||||
@app.route('/supplier', methods=['GET'])
|
||||
def supplier():
|
||||
try:
|
||||
data = request.json
|
||||
except:
|
||||
data = {}
|
||||
print(f'data={data}')
|
||||
form_data = data[Model_View_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_Supplier(db, get_info_user(), app, 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}'})
|
||||
|
||||
# product permutations
|
||||
@app.route('/store/permutations', methods=['GET'])
|
||||
def permutations_get():
|
||||
filters = Product_Filters.get_default()
|
||||
model = Model_View_Store_Permutations(app=app, db=db, filters_product=filters)
|
||||
return render_template('_page_store_product.html', model = model)
|
||||
|
||||
@app.route('/store/permutations', methods=['POST'])
|
||||
def permutations_post():
|
||||
try:
|
||||
data = request.json
|
||||
except:
|
||||
data = {}
|
||||
print(f'data={data}')
|
||||
form_filters = None
|
||||
try:
|
||||
form_data = data[Model_View_Store_Permutations.KEY_FORM_FILTERS]
|
||||
print(f'form_data: {form_data}')
|
||||
form_filters = Form_Filters_Permutations(**form_data)
|
||||
print('form acquired')
|
||||
print(form_filters.__repr__)
|
||||
print('valid form')
|
||||
filters_form = Product_Filters.from_form(form_filters)
|
||||
model = Model_View_Store_Permutations(app=app, db=db, filters_product=filters_form)
|
||||
# return render_template('_page_store_product.html', model = model)
|
||||
return jsonify({'status': 'success', '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}'})
|
||||
|
||||
|
||||
|
||||
# snore
|
||||
@app.route('/license', methods=['GET'])
|
||||
def license():
|
||||
@@ -250,12 +323,6 @@ def privacy_notice():
|
||||
return str(e)
|
||||
return html_body
|
||||
|
||||
def get_info_user():
|
||||
try:
|
||||
return session[app.ID_TOKEN_USER].get('userinfo') # .get('sub')
|
||||
except:
|
||||
return {'sub': ''}
|
||||
|
||||
# Onload
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
|
||||
Reference in New Issue
Block a user