Feat(SQL, UI): Button Icons page, Command Button Links page created with get and set functionality.
This commit is contained in:
82
business_objects/dog/deprecated/DEPRECATED - access_level.py
Normal file
82
business_objects/dog/deprecated/DEPRECATED - access_level.py
Normal file
@@ -0,0 +1,82 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Business Objects
|
||||
Feature: Product Category Business Object
|
||||
|
||||
Description:
|
||||
Business object for product
|
||||
"""
|
||||
|
||||
# internal
|
||||
import lib.argument_validation as av
|
||||
from business_objects.base import Base
|
||||
from extensions import db
|
||||
from helpers.helper_app import Helper_App
|
||||
# external
|
||||
from pydantic import BaseModel
|
||||
from typing import ClassVar
|
||||
|
||||
|
||||
class Access_Level(db.Model, Base):
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = Base.ATTR_ID_ACCESS_LEVEL
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = Base.FLAG_NAME
|
||||
__tablename__ = 'DOG_Access_Level_Temp'
|
||||
id_access_level = db.Column(db.Integer, primary_key=True)
|
||||
code = db.Column(db.String(50))
|
||||
name = db.Column(db.String(250))
|
||||
priority = db.Column(db.Integer)
|
||||
display_order = db.Column(db.Integer)
|
||||
active = db.Column(db.Boolean)
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
Base.__init__(self)
|
||||
@classmethod
|
||||
def from_DB_access_level(cls, query_row):
|
||||
access_level = cls()
|
||||
access_level.id_access_level = query_row[0]
|
||||
access_level.code = query_row[1]
|
||||
access_level.name = query_row[2]
|
||||
access_level.priority = query_row[3]
|
||||
access_level.display_order = query_row[4]
|
||||
access_level.active = query_row[5]
|
||||
return access_level
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
id: {self.id_access_level[0] if isinstance(self.id_access_level, tuple) else self.id_access_level}
|
||||
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}
|
||||
priority: {self.priority[0] if isinstance(self.priority, tuple) else self.priority}
|
||||
display_order: {self.display_order}
|
||||
active: {self.active}
|
||||
'''
|
||||
def to_json(self):
|
||||
return {
|
||||
**self.get_shared_json_attributes(self),
|
||||
self.ATTR_ID_ACCESS_LEVEL: self.id_access_level[0] if isinstance(self.id_access_level, tuple) else self.id_access_level,
|
||||
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_PRIORITY: self.priority[0] if isinstance(self.priority, tuple) else self.priority,
|
||||
self.FLAG_DISPLAY_ORDER: self.display_order,
|
||||
self.FLAG_ACTIVE: av.input_bool(self.active, self.FLAG_ACTIVE, f'{self.__class__.__name__}.to_json')
|
||||
}
|
||||
def to_json_option(self):
|
||||
return {
|
||||
'value': self.id_access_level,
|
||||
'text': self.name
|
||||
}
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
access_level = cls()
|
||||
access_level.id_access_level = json[cls.ATTR_ID_ACCESS_LEVEL],
|
||||
access_level.code = json[cls.FLAG_CODE],
|
||||
access_level.name = json[cls.FLAG_NAME],
|
||||
access_level.priority = json[cls.FLAG_PRIORITY],
|
||||
access_level.description = json[cls.FLAG_DESCRIPTION],
|
||||
access_level.display_order = json[cls.FLAG_DISPLAY_ORDER]
|
||||
access_level.active = json[cls.FLAG_ACTIVE]
|
||||
return access_level
|
||||
@@ -0,0 +1,136 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Business Objects
|
||||
Feature: Dog Command Link Container Business Object
|
||||
|
||||
Description:
|
||||
Business object for dog command link container
|
||||
|
||||
|
||||
DEPRECATED AS NOT REQUIRED - USE A LIST
|
||||
"""
|
||||
|
||||
# internal
|
||||
import lib.argument_validation as av
|
||||
from business_objects.base import Base
|
||||
from business_objects.db_base import SQLAlchemy_ABC, Get_Many_Parameters_Base
|
||||
from business_objects.dog.dog_command_link import Dog_Command_Link
|
||||
from extensions import db
|
||||
from helpers.helper_app import Helper_App
|
||||
# external
|
||||
from pydantic import BaseModel
|
||||
from typing import ClassVar
|
||||
|
||||
class Dog_Command_Link_Container(Base):
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = ''
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = Base.FLAG_ROWS
|
||||
categories: list
|
||||
def __init__(self):
|
||||
self.categories = []
|
||||
def add_dog_command_link(self, dog_command_link):
|
||||
av.val_instance(dog_command_link, 'dog_command_link', 'Dog_Command_Link_Container.add_dog_command_link', Dog_Command_Link)
|
||||
self.categories.append(dog_command_link)
|
||||
def get_index_category_from_id(self, id_category):
|
||||
for index_category in range(len(self.categories)):
|
||||
category = self.categories[index_category]
|
||||
if category.id_category == id_category:
|
||||
return index_category
|
||||
raise ValueError(f"{av.error_msg_str(id_category, 'id_category', 'Dog_Command_Link_Container.get_index_category_from_id', int)}\nID not in list")
|
||||
def get_index_category_from_id_permutation(self, id_permutation):
|
||||
for index_category in range(len(self.categories)):
|
||||
category = self.categories[index_category]
|
||||
try:
|
||||
index_product = category.get_index_product_from_id_permutation(id_permutation)
|
||||
return index_category
|
||||
except:
|
||||
pass
|
||||
raise ValueError(f"{av.error_msg_str(id_permutation, 'id_permutation', 'Dog_Command_Link_Container.get_index_category_from_id_permutation', int)}. Permutation ID not in list")
|
||||
def add_product(self, product):
|
||||
av.val_instance(product, 'product', 'Dog_Command_Link_Container.add_product', Product)
|
||||
index_category = self.get_index_category_from_id(product.id_category)
|
||||
self.categories[index_category].add_product(product)
|
||||
def add_product_permutation(self, permutation):
|
||||
av.val_instance(permutation, 'permutation', 'Dog_Command_Link_Container.add_product_permutation', Product_Permutation)
|
||||
index_category = self.get_index_category_from_id(permutation.id_category)
|
||||
self.categories[index_category].add_product_permutation(permutation)
|
||||
def add_product_variation_type(self, variation_type):
|
||||
av.val_instance(variation_type, 'variation_type', 'Dog_Command_Link_Container.add_product_variation_type', Product_Variation_Type)
|
||||
variation = variation_type.variations[0]
|
||||
index_category = self.get_index_category_from_id(variation.id_category)
|
||||
self.categories[index_category].add_product_variation_type(variation_type)
|
||||
def add_product_price(self, price):
|
||||
av.val_instance(price, 'price', 'Dog_Command_Link_Container.add_product_price', Product_Price)
|
||||
index_category = self.get_index_category_from_id(price.id_category)
|
||||
self.categories[index_category].add_product_price(price)
|
||||
def add_product_image(self, image):
|
||||
av.val_instance(image, 'image', 'Dog_Command_Link_Container.add_product_image', Image)
|
||||
index_category = self.get_index_category_from_id(image.id_category)
|
||||
self.categories[index_category].add_product_image(image)
|
||||
def add_delivery_option(self, delivery_option):
|
||||
av.val_instance(delivery_option, 'delivery_option', 'Dog_Command_Link_Container.add_delivery_option', Delivery_Option)
|
||||
index_category = self.get_index_category_from_id(delivery_option.id_category)
|
||||
self.categories[index_category].add_delivery_option(delivery_option)
|
||||
def add_product_price_discount(self, discount):
|
||||
av.val_instance(discount, 'discount', 'Dog_Command_Link_Container.add_product_price_discount', Discount)
|
||||
index_category = self.get_index_category_from_id(discount.id_category)
|
||||
self.categories[index_category].add_product_price_discount(discount)
|
||||
def add_stock_item(self, stock_item):
|
||||
av.val_instance(stock_item, 'stock_item', 'Dog_Command_Link_Container.add_stock_item', Stock_Item)
|
||||
index_category = self.get_index_category_from_id(stock_item.id_category)
|
||||
self.categories[index_category].add_stock_item(stock_item)
|
||||
def get_all_product_variation_trees(self):
|
||||
for category in self.categories:
|
||||
category.get_all_product_variation_trees()
|
||||
def __repr__(self):
|
||||
return f'categories: {self.categories}'
|
||||
def get_category_count(self):
|
||||
return len(self.categories)
|
||||
def to_permutation_row_list(self):
|
||||
list_rows = []
|
||||
for category in self.categories:
|
||||
list_rows += category.to_permutation_row_list()
|
||||
return list_rows
|
||||
def to_category_option_list(self):
|
||||
list_categories = []
|
||||
for category in self.categories:
|
||||
list_categories.append({'value': category.id_category, 'text': category.name})
|
||||
return list_categories
|
||||
def get_list_products(self):
|
||||
list_products = []
|
||||
for category in self.categories:
|
||||
list_products += category.products
|
||||
return list_products
|
||||
def to_product_option_list(self):
|
||||
list_products = self.get_list_products()
|
||||
return [{'value': product.id_product, 'text': product.name, Product.ATTR_ID_Dog_Command_Link: product.id_category} for product in list_products]
|
||||
def get_product_option_lists_by_category(self):
|
||||
dict_lists_products = {}
|
||||
for category in self.categories:
|
||||
dict_lists_products[category.id_category] = category.to_product_option_list()
|
||||
return dict_lists_products
|
||||
def to_json(self):
|
||||
return {
|
||||
**self.get_shared_json_attributes(self),
|
||||
f'{self.FLAG_ROWS}': [category.to_json() for category in self.categories]
|
||||
}
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
return None
|
||||
def to_json_option(self):
|
||||
return None
|
||||
def to_temporary_record(self):
|
||||
excluded_attributes = {
|
||||
column.name: getattr(self, column.name)
|
||||
for column in self.__table__.columns
|
||||
if column.name not in ['created_on', 'created_by']
|
||||
}
|
||||
return self.to_object_with_missing_attributes(excluded_attributes)
|
||||
def get_csv_ids_permutation(self):
|
||||
list_ids = []
|
||||
for category in self.categories:
|
||||
list_ids += category.get_csv_ids_permutation()
|
||||
return ','.join(list_ids)
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Business Objects
|
||||
Feature: Understanding Level Business Object
|
||||
"""
|
||||
|
||||
# internal
|
||||
from business_objects.base import Base
|
||||
from business_objects.db_base import SQLAlchemy_ABC
|
||||
import lib.argument_validation as av
|
||||
from extensions import db
|
||||
from helpers.helper_app import Helper_App
|
||||
# external
|
||||
from dataclasses import dataclass
|
||||
from typing import ClassVar
|
||||
|
||||
|
||||
class Understanding_Level(SQLAlchemy_ABC, Base):
|
||||
FLAG_UNDERSTANDING_LEVEL: ClassVar[str] = 'understanding-level'
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = FLAG_UNDERSTANDING_LEVEL
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = Base.FLAG_NAME
|
||||
|
||||
__tablename__ = 'DOG_Understanding_Level'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
|
||||
id_understanding_level = db.Column(db.Integer, primary_key=True)
|
||||
code = db.Column(db.String(250))
|
||||
name = db.Column(db.String(250))
|
||||
active = db.Column(db.Boolean)
|
||||
|
||||
def __init__(self):
|
||||
self.id_understanding_level = 0
|
||||
self.is_new = False
|
||||
super().__init__()
|
||||
|
||||
def from_db_dog_command_link(query_row):
|
||||
_m = 'Understanding_Level.from_db_dog_command_link'
|
||||
level = Understanding_Level()
|
||||
level.id_understanding_level = query_row[5]
|
||||
level.code = query_row[6]
|
||||
level.name = query_row[7]
|
||||
level.active = True
|
||||
return level
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
_m = 'Understanding_Level.from_json'
|
||||
understanding_level = cls()
|
||||
if json is None: return Understanding_Level
|
||||
Helper_App.console_log(f'{_m}\njson: {json}')
|
||||
understanding_level.id_understanding_level = -1
|
||||
understanding_level.code = json[cls.FLAG_CODE]
|
||||
understanding_level.name = json[cls.FLAG_NAME]
|
||||
understanding_level.active = json[cls.FLAG_ACTIVE]
|
||||
Helper_App.console_log(f'Understanding_Level: {understanding_level}')
|
||||
return understanding_level
|
||||
|
||||
|
||||
def to_json(self):
|
||||
as_json = {
|
||||
self.FLAG_UNDERSTANDING_LEVEL: self.id_understanding_level
|
||||
, self.FLAG_CODE: self.code
|
||||
, self.FLAG_NAME: self.name
|
||||
, self.FLAG_ACTIVE: self.active
|
||||
}
|
||||
Helper_App.console_log(f'as_json: {as_json}')
|
||||
return as_json
|
||||
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.__class__.__name__}(
|
||||
{self.FLAG_UNDERSTANDING_LEVEL}: {self.id_understanding_level}
|
||||
{self.FLAG_CODE}: {self.code}
|
||||
{self.FLAG_NAME}: {self.name}
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
)
|
||||
'''
|
||||
|
||||
|
||||
class Understanding_Level_Temp(db.Model, Base):
|
||||
__tablename__ = 'DOG_Understanding_Level_Temp'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_temp = db.Column(db.Integer, primary_key=True)
|
||||
id_understanding_level = db.Column(db.Integer)
|
||||
code = db.Column(db.String(250))
|
||||
name = db.Column(db.String(250))
|
||||
active = db.Column(db.Boolean)
|
||||
guid: str = db.Column(db.String(36))
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
@classmethod
|
||||
def from_understanding_level(cls, understanding_level):
|
||||
_m = 'Understanding_Level_Temp.from_Understanding_Level'
|
||||
temp = cls()
|
||||
temp.id_understanding_level = understanding_level.id_understanding_level
|
||||
temp.code = understanding_level.code
|
||||
temp.name = understanding_level.name
|
||||
temp.active = understanding_level.active
|
||||
return temp
|
||||
Reference in New Issue
Block a user