Complete system for getting + saving Product Categories with new database, server, and client architecture.

This commit is contained in:
2024-09-01 21:57:46 +01:00
parent f9cd9ec33a
commit c9dda91dc9
303 changed files with 4358 additions and 2885 deletions

View File

@@ -32,7 +32,7 @@ from business_objects.store.product import Product # , Product_Image_Filters, Re
import lib.argument_validation as av
from business_objects.store.basket import Basket_Item
from datastores.datastore_store_base import DataStore_Store
from business_objects.store.product import Product_Filters
from business_objects.store.product import Filters_Product
# external
from flask import Flask, render_template, jsonify, request, render_template_string, send_from_directory, redirect, url_for, session
from flask_cors import CORS
@@ -165,7 +165,7 @@ def store_home():
# model.get_regions_and_currencies()
# model.categories = Model_View_Store_Home.get_many_product(db)
# product = categories[list(categories.keys())[0]][0]
model.get_many_product(Product_Filters(
model.get_many_product(Filters_Product(
model.id_user,
True, '', False,
True, '', False, False,

Binary file not shown.

Binary file not shown.

17
app.py
View File

@@ -30,7 +30,7 @@ from models.model_view_store_stock_items import Model_View_Store_Stock_Items
from models.model_view_store_supplier import Model_View_Store_Supplier
from models.model_view_store_product_permutation import Model_View_Store_Product_Permutations
from models.model_view_user import Model_View_User
from business_objects.store.product import Product, Product_Filters, Product_Permutation # , Product_Image_Filters, Resolution_Level_Enum
from business_objects.store.product import Product, Filters_Product, Product_Permutation # , Product_Image_Filters, Resolution_Level_Enum
from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters
from business_objects.user import User, User_Filters
from datastores.datastore_store_base import DataStore_Store
@@ -47,6 +47,11 @@ from routing.user import routes_user
# external
from flask import Flask, render_template, jsonify, request, render_template_string, send_from_directory, redirect, url_for, session
# from flask_appconfig import AppConfig
from flask_cors import CORS
from flask_sqlalchemy import SQLAlchemy
from flask_mail import Mail, Message
from flask_wtf.csrf import CSRFProtect
from authlib.integrations.flask_client import OAuth
import os
import sys
@@ -60,6 +65,14 @@ app = Flask(__name__)
app.config.from_object(app_config) # for db init with required keys
# app.config["config"] = app_config()
"""
csrf = CSRFProtect()
cors = CORS()
db = SQLAlchemy()
mail = Mail()
oauth = OAuth()
"""
csrf.init_app(app)
cors.init_app(app)
db.init_app(app)
@@ -88,7 +101,7 @@ with app.app_context():
app.register_blueprint(routes_core)
app.register_blueprint(routes_legal)
# app.register_blueprint(routes_store_product)
# app.register_blueprint(routes_store_product_category)
app.register_blueprint(routes_store_product_category)
app.register_blueprint(routes_store_product_permutation)
app.register_blueprint(routes_store_stock_item)
app.register_blueprint(routes_store_supplier)

View File

@@ -19,7 +19,7 @@ Business object for SQL errors
# internal
import lib.argument_validation as av
from lib import data_types
from forms import Form_Basket_Add, Form_Basket_Edit # Form_Product
from forms.forms import Form_Basket_Add, Form_Basket_Edit # Form_Product
# external
from enum import Enum
from datetime import datetime, timedelta

View File

View File

View File

@@ -19,7 +19,7 @@ Business object for basket
# internal
import lib.argument_validation as av
# from lib import data_types
from business_objects.store.product import Product #, Product_Filters
from business_objects.store.product import Product #, Filters_Product
from business_objects.store.discount import Discount
from business_objects.store.delivery_option import Delivery_Option
# from forms import Form_Product

View File

@@ -102,7 +102,7 @@ class Product_Image_Filters():
def __new__(cls, product_id, get_thumbnail, get_remaining_LQ):
# Initialiser - validation
_m = 'Product_Filters.__new__'
_m = 'Filters_Product.__new__'
v_arg_type = 'class attribute'
av.val_int(product_id, 'product_id', _m, v_arg_type=v_arg_type)
av.val_bool(get_thumbnail, 'get_thumbnail', _m, v_arg_type=v_arg_type)

View File

@@ -13,7 +13,7 @@ Business object for product
# internal
import lib.argument_validation as av
from lib import data_types
from forms import Form_Basket_Add, Form_Basket_Edit, Form_Filters_Permutation
from forms.forms import Form_Basket_Add, Form_Basket_Edit, Form_Filters_Permutation
from business_objects.store.delivery_option import Delivery_Option
from business_objects.store.discount import Discount
from business_objects.store.image import Image
@@ -62,6 +62,8 @@ class Product(db.Model, Store_Base):
id_product = db.Column(db.Integer, primary_key=True)
id_category = db.Column(db.Integer)
name = db.Column(db.String(255))
id_access_level_required = db.Column(db.Integer)
active = db.Column(db.Boolean)
display_order = db.Column(db.Integer)
can_view = db.Column(db.Boolean)
can_edit = db.Column(db.Boolean)
@@ -87,13 +89,15 @@ class Product(db.Model, Store_Base):
v_arg_type = 'class attribute'
product = Product()
product.id_product = query_row[0]
product.id_category = query_row[5]
product.id_category = query_row[1]
product.name = query_row[2]
product.has_variations = av.input_bool(query_row[4], "has_variations", _m, v_arg_type=v_arg_type)
product.display_order = query_row[22]
product.can_view = av.input_bool(query_row[24], "can_view", _m, v_arg_type=v_arg_type)
product.can_edit = av.input_bool(query_row[25], "can_edit", _m, v_arg_type=v_arg_type)
product.can_admin = av.input_bool(query_row[26], "can_admin", _m, v_arg_type=v_arg_type)
product.has_variations = av.input_bool(query_row[3], "has_variations", _m, v_arg_type=v_arg_type)
product.id_access_level_required = query_row[4]
product.active = av.input_bool(query_row[5], "active", _m, v_arg_type=v_arg_type)
product.display_order = query_row[6]
product.can_view = av.input_bool(query_row[7], "can_view", _m, v_arg_type=v_arg_type)
product.can_edit = av.input_bool(query_row[8], "can_edit", _m, v_arg_type=v_arg_type)
product.can_admin = av.input_bool(query_row[9], "can_admin", _m, v_arg_type=v_arg_type)
return product
"""
def from_permutation(permutation, has_variations = False):
@@ -315,12 +319,12 @@ class Product(db.Model, Store_Base):
}
@dataclass
class Product_Filters():
class Filters_Product():
# id_user: str
get_all_category: bool
get_inactive_category: bool
# get_first_category_only: bool
ids_category: str
get_all_product_category: bool
get_inactive_product_category: bool
# get_first_product_category_only: bool
ids_product_category: str
get_all_product: bool
get_inactive_product: bool
# get_first_product_only: bool
@@ -351,10 +355,10 @@ class Product_Filters():
def to_json(self):
return {
'a_id_user': None,
'a_get_all_category': self.get_all_category,
'a_get_inactive_category': self.get_inactive_category,
# 'a_get_first_category_only': self.get_first_category_only,
'a_ids_category': self.ids_category,
'a_get_all_product_category': self.get_all_product_category,
'a_get_inactive_product_category': self.get_inactive_product_category,
# 'a_get_first_product_category_only': self.get_first_product_category_only,
'a_ids_product_category': self.ids_product_category,
'a_get_all_product': self.get_all_product,
'a_get_inactive_product': self.get_inactive_product,
# 'a_get_first_product_only': self.get_first_product_only,
@@ -384,16 +388,16 @@ class Product_Filters():
@staticmethod
def from_form(form):
# if not (form is Form_Filters_Permutation): raise ValueError(f'Invalid form type: {type(form)}')
av.val_instance(form, 'form', 'Product_Filters.from_form', Form_Filters_Permutation)
av.val_instance(form, 'form', 'Filters_Product.from_form', Form_Filters_Permutation)
has_category_filter = not (form.id_category.data == '0' or form.id_category.data == '')
has_product_filter = not (form.id_product.data == '0' or form.id_product.data == '')
get_permutations_stock_below_min = av.input_bool(form.is_out_of_stock.data, "is_out_of_stock", "Product_Filters.from_form")
get_permutations_stock_below_min = av.input_bool(form.is_out_of_stock.data, "is_out_of_stock", "Filters_Product.from_form")
print(f'form question: {type(form.is_out_of_stock)}\nbool interpretted: {get_permutations_stock_below_min}\type form: {type(form)}')
return Product_Filters(
get_all_category = not has_category_filter,
get_inactive_category = False,
# get_first_category_only = False,
ids_category = form.id_category.data,
return Filters_Product(
get_all_product_category = not has_category_filter,
get_inactive_product_category = False,
# get_first_product_category_only = False,
ids_product_category = form.id_category.data,
get_all_product = not has_product_filter,
get_inactive_product = False,
# get_first_product_only = False,
@@ -422,11 +426,11 @@ class Product_Filters():
@staticmethod
def get_default():
return Product_Filters(
get_all_category = True,
get_inactive_category = False,
# get_first_category_only = False,
ids_category = '',
return Filters_Product(
get_all_product_category = True,
get_inactive_product_category = False,
# get_first_product_category_only = False,
ids_product_category = '',
get_all_product = True,
get_inactive_product = False,
# get_first_product_only = False,
@@ -451,4 +455,55 @@ class Product_Filters():
# get_inactive_discount = False,
# ids_discount = '',
get_products_quantity_stock_below_min = True
)
@classmethod
def from_json(cls, json):
return cls(
get_all_product_category = json.get('a_get_all_product_category', False),
get_inactive_product_category = json.get('a_get_inactive_product_category', False),
# get_first_product_category_only = json.get('a_get_first_product_category_only', False),
ids_product_category = json.get('a_ids_product_category', ''),
get_all_product = json.get('a_get_all_product', False),
get_inactive_product = json.get('a_get_inactive_product', False),
# get_first_product_only = json.get('a_get_first_product_only', False),
ids_product = json.get('a_ids_product', ''),
get_all_permutation = json.get('a_get_all_permutation', False),
get_inactive_permutation = json.get('a_get_inactive_permutation', False),
# get_first_permutation_only = json.get('a_get_first_permutation_only', False),
ids_permutation = json.get('a_ids_permutation', ''),
get_all_image = json.get('a_get_all_image', False),
get_inactive_image = json.get('a_get_inactive_image', False),
# get_first_image_only = json.get('a_get_first_image_only', False),
ids_image = json.get('a_ids_image', ''),
# get_all_region = json.get('a_get_all_region', False),
# get_inactive_region = json.get('a_get_inactive_region', False),
# get_first_region_only = json.get('a_get_first_region_only', False),
# ids_region = json.get('a_ids_region', ''),
# get_all_currency = json.get('a_get_all_currency', False),
# get_inactive_currency = json.get('a_get_inactive_currency', False),
# get_first_currency_only = json.get('a_get_first_currency_only', False),
# ids_currency = json.get('a_ids_currency', ''),
# get_all_discount = json.get('a_get_all_discount', False),
# get_inactive_discount = json.get('a_get_inactive_discount', False),
# ids_discount = json.get('a_ids_discount', ''),
get_products_quantity_stock_below_min = json.get('a_get_products_quantity_stock_below_min', False)
)
@classmethod
def from_filters_product_category(cls, filters_category):
return cls(
get_all_product_category = True,
get_inactive_product_category = filters_category.active_only,
ids_product_category = '',
get_all_product = True,
get_inactive_product = False,
ids_product = False,
get_all_permutation = True,
get_inactive_permutation = False,
ids_permutation = '',
get_all_image = False,
get_inactive_image = False,
ids_image = '',
get_products_quantity_stock_below_min = False
)

View File

@@ -7,15 +7,9 @@ Technology: Business Objects
Feature: Product Category Business Object
Description:
Business object for product
Business object for product category
"""
# IMPORTS
# VARIABLE INSTANTIATION
# CLASSES
# METHODS
# IMPORTS
# internal
import lib.argument_validation as av
from business_objects.store.product import Product, Product_Permutation, Product_Price
@@ -54,16 +48,19 @@ class Enum_Product_Category(Enum):
"""
class Product_Category(db.Model, Store_Base):
ATTR_CODE_CATEGORY: ClassVar[str] = 'code-category'
ATTR_NAME_CATEGORY: ClassVar[str] = 'name-category'
ATTR_DESCRIPTION_CATEGORY: ClassVar[str] = 'description-category'
ATTR_DISPLAY_ORDER_CATEGORY: ClassVar[str] = 'display-order-category'
__tablename__ = 'Shop_Product_Category_Temp'
id_category = db.Column(db.Integer, primary_key=True)
code = db.Column(db.String(50))
name = db.Column(db.String(255))
description = db.Column(db.String(4000))
id_access_level_required = db.Column(db.Integer)
display_order = db.Column(db.Integer)
active = db.Column(db.Boolean)
can_view = db.Column(db.Boolean)
can_edit = db.Column(db.Boolean)
can_admin = db.Column(db.Boolean)
created_on = db.Column(db.DateTime)
created_by = db.Column(db.Integer)
"""
def __new__(cls, id, name, description, display_order):
_m = 'Category.__new__'
@@ -88,9 +85,15 @@ class Product_Category(db.Model, Store_Base):
def from_DB_product(query_row):
category = Product_Category()
category.id_category = query_row[0]
category.name = query_row[1]
category.description = query_row[2]
category.display_order = query_row[3]
category.code = query_row[1]
category.name = query_row[2]
category.description = query_row[3]
category.id_access_level_required = query_row[4]
category.display_order = query_row[5]
category.active = query_row[6]
category.can_view = query_row[7]
category.can_edit = query_row[8]
category.can_admin = query_row[9]
return category
"""
def key_product_index_from_ids_product_permutation(id_product, id_permutation):
@@ -174,10 +177,12 @@ class Product_Category(db.Model, Store_Base):
"""
def __repr__(self):
return f'''
id: {self.id_category}
name: {self.name}
description: {self.description}
id: {self.id_category[0] if isinstance(self.id_category, tuple) else self.id_category}
code: {self.code[0] if isinstance(self.code, tuple) else self.code}
name: {self.name[0] if isinstance(self.name, tuple) else self.name}
description: {self.description[0] if isinstance(self.description, tuple) else self.description}
display_order: {self.display_order}
active: {self.active}
products: {self.products}
'''
def get_permutation_first(self):
@@ -203,42 +208,111 @@ class Product_Category(db.Model, Store_Base):
return list_products
def to_json(self):
return {
self.ATTR_ID_PRODUCT_CATEGORY: self.id_category,
self.ATTR_CODE_CATEGORY: self.code,
self.ATTR_NAME_CATEGORY: self.name,
self.ATTR_DESCRIPTION_CATEGORY: self.description,
self.ATTR_DISPLAY_ORDER_CATEGORY: self.display_order
self.ATTR_ID_PRODUCT_CATEGORY: self.id_category[0] if isinstance(self.id_category, tuple) else self.id_category,
self.FLAG_CODE: self.code[0] if isinstance(self.code, tuple) else self.code,
self.FLAG_NAME: self.name[0] if isinstance(self.name, tuple) else self.name,
self.FLAG_DESCRIPTION: self.description[0] if isinstance(self.description, tuple) else self.description,
self.FLAG_DISPLAY_ORDER: self.display_order,
self.FLAG_ACTIVE: self.active,
self.FLAG_CAN_VIEW: self.can_view,
self.FLAG_CAN_EDIT: self.can_edit,
self.FLAG_CAN_ADMIN: self.can_admin
}
@classmethod
def from_json(cls, json):
print(f' Category.from_json: {json}')
category = cls()
category.id_category = json[cls.ATTR_ID_PRODUCT_CATEGORY],
category.code = json[cls.ATTR_CODE_CATEGORY],
category.name = json[cls.ATTR_NAME_CATEGORY],
category.description = json[cls.ATTR_DESCRIPTION_CATEGORY],
category.display_order = json[cls.ATTR_DISPLAY_ORDER_CATEGORY]
category.id_category = json.get(cls.ATTR_ID_PRODUCT_CATEGORY),
category.code = json[cls.FLAG_CODE],
category.name = json[cls.FLAG_NAME],
category.description = json[cls.FLAG_DESCRIPTION],
category.display_order = json[cls.FLAG_DISPLAY_ORDER]
category.active = json[cls.FLAG_ACTIVE]
category.can_view = json.get(cls.FLAG_CAN_VIEW, False)
category.can_edit = json.get(cls.FLAG_CAN_EDIT, False)
category.can_admin = json.get(cls.FLAG_CAN_ADMIN, False)
return category
def to_json_str(self):
return {
self.ATTR_ID_PRODUCT_CATEGORY: self.id_category[0] if isinstance(self.id_category, tuple) else self.id_category,
self.FLAG_CODE: self.code[0] if isinstance(self.code, tuple) else self.code,
self.FLAG_NAME: self.name[0] if isinstance(self.name, tuple) else self.name,
self.FLAG_DESCRIPTION: self.description[0] if isinstance(self.description, tuple) else self.description,
self.FLAG_DISPLAY_ORDER: self.display_order,
self.FLAG_ACTIVE: self.output_bool(self.active),
self.FLAG_CAN_VIEW: self.output_bool(self.can_view),
self.FLAG_CAN_EDIT: self.output_bool(self.can_edit),
self.FLAG_CAN_ADMIN: self.output_bool(self.can_admin)
}
@staticmethod
def output_bool(value):
return av.input_bool(value, 'Product_Category bool attribute', 'Product_Category.output_bool')
"""
class Filters_Product_Category(BaseModel, Store_Base):
ids_product_category: str
ids_product: str
"""
""
def __new__(cls, product_ids, product_categories):
_m = 'Product_Filters.__new__'
_m = 'Filters_Product.__new__'
v_arg_type = 'class attribute'
# av.val_list_instances(product_ids, 'product_ids', _m, str, v_arg_type=v_arg_type)
# av.val_list_instances(product_categories, 'product_categories', _m, Product_Category_Enum, v_arg_type=v_arg_type)
av.val_str(product_ids, 'product_ids', _m, v_arg_type=v_arg_type)
av.val_str(product_categories, 'product_categories', _m, v_arg_type=v_arg_type)
return super(Filters_Product_Category, cls).__new__(cls)
"""
""
def __init__(self, ids_product, ids_product_category):
super().__init__(ids_product=ids_product, ids_product_category=ids_product_category)
"""
""
# Constructor
self.ids = product_ids
self.categories = product_categories
"""
""
@classmethod
def get_default(cls):
return Filters_Product_Category(
ids_product_category = '',
ids_product = ''
)
def to_json(self):
return {
'a_ids_product_category': self.ids_product_category,
'a_ids_product': self.ids_product
}
@classmethod
def from_json(cls, json):
filters = cls()
filters.ids_product_category = json['a_ids_product_category'],
filters.ids_product = json['a_ids_product']
"""
class Filters_Product_Category(BaseModel, Store_Base):
is_not_empty_only: bool
active_only: bool
def __init__(self, is_not_empty_only, active_only):
super().__init__(is_not_empty_only=is_not_empty_only, active_only=active_only)
@classmethod
def get_default(cls):
return cls(
is_not_empty_only = False,
active_only = True
)
def to_json(self):
return {
'is_not_empty_only': self.is_not_empty_only,
'active_only': self.active_only
}
@classmethod
def from_json(cls, json):
return cls(
is_not_empty_only = json['is_not_empty_only'],
active_only = json['active_only']
)
@classmethod
def from_form(cls, form):
return cls(
is_not_empty_only = av.input_bool(form.is_not_empty.data, 'is_not_empty', 'Filters_Product_Category.from_form'),
active_only = av.input_bool(form.active.data, 'active', 'Filters_Product_Category.from_form')
)
class Container_Product_Category(Store_Base):
categories: list
@@ -311,7 +385,7 @@ class Container_Product_Category(Store_Base):
for category in self.categories:
list_rows += category.to_list_rows_permutation()
return list_rows
def to_list_categories(self):
def to_list_category_options(self):
list_categories = []
for category in self.categories:
list_categories.append({'value': category.id_category, 'text': category.name})
@@ -327,4 +401,12 @@ class Container_Product_Category(Store_Base):
dict_lists_products = {}
for category in self.categories:
dict_lists_products[category.id_category] = category.to_list_products()
return dict_lists_products
return dict_lists_products
def to_json(self):
return {
'categories': [category.to_json() for category in self.categories]
}
def to_json_str(self):
return {
'categories': [category.to_json_str() for category in self.categories]
}

View File

@@ -13,7 +13,7 @@ Business object for product permutation
# internal
import lib.argument_validation as av
from lib import data_types
from forms import Form_Basket_Add, Form_Basket_Edit, Form_Filters_Permutation
from forms.forms import Form_Basket_Add, Form_Basket_Edit, Form_Filters_Permutation
from business_objects.store.delivery_option import Delivery_Option
from business_objects.store.discount import Discount
from business_objects.store.image import Image
@@ -55,6 +55,7 @@ class Product_Permutation(db.Model, Store_Base):
name_recurrence_interval = db.Column(db.String(255))
name_plural_recurrence_interval = db.Column(db.String(256))
count_recurrence_interval = db.Column(db.Integer)
active = db.Column(db.Boolean)
display_order = db.Column(db.Integer)
can_view = db.Column(db.Boolean)
can_edit = db.Column(db.Boolean)
@@ -89,32 +90,30 @@ class Product_Permutation(db.Model, Store_Base):
v_arg_type = 'class attribute'
print(f'query_row: {query_row}')
permutation = Product_Permutation()
permutation.id_product = query_row[0]
permutation.id_permutation = query_row[1]
# permutation.name = query_row[2]
permutation.id_permutation = query_row[0]
permutation.id_product = query_row[1]
permutation.id_category = query_row[2]
permutation.description = query_row[3]
# permutation.price_GBP_full = query_row[4]
# permutation.price_GBP_min = query_row[5]
permutation.id_currency_cost = query_row[7]
permutation.code_currency_cost = query_row[8]
permutation.symbol_currency_cost = query_row[9]
permutation.cost_local = query_row[6]
permutation.has_variations = query_row[4]
permutation.id_category = query_row[5]
permutation.latency_manufacture = query_row[11]
permutation.quantity_min = query_row[12]
permutation.quantity_max = query_row[13]
permutation.quantity_step = query_row[14]
permutation.quantity_stock = query_row[15]
permutation.id_stripe_product = query_row[16]
permutation.is_subscription = av.input_bool(query_row[17], "is_subscription", _m, v_arg_type=v_arg_type)
permutation.name_recurrence_interval = query_row[18]
permutation.name_plural_recurrence_interval = query_row[19]
permutation.count_recurrence_interval = query_row[20]
permutation.display_order = query_row[23]
permutation.can_view = av.input_bool(query_row[24], "can_view", _m, v_arg_type=v_arg_type)
permutation.can_edit = av.input_bool(query_row[25], "can_edit", _m, v_arg_type=v_arg_type)
permutation.can_admin = av.input_bool(query_row[26], "can_admin", _m, v_arg_type=v_arg_type)
permutation.cost_local = query_row[4]
permutation.id_currency_cost = query_row[5]
permutation.code_currency_cost = query_row[6]
permutation.symbol_currency_cost = query_row[7]
# permutation.profit_local_min = query_row[8]
permutation.latency_manufacture = query_row[9]
permutation.quantity_min = query_row[10]
permutation.quantity_max = query_row[11]
permutation.quantity_step = query_row[12]
permutation.quantity_stock = query_row[13]
permutation.id_stripe_product = query_row[14]
permutation.is_subscription = av.input_bool(query_row[15], "is_subscription", _m, v_arg_type=v_arg_type)
permutation.name_recurrence_interval = query_row[16]
permutation.name_plural_recurrence_interval = query_row[17]
permutation.count_recurrence_interval = query_row[18]
permutation.active = query_row[19]
permutation.display_order = query_row[20]
permutation.can_view = av.input_bool(query_row[21], "can_view", _m, v_arg_type=v_arg_type)
permutation.can_edit = av.input_bool(query_row[22], "can_edit", _m, v_arg_type=v_arg_type)
permutation.can_admin = av.input_bool(query_row[23], "can_admin", _m, v_arg_type=v_arg_type)
return permutation
def from_DB_Stripe_product(query_row):

View File

@@ -11,7 +11,7 @@ Feature: Stock Item Business Object
# internal
import lib.argument_validation as av
from lib import data_types
from forms import Form_Filters_Stock_Item
from forms.forms import Form_Filters_Stock_Item
from business_objects.store.product_price import Product_Price
# from business_objects.discount import Discount
from business_objects.store.store_base import Store_Base
@@ -272,10 +272,10 @@ class Stock_Item_Filters():
@staticmethod
def from_form(form):
# if not (form is Form_Filters_Permutations): raise ValueError(f'Invalid form type: {type(form)}')
av.val_instance(form, 'form', 'Product_Filters.from_form', Form_Filters_Stock_Item)
av.val_instance(form, 'form', 'Filters_Product.from_form', Form_Filters_Stock_Item)
has_category_filter = not (form.id_category.data == '0' or form.id_category.data == '')
has_product_filter = not (form.id_product.data == '0' or form.id_product.data == '')
get_permutations_stock_below_min = av.input_bool(form.is_out_of_stock.data, "is_out_of_stock", "Product_Filters.from_form")
get_permutations_stock_below_min = av.input_bool(form.is_out_of_stock.data, "is_out_of_stock", "Filters_Product.from_form")
print(f'form question: {type(form.is_out_of_stock)}\nbool interpretted: {get_permutations_stock_below_min}\type form: {type(form)}')
return Stock_Item_Filters(
get_all_category = not has_category_filter,

View File

@@ -15,20 +15,27 @@ Abstract business object for store objects
from typing import ClassVar
class Store_Base():
ATTR_ID_CURRENCY: ClassVar[str] = 'id-currency'
# ATTR_ID_CURRENCY_COST: ClassVar[str] = 'id-currency-cost'
ATTR_ID_DELIVERY_REGION: ClassVar[str] = 'id-delivery-region'
ATTR_ID_DISCOUNT: ClassVar[str] = 'id-discount'
ATTR_ID_IMAGE: ClassVar[str] = 'id-image'
ATTR_ID_LOCATION_STORAGE: ClassVar[str] = 'id-location-storage'
ATTR_ID_PRODUCT: ClassVar[str] = 'id-product'
ATTR_ID_PRODUCT_CATEGORY: ClassVar[str] = 'id-category'
ATTR_ID_PRODUCT_PERMUTATION: ClassVar[str] = 'id-permutation'
ATTR_ID_PRODUCT_PRICE: ClassVar[str] = 'id-price'
ATTR_ID_PRODUCT_VARIATION: ClassVar[str] = 'id-variation'
ATTR_ID_CURRENCY: ClassVar[str] = 'id_currency'
# ATTR_ID_CURRENCY_COST: ClassVar[str] = 'id_currency_cost'
ATTR_ID_DELIVERY_REGION: ClassVar[str] = 'id_delivery_region'
ATTR_ID_DISCOUNT: ClassVar[str] = 'id_discount'
ATTR_ID_IMAGE: ClassVar[str] = 'id_image'
ATTR_ID_LOCATION_STORAGE: ClassVar[str] = 'id_location_storage'
ATTR_ID_PRODUCT: ClassVar[str] = 'id_product'
ATTR_ID_PRODUCT_CATEGORY: ClassVar[str] = 'id_category'
ATTR_ID_PRODUCT_PERMUTATION: ClassVar[str] = 'id_permutation'
ATTR_ID_PRODUCT_PRICE: ClassVar[str] = 'id_price'
ATTR_ID_PRODUCT_VARIATION: ClassVar[str] = 'id_variation'
ATTR_ID_PRODUCT_VARIATION_TYPE: ClassVar[str] = 'id_variation_type'
ATTR_ID_STOCK_ITEM: ClassVar[str] = 'id-stock-item'
ATTR_ID_STOCK_ITEM: ClassVar[str] = 'id_stock_item'
FLAG_ACTIVE: ClassVar[str] = 'active'
FLAG_CAN_ADMIN: ClassVar[str] = 'can_admin'
FLAG_CAN_EDIT: ClassVar[str] = 'can_edit'
FLAG_CAN_VIEW: ClassVar[str] = 'can_view'
FLAG_CODE: ClassVar[str] = 'code'
FLAG_DESCRIPTION: ClassVar[str] = 'description'
FLAG_DISPLAY_ORDER: ClassVar[str] = 'display_order'
FLAG_NAME: ClassVar[str] = 'name'
def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
@@ -54,4 +61,5 @@ class Store_Base():
def from_json(cls, json):
pass
def to_json(self):
pass
pass

View File

@@ -13,7 +13,7 @@ Business objects for Stripe
# internal
import lib.argument_validation as av
from lib import data_types
from forms import Form_Basket_Add, Form_Basket_Edit # Form_Product
from forms.forms import Form_Basket_Add, Form_Basket_Edit # Form_Product
from extensions import db
# external

View File

@@ -9,7 +9,7 @@ Feature: User Business Object
# internal
import lib.argument_validation as av
from forms import Form_Filters_User
from forms.forms import Form_Filters_User
from extensions import db
# external
from dataclasses import dataclass

View File

@@ -21,7 +21,7 @@ from business_objects.store.delivery_option import Delivery_Option
from business_objects.store.delivery_region import Delivery_Region
from business_objects.store.discount import Discount
from business_objects.store.order import Order
from business_objects.store.product import Product, Product_Permutation, Product_Price, Product_Filters # Permutation_Variation_Link
from business_objects.store.product import Product, Product_Permutation, Product_Price, Filters_Product # Permutation_Variation_Link
from business_objects.sql_error import SQL_Error
from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters
from business_objects.user import User, User_Filters, User_Permission_Evaluation
@@ -40,25 +40,31 @@ from pydantic import BaseModel, ConfigDict
from typing import ClassVar
from datetime import datetime
# db = SQLAlchemy()
class DataStore_Base(BaseModel):
# Global constants
# Attributes
"""
app: Flask = None
db: SQLAlchemy = None
session: object = None
"""
model_config = ConfigDict(arbitrary_types_allowed=True)
# model_config = ConfigDict(arbitrary_types_allowed=True)
def __init__(self, **kwargs):
super().__init__(**kwargs)
# Constructor
"""
self.db = db
self.app = current_app
with self.app.app_context():
self.session = session
def db_procedure_execute(self, proc_name, argument_dict_list = None):
"""
@staticmethod
def db_procedure_execute(proc_name, argument_dict_list = None):
# Argument validation
_m = 'DataStore_Base.db_procedure_execute'
av.val_str(proc_name, 'proc_name', _m)
@@ -80,9 +86,9 @@ class DataStore_Base(BaseModel):
# conn = Helper_DB_MySQL(self.app).get_db_connection()
if has_arguments:
result = self.db.session.execute(proc_string, argument_dict_list)
result = db.session.execute(proc_string, argument_dict_list)
else:
result = self.db.session.execute(proc_string)
result = db.session.execute(proc_string)
print(f'result: {result}')
# conn.session.remove()
return result
@@ -93,11 +99,12 @@ class DataStore_Base(BaseModel):
result_set_2 = cursor.fetchall()
print(f'products: {result_set_2}')
@staticmethod
def db_cursor_clear(cursor):
while cursor.nextset():
print(f'new result set: {cursor.fetchall()}')
def get_regions_and_currencies(self):
@classmethod
def get_regions_and_currencies(cls):
_m = 'DataStore_Base.get_regions_and_currencies'
_m_db_currency = 'p_shop_get_many_currency'
_m_db_region = 'p_shop_get_many_region'
@@ -110,7 +117,7 @@ class DataStore_Base(BaseModel):
}
print(f'executing {_m_db_currency}')
result = self.db_procedure_execute(_m_db_currency, argument_dict_list_currency)
result = cls.db_procedure_execute(_m_db_currency, argument_dict_list_currency)
cursor = result.cursor
print('data received')
@@ -118,13 +125,13 @@ class DataStore_Base(BaseModel):
result_set_1 = cursor.fetchall()
currencies = []
for row in result_set_1:
currency = Currency.from_DB_currency(row)
currency = Currency.make_from_DB_currency(row)
currencies.append(currency)
print(f'currencies: {currencies}')
DataStore_Base.db_cursor_clear(cursor)
print(f'executing {_m_db_region}')
result = self.db_procedure_execute(_m_db_region, argument_dict_list_region)
result = cls.db_procedure_execute(_m_db_region, argument_dict_list_region)
cursor = result.cursor
print('data received')
@@ -132,15 +139,16 @@ class DataStore_Base(BaseModel):
result_set_1 = cursor.fetchall()
regions = []
for row in result_set_1:
region = Delivery_Region.from_DB_region(row)
region = Delivery_Region.make_from_DB_region(row)
regions.append(region)
print(f'regions: {regions}')
DataStore_Base.db_cursor_clear(cursor)
cursor.close()
return regions, currencies
def get_user_session(self):
return User.from_json(self.session.get(User.KEY_USER))
@staticmethod
def get_user_session():
return User.from_json(session.get(User.KEY_USER))
user = User.get_default()
try:
print(f'user session: {session[self.app.ID_TOKEN_USER]}')
@@ -152,7 +160,21 @@ class DataStore_Base(BaseModel):
except:
print('get user login failed')
return user
def get_user_auth0(self):
return User.from_json_auth0(self.session.get(self.app.config['ID_TOKEN_USER']))
@staticmethod
def get_user_auth0():
return User.from_json_auth0(session.get(current_app.config['ID_TOKEN_USER']))
@staticmethod
def upload_bulk(objects, objectType, batch_size):
_m = 'DataStore_Base.upload_bulk'
print(f'{_m}\nstarting...')
try:
for i in range(0, len(objects), batch_size):
batch = objects[i:i+batch_size]
data = [object.to_json() for object in batch]
print(f'batch: {batch}\ndata: {data}')
db.session.bulk_insert_mappings(objectType, data)
db.session.commit()
except Exception as e:
print(f'{_m}\n{e}')
db.session.rollback()
raise e

View File

@@ -21,7 +21,7 @@ from business_objects.store.delivery_option import Delivery_Option
from business_objects.store.delivery_region import Delivery_Region
from business_objects.store.discount import Discount
from business_objects.store.order import Order
from business_objects.store.product import Product, Product_Permutation, Product_Price, Product_Filters
from business_objects.store.product import Product, Product_Permutation, Product_Price, Filters_Product
from business_objects.sql_error import SQL_Error
from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters
from business_objects.user import User, User_Filters, User_Permission_Evaluation
@@ -41,6 +41,8 @@ from pydantic import BaseModel, ConfigDict
from typing import ClassVar
from datetime import datetime
# db = SQLAlchemy()
class DataStore_Store_Base(DataStore_Base):
# Global constants
@@ -52,17 +54,17 @@ class DataStore_Store_Base(DataStore_Base):
def __init__(self, **kwargs):
super().__init__(**kwargs)
def get_many_product(self, product_filters):
@classmethod
def get_many_product(cls, product_filters):
# redundant argument validation?
_m = 'DataStore_Store_Base.get_many_product'
av.val_instance(product_filters, 'product_filters', _m, Product_Filters)
av.val_instance(product_filters, 'product_filters', _m, Filters_Product)
argument_dict = product_filters.to_json()
user = self.get_user_session()
user = cls.get_user_session()
argument_dict['a_id_user'] = 1 # 'auth0|6582b95c895d09a70ba10fef' # id_user
print(f'argument_dict: {argument_dict}')
print('executing p_shop_get_many_product')
result = self.db_procedure_execute('p_shop_get_many_product', argument_dict)
result = cls.db_procedure_execute('p_shop_get_many_product', argument_dict)
cursor = result.cursor
print('data received')
@@ -85,35 +87,36 @@ class DataStore_Store_Base(DataStore_Base):
cursor.nextset()
result_set_2 = cursor.fetchall()
# print(f'products: {result_set_2}')
products = [] # [Product(**row) for row in result_set_2]
product_index = {}
# products = [] # [Product(**row) for row in result_set_2]
# product_index = {}
for row in result_set_2:
new_product = Product.from_DB_product(row) # (row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10], row[11], row[12], row[13], row[14], row[15], row[16], row[17], row[18], row[19])
index_category = category_list.get_index_category_from_id(new_product.id_category)
category = category_list.categories[index_category]
category_list.add_product(new_product)
# products.append(new_product)
print(f'category_list: {category_list}')
# Permutations
cursor.nextset()
result_set_3 = cursor.fetchall()
# print(f'Permutations: {result_set_3}')
permutations = [] # [Product(**row) for row in result_set_2]
# permutation_index = {}
for row in result_set_3:
new_permutation = Product_Permutation.from_DB_product(row) # (row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10], row[11], row[12], row[13], row[14], row[15], row[16], row[17], row[18], row[19])
index_category = category_list.get_index_category_from_id(new_permutation.id_category)
category = category_list.categories[index_category]
try:
index_product = category.get_index_product_from_id(new_permutation.id_product)
category_list.add_permutation(new_permutation)
# product = products[index_product]
# product.add_permutation(new_permutation)
except KeyError:
product_index[new_permutation.id_product] = len(products)
product = Product.from_DB_product(row)
product.add_permutation(new_permutation)
products.append(product)
# categories[category_index[new_product.id_category]].add_product(new_product)
category_list.add_product(product)
# category_list.add_permutation(new_permutation)
# print(f'products: {[p.id_product for p in products]}') # {products}')
category_list.add_permutation(new_permutation)
print(f'category_list: {category_list}')
# Product_Variations
cursor.nextset()
result_set_3 = cursor.fetchall()
# print(f'variations: {result_set_3}')
# variations = [Product_Variation(**row) for row in result_set_3]
result_set_4 = cursor.fetchall()
# print(f'variations: {result_set_4}')
# variations = [Product_Variation(**row) for row in result_set_4]
variations = []
for row in result_set_3:
for row in result_set_4:
new_variation = Product_Variation.from_DB_product(row) # (row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7])
variations.append(new_variation)
# products[product_index[new_variation.id_product]].variations.append(new_variation)
@@ -127,8 +130,8 @@ class DataStore_Store_Base(DataStore_Base):
# Images
cursor.nextset()
result_set_5 = cursor.fetchall()
# print(f'images: {result_set_4}')
# images = [Image(**row) for row in result_set_4]
# print(f'images: {result_set_5}')
# images = [Image(**row) for row in result_set_5]
images = []
for row in result_set_5:
new_image = Image.from_DB_product(row) # (row[0], row[1], row[2], row[3], row[4])
@@ -179,6 +182,7 @@ class DataStore_Store_Base(DataStore_Base):
DataStore_Store_Base.db_cursor_clear(cursor)
cursor.close()
return category_list, errors # categories, category_index
@@ -192,7 +196,7 @@ class DataStore_Store_Base(DataStore_Base):
price_ids.append() # get price id
return price_ids
"""
@staticmethod
def get_ids_permutation_from_error_availability(msg_error_availability):
ids_permutation = []
index_colon = msg_error_availability.find(':', msg_error_availability.find(':'))
@@ -203,8 +207,8 @@ class DataStore_Store_Base(DataStore_Base):
index_comma = msg_error_availability.find(',')
ids_permutation.append(msg_error_availability[:index_comma])
return ids_permutation
def get_regions_and_currencies(self):
@classmethod
def get_regions_and_currencies(cls):
_m = 'DataStore_Store_Base.get_regions_and_currencies'
_m_db_currency = 'p_shop_get_many_currency'
_m_db_region = 'p_shop_get_many_region'
@@ -217,7 +221,7 @@ class DataStore_Store_Base(DataStore_Base):
}
print(f'executing {_m_db_currency}')
result = self.db_procedure_execute(_m_db_currency, argument_dict_list_currency)
result = cls.db_procedure_execute(_m_db_currency, argument_dict_list_currency)
cursor = result.cursor
print('data received')
@@ -231,7 +235,7 @@ class DataStore_Store_Base(DataStore_Base):
DataStore_Store_Base.db_cursor_clear(cursor)
print(f'executing {_m_db_region}')
result = self.db_procedure_execute(_m_db_region, argument_dict_list_region)
result = cls.db_procedure_execute(_m_db_region, argument_dict_list_region)
cursor = result.cursor
print('data received')
@@ -243,10 +247,11 @@ class DataStore_Store_Base(DataStore_Base):
regions.append(region)
print(f'regions: {regions}')
DataStore_Store_Base.db_cursor_clear(cursor)
cursor.close()
return regions, currencies
def get_many_product_variation(self, variation_filters):
@classmethod
def get_many_product_variation(cls, variation_filters):
_m = 'DataStore_Store_Base.get_many_product_variation'
print(_m)
av.val_instance(variation_filters, 'variation_filters', _m, Product_Variation_Filters)
@@ -262,14 +267,14 @@ class DataStore_Store_Base(DataStore_Base):
'a_guid': guid
}
"""
user = self.get_user_session()
user = cls.get_user_session()
argument_dict_list = {
# 'a_guid': guid
'a_id_user': user.id_user
, **variation_filters.to_json()
}
# argument_dict_list['a_guid'] = guid
result = self.db_procedure_execute('p_shop_get_many_product_variation', argument_dict_list)
result = cls.db_procedure_execute('p_shop_get_many_product_variation', argument_dict_list)
cursor = result.cursor
result_set = cursor.fetchall()
@@ -290,5 +295,7 @@ class DataStore_Store_Base(DataStore_Base):
print(f"Error [{error.code}]: {error.msg}")
DataStore_Store_Base.db_cursor_clear(cursor)
cursor.close()
return variations, errors

View File

@@ -21,7 +21,7 @@ from business_objects.store.delivery_option import Delivery_Option
from business_objects.store.delivery_region import Delivery_Region
from business_objects.store.discount import Discount
from business_objects.store.order import Order
from business_objects.store.product import Product, Product_Permutation, Product_Price, Product_Filters
from business_objects.store.product import Product, Product_Permutation, Product_Price, Filters_Product
from business_objects.sql_error import SQL_Error
from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters
from business_objects.user import User, User_Filters, User_Permission_Evaluation
@@ -41,6 +41,8 @@ from pydantic import BaseModel, ConfigDict
from typing import ClassVar
from datetime import datetime
# db = SQLAlchemy()
class DataStore_Store_Basket(DataStore_Store_Base):
# Global constants

View File

@@ -20,11 +20,12 @@ from business_objects.store.delivery_option import Delivery_Option
from business_objects.store.delivery_region import Delivery_Region
from business_objects.store.discount import Discount
from business_objects.store.order import Order
from business_objects.store.product import Product, Product_Permutation, Product_Price, Product_Filters
from business_objects.store.product import Product, Product_Permutation, Product_Price, Filters_Product
from business_objects.sql_error import SQL_Error
from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters
from business_objects.user import User, User_Filters, User_Permission_Evaluation
from business_objects.store.product_variation import Product_Variation, Product_Variation_Filters, Product_Variation_List
# from datastores.datastore_base import Table_Shop_Product_Category, Table_Shop_Product_Category_Temp
from datastores.datastore_store_base import DataStore_Store_Base
from helpers.helper_db_mysql import Helper_DB_MySQL
# from models.model_view_store_checkout import Model_View_Store_Checkout # circular!
@@ -40,36 +41,114 @@ from pydantic import BaseModel, ConfigDict
from typing import ClassVar
from datetime import datetime
# db = SQLAlchemy()
"""
class Table_Shop_Product_Category(db.Model):
__tablename__ = 'Shop_Product_Category'
id_category: int = db.Column(db.Integer, primary_key=True)
code: str = db.Column(db.String(50))
name: str = db.Column(db.String(255))
description: str = db.Column(db.String(4000))
active: bool = db.Column(db.Boolean)
display_order: int = db.Column(db.Integer)
created_on: datetime = db.Column(db.DateTime)
created_by: int = db.Column(db.Integer)
id_change_set: int = db.Column(db.Integer)
"""
class Row_Shop_Product_Category_Temp(db.Model):
__tablename__ = 'Shop_Product_Category_Temp'
__table_args__ = { 'extend_existing': True }
id_category: int = db.Column(db.Integer, primary_key=True)
code: str = db.Column(db.String(50))
name: str = db.Column(db.String(255))
description: str = db.Column(db.String(4000))
active: bool = db.Column(db.Boolean)
display_order: int = db.Column(db.Integer)
guid: str = db.Column(db.BINARY(36))
created_on: datetime = db.Column(db.DateTime)
created_by: int = db.Column(db.Integer)
@classmethod
def from_product_category(cls, product_category):
row = cls()
row.id_category = product_category.id_category[0] if isinstance(product_category.id_category, tuple) else product_category.id_category
row.code = product_category.code[0] if isinstance(product_category.code, tuple) else product_category.code
row.name = product_category.name[0] if isinstance(product_category.name, tuple) else product_category.name
row.description = product_category.description[0] if isinstance(product_category.description, tuple) else product_category.description
row.active = product_category.active
row.display_order = product_category.display_order
"""
row.guid = product_category.guid
row.created_on = product_category.created_on
row.created_by = product_category.created_by
"""
return row
def to_json(self):
return {
'id_category': self.id_category,
'code': self.code,
'name': self.name,
'description': self.description,
'active': self.active,
'display_order': self.display_order,
'guid': self.guid,
'created_on': self.created_on,
'created_by': self.created_by
}
class DataStore_Store_Product_Category(DataStore_Store_Base):
def __init__(self):
super().__init__()
def save_categories(self, comment, categories):
@classmethod
def save_categories(cls, comment, categories):
_m = 'DataStore_Store_Product_Category.save_categories'
av.val_str(comment, 'comment', _m)
av.val_list(categories, 'categories', _m, Product_Category, 1)
print(f'{_m}\nstarting...')
print(f'comment: {comment}\ncategories: {categories}')
# av.val_str(comment, 'comment', _m)
# av.val_list_instances(categories, 'categories', _m, Product_Category, 1)
guid = Helper_DB_MySQL.create_guid()
now = datetime.now()
user = self.get_user_session()
for permutation in permutations:
setattr(permutation, 'guid', guid)
setattr(permutation, 'created_on', now)
setattr(permutation, 'created_by', user.id_user)
user = cls.get_user_session()
rows = []
id_category_new = 0
for category in categories:
row = Row_Shop_Product_Category_Temp.from_product_category(category)
# id_tmp =
if row.id_category == '':
id_category_new -= 1
row.id_category = id_category_new
else:
print(f'row.id_category: {row.id_category}')
row.guid = guid
row.created_on = now
row.created_by = user.id_user
rows.append(row)
cursor = self.db.cursor()
print(f'rows: {rows}')
"""
cursor = db.cursor()
print('cursor created')
cursor.executemany(
'INSERT INTO Shop_Product_Permutation_Temp (id_permutation, id_product, description, cost_local, id_currency_cost, profit_local_min, latency_manufacture, quantity_min, quantity_max, quantity_step, quantity_stock, is_subscription, id_recurrence_interval, count_recurrence_interval, id_stripe_product, active, display_order, guid) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)',
permutations
'INSERT INTO Shop_Product_Category_Temp (id_category, code, name, description, active, display_order, guid, created_on, created_by) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)',
categories
)
self.db.commit()
print('bulk upload executed')
db.commit()
print('bulk upload committed')
cursor.close()
print('cursor closed')
"""
DataStore_Store_Base.upload_bulk(rows, Row_Shop_Product_Category_Temp, 1000)
argument_dict_list = {
'a_id_user': user.id_user,
'a_guid': guid,
'a_comment': comment,
'a_guid': guid
}
self.db_procedure_execute('p_shop_save_permutation', argument_dict_list)
cursor.close()
save_result = cls.db_procedure_execute('p_shop_save_product_category', argument_dict_list)
save_result.close()
print('save procedure executed')

View File

@@ -20,7 +20,7 @@ from business_objects.store.delivery_option import Delivery_Option
from business_objects.store.delivery_region import Delivery_Region
from business_objects.store.discount import Discount
from business_objects.store.order import Order
from business_objects.store.product import Product, Product_Permutation, Product_Price, Product_Filters
from business_objects.store.product import Product, Product_Permutation, Product_Price, Filters_Product
from business_objects.sql_error import SQL_Error
from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters
from business_objects.user import User, User_Filters, User_Permission_Evaluation
@@ -40,6 +40,8 @@ from pydantic import BaseModel, ConfigDict
from typing import ClassVar
from datetime import datetime
# db = SQLAlchemy()
class DataStore_Store_Product_Permutation(DataStore_Store_Base):
def __init__(self):

View File

@@ -21,7 +21,7 @@ from business_objects.store.delivery_option import Delivery_Option
from business_objects.store.delivery_region import Delivery_Region
from business_objects.store.discount import Discount
from business_objects.store.order import Order
from business_objects.store.product import Product, Product_Permutation, Product_Price, Product_Filters
from business_objects.store.product import Product, Product_Permutation, Product_Price, Filters_Product
from business_objects.sql_error import SQL_Error
from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters
from business_objects.user import User, User_Filters, User_Permission_Evaluation
@@ -41,6 +41,8 @@ from pydantic import BaseModel, ConfigDict
from typing import ClassVar
from datetime import datetime
# db = SQLAlchemy()
class DataStore_Store_Product_Variation(DataStore_Store_Base):
# Global constants

View File

@@ -21,7 +21,7 @@ from business_objects.store.delivery_option import Delivery_Option
from business_objects.store.delivery_region import Delivery_Region
from business_objects.store.discount import Discount
from business_objects.store.order import Order
from business_objects.store.product import Product, Product_Permutation, Product_Price, Product_Filters
from business_objects.store.product import Product, Product_Permutation, Product_Price, Filters_Product
from business_objects.sql_error import SQL_Error
from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters
from business_objects.user import User, User_Filters, User_Permission_Evaluation
@@ -41,6 +41,8 @@ from pydantic import BaseModel, ConfigDict
from typing import ClassVar
from datetime import datetime
# db = SQLAlchemy()
class DataStore_Store_Stock_Item(DataStore_Store_Base):
# Global constants

View File

@@ -21,7 +21,7 @@ from business_objects.store.delivery_option import Delivery_Option
from business_objects.store.delivery_region import Delivery_Region
from business_objects.store.discount import Discount
from business_objects.store.order import Order
from business_objects.store.product import Product, Product_Permutation, Product_Price, Product_Filters
from business_objects.store.product import Product, Product_Permutation, Product_Price, Filters_Product
from business_objects.sql_error import SQL_Error
from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters
from business_objects.user import User, User_Filters, User_Permission_Evaluation
@@ -41,6 +41,8 @@ from pydantic import BaseModel, ConfigDict
from typing import ClassVar
from datetime import datetime
# db = SQLAlchemy()
class DataStore_Store_Stripe(DataStore_Store_Base):
# Global constants

View File

@@ -21,7 +21,7 @@ from business_objects.store.delivery_option import Delivery_Option
from business_objects.store.delivery_region import Delivery_Region
from business_objects.store.discount import Discount
from business_objects.store.order import Order
from business_objects.store.product import Product, Product_Permutation, Product_Price, Product_Filters
from business_objects.store.product import Product, Product_Permutation, Product_Price, Filters_Product
from business_objects.sql_error import SQL_Error
from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters
from business_objects.user import User, User_Filters, User_Permission_Evaluation
@@ -41,6 +41,8 @@ from pydantic import BaseModel, ConfigDict
from typing import ClassVar
from datetime import datetime
# db = SQLAlchemy()
class DataStore_User(DataStore_Base):
# Global constants

0
forms/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

View File

@@ -12,6 +12,7 @@ Defines Flask-WTF forms for handling user input.
# IMPORTS
# internal
# from business_objects.store.product_category import Filters_Product_Category # circular
# from models.model_view_store import Model_View_Store # circular
# external
from flask_wtf import FlaskForm

0
forms/store/__init__.py Normal file
View File

Binary file not shown.

View File

@@ -0,0 +1,34 @@
"""
Project: PARTS Website
Author: Edward Middleton-Smith
Precision And Research Technology Systems Limited
Technology: Backend
Feature: Forms - User data input
Description:
Defines Flask-WTF forms for handling user input.
"""
# IMPORTS
# internal
# from business_objects.store.product_category import Filters_Product_Category
# from models.model_view_store import Model_View_Store # circular
# external
from flask_wtf import FlaskForm
from wtforms import StringField, TextAreaField, SubmitField, BooleanField, IntegerField, SelectField, FloatField
from wtforms.validators import InputRequired, NumberRange, Regexp, DataRequired, Optional
from flask_wtf.recaptcha import RecaptchaField
class Form_Filters_Product_Category(FlaskForm):
is_not_empty = BooleanField('Not empty only?')
active = BooleanField("Active only?")
@classmethod
def from_filters_product_category(cls, filters_product_category):
form = Form_Filters_Product_Category()
form.is_not_empty.data = filters_product_category.is_not_empty_only
form.active.data = filters_product_category.active_only
return form
def __repr__(self):
return f'Form_Filters_Product_Category(is_not_empty={self.is_not_empty.data}, active={self.active.data})'

View File

@@ -22,4 +22,10 @@ class Helper_App(BaseModel):
try:
return request.json
except:
return {}
try:
return request.data
except:
try:
return request.form
except:
return {}

View File

@@ -35,5 +35,8 @@ class Helper_DB_MySQL(BaseModel):
return db
@staticmethod
def create_guid_str():
return str(uuid.uuid4())
@staticmethod
def create_guid():
return str(uuid.uuid4())
return uuid.uuid4().bytes

View File

@@ -910,7 +910,7 @@ def val_list_instances(v_input, v_name, method, v_type = None, min_len = -1, max
# optional bool allow_nuns
# optional str v_arg_type
# ARGUMENT VALIDATION
my_f = 'val_list'
my_f = 'val_list_instances'
val_bool(suppress_errors, 'suppress_errors', my_f)
if not val_bool(suppress_console_outputs, 'suppress_console_outputs', my_f, suppress_errors):
print(error_msg_str(suppress_console_outputs, 'suppress_console_outputs', my_f, "<class 'bool'>", suppress_errors))

View File

@@ -18,8 +18,9 @@ Base data model for views
# internal
# from routes import bp_home
import lib.argument_validation as av
from forms import Form_Is_Included_VAT, Form_Delivery_Region, Form_Currency
from forms.forms import Form_Is_Included_VAT, Form_Delivery_Region, Form_Currency
from datastores.datastore_user import DataStore_User
from business_objects.store.store_base import Store_Base
from business_objects.user import User, User_Filters
# external
from abc import ABC, abstractmethod
@@ -28,36 +29,41 @@ from flask import Flask, session, current_app
from pydantic import BaseModel, ConfigDict
from typing import ClassVar
# VARIABLE INSTANTIATION
# CLASSES
class Model_View_Base(BaseModel, ABC):
# Global constants
# ATTR_FOR: ClassVar[str] = 'for'
ATTR_TEXT_COLLAPSED: ClassVar[str] = 'textCollapsed'
ATTR_TEXT_EXPANDED: ClassVar[str] = 'textExpanded'
ATTR_VALUE_CURRENT: ClassVar[str] = 'current-value'
ATTR_VALUE_PREVIOUS: ClassVar[str] = 'previous-value'
FLAG_ACTIVE: ClassVar[str] = 'active'
FLAG_ACTIVE: ClassVar[str] = Store_Base.FLAG_ACTIVE
FLAG_ADD: ClassVar[str] = 'add'
FLAG_CANCEL: ClassVar[str] = 'button-cancel'
# FLAG_CONTACT_US: ClassVar[str] = 'button-contact'
FLAG_CLOSE_TEMPORARY_ELEMENT: ClassVar[str] = 'button-temporary-element-close'
FLAG_CARD: ClassVar[str] = 'card'
FLAG_CODE: ClassVar[str] = Store_Base.FLAG_CODE
FLAG_COLLAPSED: ClassVar[str] = 'collapsed'
FLAG_COLLAPSIBLE: ClassVar[str] = 'collapsible'
FLAG_COLUMN: ClassVar[str] = 'column'
FLAG_COMMENT: ClassVar[str] = 'comment'
FLAG_CONTAINER: ClassVar[str] = 'container'
FLAG_CONTAINER_INPUT: ClassVar[str] = FLAG_CONTAINER + '-input'
FLAG_DELETE: ClassVar[str] = 'delete'
FLAG_DESCRIPTION: ClassVar[str] = Store_Base.FLAG_DESCRIPTION
FLAG_DETAIL: ClassVar[str] = 'detail'
FLAG_DIALOG: ClassVar[str] = 'dialog' # try <dialog> element
FLAG_DIRTY: ClassVar[str] = 'dirty'
FLAG_DISPLAY_ORDER: ClassVar[str] = Store_Base.FLAG_DISPLAY_ORDER
FLAG_ERROR: ClassVar[str] = 'error'
FLAG_EXPANDED: ClassVar[str] = 'expanded'
FLAG_FILTER: ClassVar[str] = 'filter'
FLAG_HAMBURGER: ClassVar[str] = 'hamburger'
FLAG_IMAGE_LOGO: ClassVar[str] = 'image-logo'
FLAG_INITIALISED: ClassVar[str] = 'initialised'
FLAG_MODAL: ClassVar[str] = 'modal'
FLAG_NAME: ClassVar[str] = Store_Base.FLAG_NAME
FLAG_NAV_ADMIN_HOME: ClassVar[str] = 'navAdminHome'
FLAG_NAV_ADMIN_STORE_STRIPE_PRICES: ClassVar[str] = 'navAdminStoreStripePrices'
FLAG_NAV_ADMIN_STORE_STRIPE_PRODUCTS: ClassVar[str] = 'navAdminStoreStripeProducts'
@@ -80,7 +86,9 @@ class Model_View_Base(BaseModel, ABC):
FLAG_PAGE_BODY: ClassVar[str] = 'page-body'
FLAG_ROW: ClassVar[str] = 'row'
FLAG_ROW_NEW: ClassVar[str] = 'row-new'
FLAG_SAVE: ClassVar[str] = 'save'
FLAG_SCROLLABLE: ClassVar[str] = 'scrollable'
FLAG_SLIDER: ClassVar[str] = 'slider'
FLAG_SUBMIT: ClassVar[str] = 'submit'
FLAG_SUBMITTED: ClassVar[str] = 'submitted'
# flagIsDatePicker: ClassVar[str] = 'is-date-picker'
@@ -110,8 +118,8 @@ class Model_View_Base(BaseModel, ABC):
HASH_PAGE_USER_ADMIN: ClassVar[str] = '/user/admin'
HASH_PAGE_USER_LOGIN: ClassVar[str] = '/login'
HASH_PAGE_USER_LOGOUT: ClassVar[str] = '/logout'
HASH_SAVE_STORE_PRODUCT_PERMUTATION: ClassVar[str] = '/store/permutation_save'
ID_BUTTON_ADD: ClassVar[str] = 'buttonAdd'
ID_BUTTON_APPLY_FILTERS: ClassVar[str] = 'buttonApplyFilters'
ID_BUTTON_CANCEL: ClassVar[str] = 'buttonCancel'
ID_BUTTON_HAMBURGER: ClassVar[str] = 'buttonHamburger'
ID_BUTTON_SAVE: ClassVar[str] = 'buttonSave'
@@ -143,6 +151,7 @@ class Model_View_Base(BaseModel, ABC):
ID_BUTTON_NAV_USER_LOGOUT: ClassVar[str] = 'navUserLogout'
"""
ID_OVERLAY_CONFIRM: ClassVar[str] = 'overlayConfirm'
ID_OVERLAY_ERROR: ClassVar[str] = 'overlayError'
ID_OVERLAY_HAMBURGER: ClassVar[str] = 'overlayHamburger'
ID_PAGE_BODY: ClassVar[str] = 'pageBody'
ID_TABLE_MAIN: ClassVar[str] = 'tableMain'

View File

@@ -14,7 +14,7 @@ Data model for contact view
from models.model_view_base import Model_View_Base
# from routes import bp_home
from lib import argument_validation as av
from forms import Form_Contact
from forms.forms import Form_Contact
# external
from flask_wtf import FlaskForm
from abc import abstractproperty

View File

@@ -18,13 +18,13 @@ Parent data model for store views
# internal
# from context import models
from models.model_view_base import Model_View_Base
from business_objects.store.product import Product, Product_Filters, Product_Permutation # Product_Image_Filters,
from business_objects.store.product import Product, Filters_Product, Product_Permutation # Product_Image_Filters,
from business_objects.store.image import Resolution_Level_Enum
import lib.argument_validation as av
from datastores.datastore_store_base import DataStore_Store_Base
from datastores.datastore_user import DataStore_User
from datastores.datastore_store_basket import DataStore_Store_Basket
from forms import Form_Basket_Edit, Form_Is_Included_VAT, Form_Delivery_Region, Form_Currency
from forms.forms import Form_Basket_Edit, Form_Is_Included_VAT, Form_Delivery_Region, Form_Currency
from business_objects.store.basket import Basket_Item, Basket
from business_objects.store.product_category import Product_Category
from business_objects.store.product_variation import Product_Variation_Filters, Product_Variation
@@ -71,6 +71,10 @@ class Model_View_Store(Model_View_Base):
HASH_STORE_BASKET_DELETE : ClassVar[str] = '/store/basket_delete'
HASH_STORE_BASKET_EDIT : ClassVar[str] = '/store/basket_edit'
HASH_STORE_BASKET_LOAD : ClassVar[str] = '/store/basket_load'
HASH_GET_STORE_PRODUCT_CATEGORY: ClassVar[str] = '/store/category_get'
HASH_GET_STORE_PRODUCT_PERMUTATION: ClassVar[str] = '/store/permutation_get'
HASH_SAVE_STORE_PRODUCT_CATEGORY: ClassVar[str] = '/store/category_save'
HASH_SAVE_STORE_PRODUCT_PERMUTATION: ClassVar[str] = '/store/permutation_save'
HASH_STORE_SET_CURRENCY : ClassVar[str] = '/store/set_currency'
HASH_STORE_SET_DELIVERY_REGION : ClassVar[str] = '/store/set_delivery_region'
HASH_STORE_SET_IS_INCLUDED_VAT : ClassVar[str] = '/store/set_is_included_VAT'
@@ -158,7 +162,7 @@ class Model_View_Store(Model_View_Base):
def get_many_product(self, product_filters): # category_ids = '', product_ids = '', get_all_category = True, get_all_product = True, max_products_per_category = -1):
_m = 'Model_View_Store.get_many_product'
av.val_instance(product_filters, 'product_filters', _m, Product_Filters)
av.val_instance(product_filters, 'product_filters', _m, Filters_Product)
"""
av.val_str(category_ids, 'category_ids', _m)
av.val_str(product_ids, 'product_ids', _m)
@@ -288,7 +292,7 @@ class Model_View_Store(Model_View_Base):
is_included_VAT = basket[self.KEY_IS_INCLUDED_VAT]
print(f'json basket items: {items}')
product_ids, permutation_ids, item_index_dict = self._get_json_basket_id_CSVs_product_permutation(items)
category_list, errors = DataStore_Store_Base().get_many_product(Product_Filters(
category_list, errors = DataStore_Store_Base().get_many_product(Filters_Product(
self.id_user, # :a_id_user
True, '', False, # :a_get_all_category, :a_ids_category, :a_get_inactive_category
False, product_ids, False, False, # :a_get_all_product, :a_ids_product, :a_get_inactive_product, :a_get_first_product_only
@@ -335,7 +339,7 @@ class Model_View_Store(Model_View_Base):
"""
ids_permutation_unavailable = self.basket.get_ids_permutation_unavailable()
if len(ids_permutation_unavailable) > 0:
category_list_unavailable, errors_unavailable = DataStore_Store().get_many_product(Product_Filters(
category_list_unavailable, errors_unavailable = DataStore_Store().get_many_product(Filters_Product(
self.id_user, # :a_id_user
True, '', False, # :a_get_all_category, :a_ids_category, :a_get_inactive_category
False, '', False, False, # :a_get_all_product, :a_ids_product, :a_get_inactive_product, :a_get_first_product_only

View File

@@ -19,7 +19,7 @@ Data model for store basket view
from models.model_view_store import Model_View_Store
# from routes import bp_home
from business_objects.store.product import Product
from forms import Form_Billing # Form_Product
from forms.forms import Form_Billing # Form_Product
# external

View File

@@ -20,7 +20,7 @@ from models.model_view_store import Model_View_Store
from models.model_view_store_basket import Model_View_Store_Basket
# from routes import bp_home
from business_objects.store.product import Product
from forms import Form_Billing # Form_Product
from forms.forms import Form_Billing # Form_Product
import lib.argument_validation as av
# from datastores.datastore_store_base import DataStore_Store
# external

View File

@@ -20,7 +20,7 @@ from models.model_view_store import Model_View_Store
from models.model_view_store_checkout import Model_View_Store_Checkout
# from routes import bp_home
from business_objects.store.product import Product
from forms import Form_Billing # Form_Product
from forms.forms import Form_Billing # Form_Product
import lib.argument_validation as av
# from datastores.datastore_store_base import DataStore_Store
# external

View File

@@ -19,7 +19,7 @@ Data model for store home view
from models.model_view_store import Model_View_Store
# from routes import bp_home
from business_objects.store.product import Product
from forms import Form_Basket_Add, Form_Basket_Edit # Form_Product
from forms.forms import Form_Basket_Add, Form_Basket_Edit # Form_Product
# external

View File

@@ -19,7 +19,7 @@ Data model for store product view
from models.model_view_store import Model_View_Store
from datastores.datastore_store_base import DataStore_Store_Base
# from routes import bp_home
from business_objects.store.product import Product, Product_Filters
from business_objects.store.product import Product, Filters_Product
import lib.argument_validation as av
# external
@@ -44,7 +44,7 @@ class Model_View_Store_Product(Model_View_Store):
super().__init__(hash_page_current=hash_page_current, id_currency=id_currency, id_region_delivery=id_region_delivery, is_included_VAT=is_included_VAT)
print('supered')
category_list = DataStore_Store_Base().get_many_product(Product_Filters(
category_list = DataStore_Store_Base().get_many_product(Filters_Product(
self.info_user['sub'],
True, '', False,
True, '', False, False,

View File

@@ -14,10 +14,11 @@ Data model for store permutations view
from models.model_view_store import Model_View_Store
# from datastores.datastore_store_base import DataStore_Store_Base
from datastores.datastore_store_product_category import DataStore_Store_Product_Category
from business_objects.store.product_category import Container_Product_Category
from forms import Form_Filters_Permutation
from business_objects.store.product_category import Container_Product_Category, Filters_Product_Category
from forms.forms import Form_Filters_Permutation
from forms.store.product_category import Form_Filters_Product_Category
# from routes import bp_home
from business_objects.store.product import Product, Product_Filters, Product_Permutation
from business_objects.store.product import Product, Filters_Product, Product_Permutation
from business_objects.store.product_variation import Product_Variation_List
import lib.argument_validation as av
@@ -26,56 +27,29 @@ from pydantic import BaseModel
from typing import ClassVar
class Model_View_Store_Product_Category(Model_View_Store):
ID_FILTER_CATEGORY: ClassVar[str] = 'id_category'
ID_FILTER_PRODUCT: ClassVar[str] = 'id_product'
ID_FILTER_IS_OUT_OF_STOCK: ClassVar[str] = 'is_out_of_stock'
ID_FILTER_QUANTITY_MIN: ClassVar[str] = 'quantity_min'
ID_FILTER_QUANTITY_MAX: ClassVar[str] = 'quantity_max'
ID_Form_Filters_Permutation: ClassVar[str] = 'Form_Filters_Permutation'
KEY_PERMUTATIONS: ClassVar[str] = 'permutations'
FLAG_IS_NOT_EMPTY: ClassVar[str] = 'is-not-empty'
ID_FORM_FILTERS_PRODUCT_CATEGORY: ClassVar[str] = 'Form_Filters_Product_Category'
KEY_CATEGORIES: ClassVar[str] = 'categories'
category_list: Container_Product_Category = None # (str)
filters_product: Product_Filters
form_filters: Form_Filters_Permutation = None
permutation_blank: Product_Permutation = None
variations: Product_Variation_List = None
filters_category: Filters_Product_Category
form_filters: Form_Filters_Product_Category = None
@property
def title(self):
return 'Product Category'
def __init__(self, filters_product, hash_page_current=Model_View_Store.HASH_PAGE_STORE_PRODUCT_PERMUTATIONS):
def __init__(self, filters_category, hash_page_current=Model_View_Store.HASH_PAGE_STORE_PRODUCT_CATEGORIES):
_m = 'Model_View_Store_Product_Category.__init__'
print(f'{_m}\nstarting...')
super().__init__(hash_page_current=hash_page_current, filters_product=filters_product)
super().__init__(hash_page_current=hash_page_current, filters_category=filters_category)
# BaseModel.__init__(self, app=app, filters_product=filters_product, **kwargs)
self.form_filters = Form_Filters_Permutation()
datastore_store = DataStore_Store_Product_Category()
self.form_filters = Form_Filters_Product_Category.from_filters_product_category(filters_category)
filters_product = Filters_Product.from_filters_product_category(filters_category)
self.category_list, errors = datastore_store.get_many_product(filters_product)
category_list_filters, errors_filters = datastore_store.get_many_product(
Product_Filters(
# self.info_user['sub'],
True, False, False, '',
True, False, False, '',
True, False, False, '',
False, False, False, '',
False, False, False, '',
False, False, False, '',
False, False, '',
filters_product.get_products_quantity_stock_below_min
)
)
print(f'category_list_filters: {category_list_filters.categories}')
self.form_filters.id_category.choices = [('0', 'All')] + [(str(category.id_category), category.name) for category in category_list_filters.categories]
print(f'category options: {self.form_filters.id_category.choices}')
product_list = category_list_filters.to_list_products()
print(f'product_list: {product_list}')
self.form_filters.id_product.choices = [('0', 'All')] + [(str(product['value']), product['text']) for product in product_list]
self.permutation_blank = Product_Permutation()
print(f'category options: {self.form_filters.id_category.choices}')
variations, errors = self.get_many_product_variation()
self.variations = variations
def save_categories(self, comment, list_categories):
_m = 'Model_View_Store_Product_Category.save_categories'
@classmethod
def save_categories(cls, comment, list_categories):
_m = f'{cls.__name__}.save_categories'
DataStore_Store_Product_Category().save_categories(comment, list_categories)

View File

@@ -14,9 +14,9 @@ Data model for store permutations view
from models.model_view_store import Model_View_Store
from datastores.datastore_store_product_permutation import DataStore_Store_Product_Permutation
from business_objects.store.product_category import Container_Product_Category
from forms import Form_Filters_Permutation
from forms.forms import Form_Filters_Permutation
# from routes import bp_home
from business_objects.store.product import Product, Product_Filters, Product_Permutation
from business_objects.store.product import Product, Filters_Product, Product_Permutation
from business_objects.store.product_variation import Product_Variation_List
import lib.argument_validation as av
@@ -34,7 +34,7 @@ class Model_View_Store_Product_Permutation(Model_View_Store):
KEY_PERMUTATIONS: ClassVar[str] = 'permutations'
category_list: Container_Product_Category = None # (str)
filters_product: Product_Filters
filters_product: Filters_Product
form_filters: Form_Filters_Permutation = None
permutation_blank: Product_Permutation = None
variations: Product_Variation_List = None
@@ -52,7 +52,7 @@ class Model_View_Store_Product_Permutation(Model_View_Store):
datastore_store = DataStore_Store_Product_Permutation()
self.category_list, errors = datastore_store.get_many_product(filters_product)
category_list_filters, errors_filters = datastore_store.get_many_product(
Product_Filters(
Filters_Product(
# self.info_user['sub'],
True, False, '',
True, False, '',

View File

@@ -14,9 +14,9 @@ Data model for store stock items view
from models.model_view_store import Model_View_Store
from datastores.datastore_store_stock_item import DataStore_Store_Stock_Item
from business_objects.store.product_category import Container_Product_Category
from forms import Form_Filters_Stock_Item
from forms.forms import Form_Filters_Stock_Item
# from routes import bp_home
from business_objects.store.product import Product, Product_Filters, Product_Permutation
from business_objects.store.product import Product, Filters_Product, Product_Permutation
from business_objects.store.stock_item import Stock_Item, Stock_Item_Filters
import lib.argument_validation as av

View File

@@ -15,7 +15,7 @@ from models.model_view_base import Model_View_Base
from models.model_view_store import Model_View_Store
# from routes import bp_home
from lib import argument_validation as av
from forms import Form_Supplier
from forms.forms import Form_Supplier
# external

View File

@@ -12,7 +12,7 @@ Initializes the Flask application, sets the configuration based on the environme
# IMPORTS
# internal
from forms import Form_Contact
from forms.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

View File

@@ -11,15 +11,9 @@ Initializes the Flask application, sets the configuration based on the environme
"""
# 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 business_objects.store.product_category import Product_Category, Filters_Product_Category
from forms.store.product_category import Form_Filters_Product_Category
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
@@ -34,62 +28,58 @@ 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()
@routes_store_product_category.route(Model_View_Store_Product_Category.HASH_PAGE_STORE_PRODUCT_CATEGORIES, methods=['GET'])
def categories():
filters = Filters_Product_Category.get_default()
model = Model_View_Store_Product_Category(filters)
return render_template('_page_store_product_categories.html', model = model)
@routes_store_product_category.route('/store/category_filter', methods=['POST'])
def category_filter():
@routes_store_product_category.route(Model_View_Store_Product_Category.HASH_GET_STORE_PRODUCT_CATEGORY, methods=['POST'])
def filter_category():
data = Helper_App.get_request_data(request)
# form_filters = None
try:
"""
form_filters = get_Form_Filters_Permutation(data)
form_filters = get_Form_Filters_Product_Category(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()})
filters_form = Filters_Product_Category.from_form(form_filters)
model = Model_View_Store_Product_Category(filters_category = filters_form)
return jsonify({'status': 'success', 'Success': True, 'data': model.category_list.to_json_str()})
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')
data_form = data_request[Model_View_Store_Product_Category.KEY_FORM]
form_filters = Form_Filters_Product_Category(**data_form)
form_filters.is_not_empty.data = av.input_bool(data_form['is_not_empty'], 'is_not_empty', 'filter_category')
form_filters.active.data = av.input_bool(data_form['active'], 'active', 'filter_category')
return form_filters
"""
@routes_store_product_category.route('/store/category_save', methods=['POST'])
def category_save():
@routes_store_product_category.route(Model_View_Store_Product_Category.HASH_SAVE_STORE_PRODUCT_CATEGORY, methods=['POST'])
def save_category():
data = Helper_App.get_request_data(request)
# form_filters = None
print(f'data={data}')
try:
"""
form_filters = get_Form_Filters_Permutation(data)
form_filters = get_Form_Filters_Product_Category(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)
"""
filters_form = Filters_Product_Category.from_form(form_filters)
categories = data[Model_View_Store_Product_Permutation.FLAG_PRODUCT_CATEGORY]
categories = data[Model_View_Store_Product_Category.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)
objsCategory.append(Product_Category.from_json(category))
# model_save = Model_View_Store_Product_Category() # filters_product=filters_form)
print(f'objsCategory={objsCategory}')
Model_View_Store_Product_Category.save_categories(data.get('comment', 'No 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()})
model_return = Model_View_Store_Product_Category(filters_category=filters_form)
print('nips')
return jsonify({'status': 'success', 'Success': True, 'data': model_return.category_list.to_json_str()})
except Exception as e:
return jsonify({'status': 'failure', 'Message': f'Bad data received by controller.\n{e}'})

View File

@@ -12,9 +12,9 @@ Initializes the Flask application, sets the configuration based on the environme
# internal
from business_objects.store.product import Product, Product_Filters, Product_Permutation
from business_objects.store.product import Product, Filters_Product, 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 forms.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
@@ -37,7 +37,7 @@ routes_store_product_permutation = Blueprint('routes_store_product_permutation',
@routes_store_product_permutation.route('/store/permutations', methods=['GET'])
def permutation():
filters = Product_Filters.get_default()
filters = Filters_Product.get_default()
model = Model_View_Store_Product_Permutation(filters_product=filters)
return render_template('_page_store_product_permutations.html', model = model)
@@ -50,7 +50,7 @@ def permutation_filter():
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)
filters_form = Filters_Product.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:
@@ -79,7 +79,7 @@ def permutation_save():
objsPermutation.append(Product_Permutation.from_json(permutation))
# ToDo: manually validate category, product
filters_form = Product_Filters.from_form(form_filters)
filters_form = Filters_Product.from_form(form_filters)
model_save = Model_View_Store_Product_Permutation(filters_product=filters_form)
model_save.save_permutations(data.comment, objsPermutation)

View File

@@ -11,9 +11,9 @@ Initializes the Flask application, sets the configuration based on the environme
"""
# internal
from business_objects.store.product import Product, Product_Filters, Product_Permutation
from business_objects.store.product import Product, Filters_Product, 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 forms.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

View File

@@ -12,9 +12,9 @@ Initializes the Flask application, sets the configuration based on the environme
# internal
from business_objects.store.product import Product, Product_Filters, Product_Permutation
from business_objects.store.product import Product, Filters_Product, 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 forms.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

File diff suppressed because it is too large Load Diff

View File

@@ -152,6 +152,7 @@ DROP TABLE IF EXISTS Shop_Recurrence_Interval;
DROP TABLE IF EXISTS Shop_Product_Audit;
DROP TABLE IF EXISTS Shop_Product;
DROP TABLE IF EXISTS Shop_Product_Category_Temp;
DROP TABLE IF EXISTS Shop_Product_Category_Audit;
DROP TABLE IF EXISTS Shop_Product_Category;
DROP TABLE IF EXISTS Shop_Category_Audit;
@@ -214,3 +215,43 @@ DROP TABLE IF EXISTS Shop_Access_Level;
DROP TABLE IF EXISTS Shop_Sales_And_Purchasing_Change_Set;
DROP TABLE IF EXISTS Shop_User_Change_Set;
DROP TABLE IF EXISTS Shop_Product_Change_Set;
-- Procedures
DROP PROCEDURE IF EXISTS p_split;
DROP PROCEDURE IF EXISTS p_clear_split_temp;
DROP PROCEDURE IF EXISTS p_shop_user_eval;
DROP PROCEDURE IF EXISTS p_clear_shop_user_eval_temp;
DROP PROCEDURE IF EXISTS p_shop_get_many_region;
DROP PROCEDURE IF EXISTS p_shop_get_many_currency;
DROP PROCEDURE IF EXISTS p_shop_save_category;
DROP PROCEDURE IF EXISTS p_shop_save_product_category;
DROP PROCEDURE IF EXISTS p_shop_save_product_category_test;
DROP PROCEDURE IF EXISTS p_shop_save_product;
DROP PROCEDURE IF EXISTS p_shop_get_many_product;
DROP PROCEDURE IF EXISTS p_shop_get_many_stripe_product_new;
DROP PROCEDURE IF EXISTS p_shop_save_permutation;
DROP PROCEDURE IF EXISTS p_shop_get_many_product_variation;
DROP PROCEDURE IF EXISTS p_shop_get_many_stock_item;
DROP PROCEDURE IF EXISTS p_shop_get_many_product_price_and_discount_and_delivery_option;
DROP PROCEDURE IF EXISTS p_shop_get_many_product_price_and_discount_and_delivery_region;
DROP PROCEDURE IF EXISTS p_shop_get_many_stripe_price_new;
DROP PROCEDURE IF EXISTS p_shop_save_user;
DROP PROCEDURE IF EXISTS p_shop_edit_user;
DROP PROCEDURE IF EXISTS p_shop_get_many_user;
DROP PROCEDURE IF EXISTS p_get_many_user;
DROP PROCEDURE IF EXISTS p_shop_get_many_user_basket;
DROP PROCEDURE IF EXISTS p_shop_edit_user_basket;
DROP PROCEDURE IF EXISTS p_shop_save_supplier;
DROP PROCEDURE IF EXISTS p_shop_get_many_supplier;
DROP PROCEDURE IF EXISTS p_shop_save_supplier_purchase_order;
DROP PROCEDURE IF EXISTS p_shop_get_many_supplier_purchase_order;
DROP PROCEDURE IF EXISTS p_shop_save_manufacturing_purchase_order;
DROP PROCEDURE IF EXISTS p_shop_get_many_manufacturing_purchase_order;
DROP PROCEDURE IF EXISTS p_shop_save_customer;
DROP PROCEDURE IF EXISTS p_shop_get_many_customer;
DROP PROCEDURE IF EXISTS p_shop_save_customer_sales_order;
DROP PROCEDURE IF EXISTS p_shop_get_many_customer_sales_order;

View File

@@ -13,9 +13,11 @@ CREATE TABLE IF NOT EXISTS Shop_Access_Level (
active BIT NOT NULL DEFAULT 1,
display_order INT NOT NULL,
created_on TIMESTAMP,
created_by VARCHAR(100),
created_by INT,
id_change_set INT,
CONSTRAINT FK_Shop_Access_Level_id_change_set
FOREIGN KEY (id_change_set)
REFERENCES Shop_User_Change_Set(id_change_set)
);
);

View File

@@ -11,7 +11,7 @@ CREATE TABLE IF NOT EXISTS File_Type (
name VARCHAR(100),
extension VARCHAR(50),
created_on TIMESTAMP,
created_by VARCHAR(100),
created_by INT,
updated_last_on TIMESTAMP,
updated_last_by VARCHAR(100)
);

View File

@@ -16,7 +16,7 @@ CREATE TABLE IF NOT EXISTS File_Type_Audit (
value_prev VARCHAR(500),
value_new VARCHAR(500),
created_on TIMESTAMP,
created_by VARCHAR(100),
created_by INT,
updated_last_on TIMESTAMP,
updated_last_by VARCHAR(100)
);

View File

@@ -9,7 +9,7 @@ CREATE TABLE IF NOT EXISTS Shop_General (
id_general INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
quantity_max FLOAT,
created_on TIMESTAMP,
created_by VARCHAR(100),
created_by INT,
id_change_set INT,
CONSTRAINT CHK_Shop_General_id_change_set
FOREIGN KEY (id_change_set)

View File

@@ -19,7 +19,7 @@ CREATE TABLE IF NOT EXISTS Shop_Image_Type (
active BIT NOT NULL DEFAULT 1,
display_order INT NOT NULL,
created_on TIMESTAMP,
created_by VARCHAR(100),
created_by INT,
id_change_set INT,
CONSTRAINT FK_Shop_Image_Type_id_change_set
FOREIGN KEY (id_change_set)

View File

@@ -12,7 +12,7 @@ CREATE TABLE IF NOT EXISTS Shop_Region (
active BIT NOT NULL DEFAULT 1,
display_order INT NOT NULL,
created_on TIMESTAMP,
created_by VARCHAR(100),
created_by INT,
id_change_set INT,
CONSTRAINT FK_Shop_Region_id_change_set
FOREIGN KEY (id_change_set)

View File

@@ -12,7 +12,7 @@ CREATE TABLE IF NOT EXISTS Shop_Region_Temp (
active BIT NOT NULL DEFAULT 1,
display_order INT NOT NULL,
created_on TIMESTAMP,
created_by VARCHAR(100),
created_by INT,
id_change_set INT,
CONSTRAINT FK_Shop_Region_Temp_id_change_set
FOREIGN KEY (id_change_set)

View File

@@ -21,7 +21,7 @@ CREATE TABLE IF NOT EXISTS Shop_Region_Branch (
active BIT NOT NULL DEFAULT 1,
display_order INT NOT NULL,
created_on TIMESTAMP,
created_by VARCHAR(100),
created_by INT,
id_change_set INT,
CONSTRAINT FK_Shop_Region_Branch_id_change_set
FOREIGN KEY (id_change_set)

View File

@@ -13,7 +13,7 @@ CREATE TABLE IF NOT EXISTS Shop_Plant (
id_user_manager INT NOT NULL,
active BIT NOT NULL DEFAULT 1,
created_on TIMESTAMP,
created_by VARCHAR(100),
created_by INT,
id_change_set INT,
CONSTRAINT FK_Shop_Plant_id_change_set
FOREIGN KEY (id_change_set)

View File

@@ -15,7 +15,7 @@ CREATE TABLE IF NOT EXISTS Shop_Storage_Location (
name VARCHAR(500) NOT NULL,
active BIT NOT NULL DEFAULT 1,
created_on TIMESTAMP,
created_by VARCHAR(100),
created_by INT,
id_change_set INT,
CONSTRAINT FK_Shop_Storage_Location_id_change_set
FOREIGN KEY (id_change_set)

View File

@@ -21,7 +21,7 @@ CREATE TABLE IF NOT EXISTS Shop_Storage_Location_Branch (
active BIT NOT NULL DEFAULT 1,
display_order INT NOT NULL,
created_on TIMESTAMP,
created_by VARCHAR(100),
created_by INT,
id_change_set INT,
CONSTRAINT FK_Shop_Storage_Location_Branch_id_change_set
FOREIGN KEY (id_change_set)

View File

@@ -14,7 +14,7 @@ CREATE TABLE IF NOT EXISTS Shop_Currency (
active BIT NOT NULL DEFAULT 1,
display_order INT NOT NULL,
created_on TIMESTAMP,
created_by VARCHAR(100),
created_by INT,
id_change_set INT,
CONSTRAINT FK_Shop_Currency_id_change_set
FOREIGN KEY (id_change_set)

View File

@@ -30,7 +30,7 @@ CREATE TABLE Shop_Tax_Or_Surcharge (
active BIT NOT NULL DEFAULT 1,
display_order INT NOT NULL,
created_on TIMESTAMP,
created_by VARCHAR(100),
created_by INT,
id_change_set INT,
CONSTRAINT FK_Shop_Tax_Or_Surcharge_id_change_set
FOREIGN KEY (id_change_set)

Some files were not shown because too many files have changed in this diff Show More