Fix: Clean up Python comments and deprecated js code.
This commit is contained in:
@@ -10,11 +10,6 @@ Description:
|
||||
Base data model for views
|
||||
"""
|
||||
|
||||
# IMPORTS
|
||||
# VARIABLE INSTANTIATION
|
||||
# METHODS
|
||||
|
||||
# IMPORTS
|
||||
# internal
|
||||
# from routes import bp_home
|
||||
from business_objects.base import Base
|
||||
@@ -36,8 +31,6 @@ from typing import ClassVar
|
||||
|
||||
|
||||
class Model_View_Base(BaseModel, ABC):
|
||||
# Global constants
|
||||
# ATTR_FOR: ClassVar[str] = 'for'
|
||||
ATTR_ID_ACCESS_LEVEL: ClassVar[str] = Base.ATTR_ID_ACCESS_LEVEL
|
||||
ATTR_ID_ADDRESS: ClassVar[str] = Base.ATTR_ID_ADDRESS
|
||||
ATTR_ID_CURRENCY: ClassVar[str] = Base.ATTR_ID_CURRENCY
|
||||
@@ -50,7 +43,6 @@ class Model_View_Base(BaseModel, ABC):
|
||||
FLAG_ACCESS_LEVEL_REQUIRED: ClassVar[str] = Product_Category.FLAG_ACCESS_LEVEL_REQUIRED
|
||||
FLAG_ACTIVE: ClassVar[str] = Base.FLAG_ACTIVE
|
||||
FLAG_ADD: ClassVar[str] = 'add'
|
||||
# FLAG_ADD_DELETE: ClassVar[str] = 'add-delete'
|
||||
FLAG_ADDRESS: ClassVar[str] = Base.FLAG_ADDRESS
|
||||
FLAG_ADDRESS_LINE_1: ClassVar[str] = Base.FLAG_ADDRESS_LINE_1
|
||||
FLAG_ADDRESS_LINE_2: ClassVar[str] = Base.FLAG_ADDRESS_LINE_2
|
||||
@@ -66,7 +58,6 @@ class Model_View_Base(BaseModel, ABC):
|
||||
FLAG_COLLAPSIBLE: ClassVar[str] = 'collapsible'
|
||||
FLAG_COLUMN: ClassVar[str] = 'column'
|
||||
FLAG_COMMENT: ClassVar[str] = 'comment'
|
||||
# FLAG_CONTACT_US: ClassVar[str] = 'button-contact'
|
||||
FLAG_CONTAINER: ClassVar[str] = 'container'
|
||||
FLAG_CONTAINER_ICON_AND_LABEL: ClassVar[str] = 'container-icon-label'
|
||||
FLAG_CONTAINER_INPUT: ClassVar[str] = FLAG_CONTAINER + '-input'
|
||||
@@ -79,7 +70,7 @@ class Model_View_Base(BaseModel, ABC):
|
||||
FLAG_DELETE: ClassVar[str] = 'delete'
|
||||
FLAG_DESCRIPTION: ClassVar[str] = Base.FLAG_DESCRIPTION
|
||||
FLAG_DETAIL: ClassVar[str] = 'detail'
|
||||
FLAG_DIALOG: ClassVar[str] = 'dialog' # try <dialog> element
|
||||
FLAG_DIALOG: ClassVar[str] = 'dialog'
|
||||
FLAG_DIRTY: ClassVar[str] = 'dirty'
|
||||
FLAG_DISPLAY_ORDER: ClassVar[str] = Base.FLAG_DISPLAY_ORDER
|
||||
FLAG_EDIT: ClassVar[str] = 'edit'
|
||||
@@ -140,7 +131,6 @@ class Model_View_Base(BaseModel, ABC):
|
||||
FLAG_TEMPORARY_ELEMENT: ClassVar[str] = 'temporary-element'
|
||||
FLAG_USER: ClassVar[str] = User.FLAG_USER
|
||||
FLAG_WEBSITE: ClassVar[str] = Base.FLAG_WEBSITE
|
||||
# flagIsDatePicker: ClassVar[str] = 'is-date-picker'
|
||||
HASH_APPLY_FILTERS_STORE_PRODUCT_PERMUTATION: ClassVar[str] = '/store/permutation_filter'
|
||||
HASH_CALLBACK_LOGIN: ClassVar[str] = '/callback-login'
|
||||
HASH_PAGE_ACCESSIBILITY_REPORT: ClassVar[str] = '/accessibility-report'
|
||||
@@ -153,7 +143,6 @@ class Model_View_Base(BaseModel, ABC):
|
||||
HASH_PAGE_LICENSE: ClassVar[str] = '/license'
|
||||
HASH_PAGE_PRIVACY_POLICY: ClassVar[str] = '/privacy-policy'
|
||||
HASH_PAGE_SERVICES: ClassVar[str] = '/services'
|
||||
# HASH_PAGE_STORE_ADMIN: ClassVar[str] = '/store/admin'
|
||||
HASH_PAGE_STORE_BASKET: ClassVar[str] = '/store/basket'
|
||||
HASH_PAGE_STORE_CUSTOMER_SALES_ORDERS: ClassVar[str] = '/store/customer_sales_orders'
|
||||
HASH_PAGE_STORE_HOME: ClassVar[str] = '/store'
|
||||
@@ -183,27 +172,6 @@ class Model_View_Base(BaseModel, ABC):
|
||||
ID_FORM_FILTERS: ClassVar[str] = 'formFilters'
|
||||
ID_FORM_IS_INCLUDED_VAT: ClassVar[str] = 'formIsIncludedVAT'
|
||||
ID_LABEL_ERROR: ClassVar[str] = 'labelError'
|
||||
"""
|
||||
ID_MODAL_SERVICES: ClassVar[str] = 'modalServices'
|
||||
ID_MODAL_TECHNOLOGIES: ClassVar[str] = 'modalTechnologies'
|
||||
ID_BUTTON_NAV_ADMIN_HOME: ClassVar[str] = 'navAdminHome'
|
||||
ID_BUTTON_NAV_ADMIN_STORE_STRIPE_PRICE: ClassVar[str] = 'navAdminStoreStripePrice'
|
||||
ID_BUTTON_NAV_ADMIN_STORE_STRIPE_PRODUCT: ClassVar[str] = 'navAdminStoreStripeProduct'
|
||||
# ID_BUTTON_NAV_CONTACT: ClassVar[str] = 'navContact'
|
||||
ID_BUTTON_NAV_HOME: ClassVar[str] = 'navHome'
|
||||
ID_BUTTON_NAV_SERVICES: ClassVar[str] = 'navServices'
|
||||
ID_BUTTON_NAV_STORE_HOME: ClassVar[str] = 'navStoreHome'
|
||||
ID_BUTTON_NAV_STORE_PRODUCT: ClassVar[str] = 'navStoreProduct'
|
||||
ID_BUTTON_NAV_STORE_PRODUCT_CATEGORIES: ClassVar[str] = 'navStoreProductCategories'
|
||||
ID_BUTTON_NAV_STORE_PRODUCT_PERMUTATIONS: ClassVar[str] = 'navStoreProductPermutations'
|
||||
ID_BUTTON_NAV_STORE_PRODUCT_PRICES: ClassVar[str] = 'navStoreProductPrices'
|
||||
ID_BUTTON_NAV_STORE_PRODUCT_VARIATIONS: ClassVar[str] = 'navStoreProductVariations'
|
||||
ID_BUTTON_NAV_STORE_STOCK_ITEMS: ClassVar[str] = 'navStoreStockItems'
|
||||
ID_BUTTON_NAV_USER_ACCOUNT: ClassVar[str] = 'navUserAccount'
|
||||
ID_BUTTON_NAV_USER_ADMIN: ClassVar[str] = 'navUserAdmin'
|
||||
ID_BUTTON_NAV_USER_LOGIN: ClassVar[str] = 'navUserLogin'
|
||||
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'
|
||||
@@ -216,19 +184,7 @@ class Model_View_Base(BaseModel, ABC):
|
||||
URL_GITHUB: ClassVar[str] = 'https://github.com/Teddy-1024'
|
||||
URL_LINKEDIN: ClassVar[str] = 'https://uk.linkedin.com/in/lordteddyms'
|
||||
|
||||
# Attributes
|
||||
"""
|
||||
is_user_logged_in: bool
|
||||
id_user: str
|
||||
form_is_included_VAT: Form_Is_Included_VAT
|
||||
form_delivery_region: Form_Delivery_Region
|
||||
form_currency: Form_Currency
|
||||
# app: Flask
|
||||
db: SQLAlchemy
|
||||
"""
|
||||
# """
|
||||
hash_page_current: str
|
||||
# """
|
||||
app: Flask = None
|
||||
session: None = None
|
||||
is_page_store: bool = None
|
||||
@@ -243,41 +199,11 @@ class Model_View_Base(BaseModel, ABC):
|
||||
def title(self):
|
||||
pass
|
||||
|
||||
"""
|
||||
def __new__(cls, db, info_user, app): # , *args, **kwargs
|
||||
# Initialiser - validation
|
||||
_m = 'Model_View_Base.__new__'
|
||||
v_arg_type = 'class attribute'
|
||||
Helper_App.console_log(f'{_m}\nstarting')
|
||||
# return super().__new__(cls, *args, **kwargs)
|
||||
av.val_instance(db, 'db', _m, SQLAlchemy, v_arg_type=v_arg_type)
|
||||
return super(Model_View_Base, cls).__new__(cls)
|
||||
"""
|
||||
def __init__(self, hash_page_current, **kwargs):
|
||||
# Constructor
|
||||
"""
|
||||
_m = 'Model_View_Base.__init__'
|
||||
v_arg_type = 'class attribute'
|
||||
Helper_App.console_log(f'{_m}\nstarting')
|
||||
av.val_instance(db, 'db', _m, SQLAlchemy, v_arg_type=v_arg_type)
|
||||
"""
|
||||
BaseModel.__init__(self, hash_page_current=hash_page_current, **kwargs)
|
||||
"""
|
||||
self.db = db
|
||||
self.session = session
|
||||
info_user = self.get_info_user()
|
||||
Helper_App.console_log(f'info_user: {info_user}\ntype: {str(type(info_user))}')
|
||||
self.is_user_logged_in = ('sub' in list(info_user.keys()) and not info_user['sub'] == '' and not str(type(info_user['sub'])) == "<class 'NoneType'?")
|
||||
Helper_App.console_log(f'is_user_logged_in: {self.is_user_logged_in}')
|
||||
self.id_user = info_user['sub'] if self.is_user_logged_in else ''
|
||||
self.app = app
|
||||
"""
|
||||
self.app = current_app
|
||||
with self.app.app_context():
|
||||
self.session = session
|
||||
# self.form_is_included_VAT = Form_Is_Included_VAT()
|
||||
# self.form_delivery_region = Form_Delivery_Region()
|
||||
# self.form_currency = Form_Currency()
|
||||
self.is_page_store = False
|
||||
Helper_App.console_log(f'session: {self.session}')
|
||||
|
||||
@@ -295,43 +221,13 @@ class Model_View_Base(BaseModel, ABC):
|
||||
def get_user_session(self):
|
||||
datastore_user = DataStore_User()
|
||||
return datastore_user.get_user_session()
|
||||
|
||||
"""
|
||||
def get_is_admin_store_user(self):
|
||||
datastore_store = DataStore_Store()
|
||||
user = datastore_store.get_user_session()
|
||||
if not user.is_logged_in: return False
|
||||
filters_user = Parameters_User.from_user(user) # get_default(datastore_store)
|
||||
users, errors = datastore_store.get_many_user(filters_user)
|
||||
try:
|
||||
user = users[0]
|
||||
return av.input_bool(user.can_admin_store, 'can_admin_store', 'Model_View_Base.get_is_admin_store_user')
|
||||
except:
|
||||
return False
|
||||
user = self.get_user_session()
|
||||
return user.can_admin_store
|
||||
|
||||
def get_is_admin_user_user(self):
|
||||
datastore_store = DataStore_Store()
|
||||
user = datastore_store.get_user_session()
|
||||
if not user.is_logged_in: return False
|
||||
filters_user = Parameters_User.from_user(user) # .get_default(datastore_store)
|
||||
users, errors = datastore_store.get_many_user(filters_user)
|
||||
try:
|
||||
user = users[0]
|
||||
return av.input_bool(user.can_admin_user, 'can_admin_user', 'Model_View_Base.get_is_admin_user_user')
|
||||
except:
|
||||
return False
|
||||
"""
|
||||
|
||||
def get_many_access_level(self, filters=None):
|
||||
_m = 'Model_View_Store.get_many_access_level'
|
||||
# av.val_instance(filters, 'filters', _m, Filters_Access_Level)
|
||||
access_levels, errors = DataStore_Base.get_many_access_level(filters)
|
||||
return access_levels
|
||||
def get_many_unit_measurement(self, filters=None):
|
||||
_m = 'Model_View_Store.get_many_unit_measurement'
|
||||
# av.val_instance(filters, 'filters', _m, Filters_Unit_Measurement)
|
||||
units_measurement, errors = DataStore_Base.get_many_unit_measurement(filters)
|
||||
return units_measurement
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ from abc import abstractproperty
|
||||
from pydantic import BaseModel
|
||||
|
||||
class Model_View_Contact(Model_View_Base):
|
||||
# Attributes
|
||||
ID_EMAIL: str = 'email'
|
||||
ID_MESSAGE: str = 'msg'
|
||||
ID_NAME: str = 'name'
|
||||
@@ -34,4 +33,3 @@ class Model_View_Contact(Model_View_Base):
|
||||
|
||||
def __init__(self, form_contact, hash_page_current=Model_View_Base.HASH_PAGE_CONTACT, **kwargs):
|
||||
super().__init__(hash_page_current=hash_page_current, form_contact=form_contact, **kwargs)
|
||||
# self.form = form
|
||||
|
||||
@@ -26,6 +26,5 @@ class Model_View_Services(Model_View_Base):
|
||||
return 'Services'
|
||||
|
||||
def __init__(self, hash_page_current=Model_View_Base.HASH_PAGE_SERVICES):
|
||||
# Constructor
|
||||
super().__init__(hash_page_current=hash_page_current)
|
||||
|
||||
@@ -10,24 +10,18 @@ Description:
|
||||
Parent data model for store views
|
||||
"""
|
||||
|
||||
# IMPORTS
|
||||
# VARIABLE INSTANTIATION
|
||||
# METHODS
|
||||
|
||||
# IMPORTS
|
||||
# internal
|
||||
# from context import models
|
||||
from business_objects.store.store_base import Store_Base
|
||||
from business_objects.store.product import Product, Parameters_Product, Product_Permutation # Product_Image_Filters,
|
||||
# from business_objects.store.product_category import Filters_Product_Category
|
||||
from business_objects.store.image import Resolution_Level_Enum
|
||||
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, Parameters_Product_Variation
|
||||
from business_objects.store.stock_item import Stock_Item
|
||||
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.forms import Form_Basket_Edit, Form_Is_Included_VAT, Form_Delivery_Region, Form_Currency
|
||||
from helpers.helper_app import Helper_App
|
||||
import lib.argument_validation as av
|
||||
@@ -41,7 +35,6 @@ from abc import abstractmethod
|
||||
|
||||
|
||||
class Model_View_Store(Model_View_Base):
|
||||
# Global constants
|
||||
ATTR_FORM_TYPE: ClassVar[str] = 'form-type'
|
||||
ATTR_ID_CUSTOMER: ClassVar[str] = 'id-customer'
|
||||
ATTR_ID_CUSTOMER_ADDRESS: ClassVar[str] = Store_Base.ATTR_ID_CUSTOMER_ADDRESS
|
||||
@@ -51,12 +44,12 @@ class Model_View_Store(Model_View_Base):
|
||||
ATTR_ID_MANUFACTURING_PURCHASE_ORDER: ClassVar[str] = Store_Base.ATTR_ID_MANUFACTURING_PURCHASE_ORDER
|
||||
ATTR_ID_MANUFACTURING_PURCHASE_ORDER_PRODUCT_LINK: ClassVar[str] = Store_Base.ATTR_ID_MANUFACTURING_PURCHASE_ORDER_PRODUCT_LINK
|
||||
ATTR_ID_PLANT: ClassVar[str] = 'id-plant'
|
||||
ATTR_ID_PRODUCT : ClassVar[str] = Product.ATTR_ID_PRODUCT # 'id-product'
|
||||
ATTR_ID_PRODUCT : ClassVar[str] = Product.ATTR_ID_PRODUCT
|
||||
ATTR_ID_PRODUCT_CATEGORY: ClassVar[str] = Product.ATTR_ID_PRODUCT_CATEGORY
|
||||
ATTR_ID_PRODUCT_PERMUTATION : ClassVar[str] = Product.ATTR_ID_PRODUCT_PERMUTATION # 'id-permutation'
|
||||
ATTR_ID_PRODUCT_PERMUTATION : ClassVar[str] = Product.ATTR_ID_PRODUCT_PERMUTATION
|
||||
ATTR_ID_PRODUCT_PRICE: ClassVar[str] = Product.ATTR_ID_PRODUCT_PRICE
|
||||
ATTR_ID_PRODUCT_VARIATION : ClassVar[str] = Product_Variation.ATTR_ID_PRODUCT_VARIATION # 'id-variation'
|
||||
ATTR_ID_PRODUCT_VARIATION_TYPE : ClassVar[str] = Product_Variation.ATTR_ID_PRODUCT_VARIATION_TYPE # 'id-variation-type'
|
||||
ATTR_ID_PRODUCT_VARIATION : ClassVar[str] = Product_Variation.ATTR_ID_PRODUCT_VARIATION
|
||||
ATTR_ID_PRODUCT_VARIATION_TYPE : ClassVar[str] = Product_Variation.ATTR_ID_PRODUCT_VARIATION_TYPE
|
||||
ATTR_ID_STOCK_ITEM: ClassVar[str] = Store_Base.ATTR_ID_STOCK_ITEM
|
||||
ATTR_ID_STORAGE_LOCATION: ClassVar[str] = Store_Base.ATTR_ID_STORAGE_LOCATION
|
||||
ATTR_ID_SUPPLIER: ClassVar[str] = Store_Base.ATTR_ID_SUPPLIER
|
||||
@@ -67,11 +60,6 @@ class Model_View_Store(Model_View_Base):
|
||||
ATTR_ID_UNIT_MEASUREMENT_QUANTITY: ClassVar[str] = Product_Permutation.ATTR_ID_UNIT_MEASUREMENT_QUANTITY
|
||||
FLAG_BUTTON_BASKET_ADD : ClassVar[str] = Model_View_Base.FLAG_SUBMIT + '.buttonAddToBasket'
|
||||
FLAG_BUTTON_BUY_NOW : ClassVar[str] = 'buttonBuyNow'
|
||||
"""
|
||||
FLAG_COST_LOCAL: ClassVar[str] = Store_Base.FLAG_COST_LOCAL
|
||||
FLAG_COST_LOCAL_VAT_EXCL: ClassVar[str] = Store_Base.FLAG_COST_LOCAL_VAT_EXCL
|
||||
FLAG_COST_LOCAL_VAT_INCL: ClassVar[str] = Store_Base.FLAG_COST_LOCAL_VAT_INCL
|
||||
"""
|
||||
FLAG_COST_TOTAL_LOCAL_VAT_EXCL: ClassVar[str] = Store_Base.FLAG_COST_TOTAL_LOCAL_VAT_EXCL
|
||||
FLAG_COST_TOTAL_LOCAL_VAT_INCL: ClassVar[str] = Store_Base.FLAG_COST_TOTAL_LOCAL_VAT_INCL
|
||||
FLAG_COST_UNIT_LOCAL_VAT_EXCL: ClassVar[str] = Store_Base.FLAG_COST_UNIT_LOCAL_VAT_EXCL
|
||||
@@ -121,11 +109,11 @@ class Model_View_Store(Model_View_Base):
|
||||
FLAG_PRODUCT_VARIATION_TYPE: ClassVar[str] = Store_Base.FLAG_PRODUCT_VARIATION_TYPE
|
||||
FLAG_PROFIT_LOCAL_MIN: ClassVar[str] = Product_Permutation.FLAG_PROFIT_LOCAL_MIN
|
||||
FLAG_QUANTITY: ClassVar[str] = 'quantity'
|
||||
FLAG_QUANTITY_MAX: ClassVar[str] = Product_Permutation.FLAG_QUANTITY_MAX # 'quantity-max'
|
||||
FLAG_QUANTITY_MIN: ClassVar[str] = Product_Permutation.FLAG_QUANTITY_MIN # 'quantity-min'
|
||||
FLAG_QUANTITY_MAX: ClassVar[str] = Product_Permutation.FLAG_QUANTITY_MAX
|
||||
FLAG_QUANTITY_MIN: ClassVar[str] = Product_Permutation.FLAG_QUANTITY_MIN
|
||||
FLAG_QUANTITY_ORDERED: ClassVar[str] = Store_Base.FLAG_QUANTITY_ORDERED
|
||||
FLAG_QUANTITY_RECEIVED: ClassVar[str] = Store_Base.FLAG_QUANTITY_RECEIVED
|
||||
FLAG_QUANTITY_STOCK: ClassVar[str] = Product_Permutation.FLAG_QUANTITY_STOCK # 'quantity-stock'
|
||||
FLAG_QUANTITY_STOCK: ClassVar[str] = Product_Permutation.FLAG_QUANTITY_STOCK
|
||||
FLAG_REGION: ClassVar[str] = Store_Base.FLAG_REGION
|
||||
FLAG_STOCK_ITEM: ClassVar[str] = Store_Base.FLAG_STOCK_ITEM
|
||||
FLAG_STORAGE_LOCATION: ClassVar[str] = Store_Base.FLAG_STORAGE_LOCATION
|
||||
@@ -175,321 +163,46 @@ class Model_View_Store(Model_View_Base):
|
||||
ID_BUTTON_BASKET_ADD : ClassVar[str] = 'buttonBasketAdd'
|
||||
ID_BUTTON_BUY_NOW : ClassVar[str] = 'buttonBuyNow'
|
||||
ID_BUTTON_CHECKOUT : ClassVar[str] = 'buttonCheckout'
|
||||
ID_CURRENCY : ClassVar[str] = Form_Currency.id_id_currency # 'id_currency'
|
||||
ID_CURRENCY : ClassVar[str] = Form_Currency.id_id_currency
|
||||
ID_CURRENCY_DEFAULT : ClassVar[str] = 1
|
||||
ID_LABEL_BASKET_EMPTY : ClassVar[str] = 'basketEmpty'
|
||||
ID_PRODUCT_CATEGORY_DEFAULT: ClassVar[str] = 1
|
||||
ID_REGION_DELIVERY_DEFAULT : ClassVar[str] = 1
|
||||
IS_INCLUDED_VAT_DEFAULT : ClassVar[str] = True
|
||||
"""
|
||||
KEY_BASKET : ClassVar[str] = Basket.KEY_BASKET # 'basket'
|
||||
# KEY_CODE_CURRENCY : ClassVar[str] = 'code_currency'
|
||||
KEY_ID_CURRENCY : ClassVar[str] = Basket.KEY_ID_CURRENCY # 'id_currency'
|
||||
KEY_ID_PRODUCT : ClassVar[str] = 'product_id'
|
||||
KEY_ID_PERMUTATION : ClassVar[str] = 'permutation_id'
|
||||
KEY_ID_REGION_DELIVERY : ClassVar[str] = Basket.KEY_ID_REGION_DELIVERY # 'id_region_delivery'
|
||||
KEY_IS_INCLUDED_VAT : ClassVar[str] = Basket.KEY_IS_INCLUDED_VAT # 'is_included_VAT'
|
||||
KEY_ITEMS : ClassVar[str] = Basket.KEY_ITEMS # 'items'
|
||||
KEY_PRICE : ClassVar[str] = 'price'
|
||||
KEY_QUANTITY : ClassVar[str] = 'quantity'
|
||||
KEY_VALUE_DEFAULT : ClassVar[str] = 'default'
|
||||
"""
|
||||
TYPE_FORM_BASKET_ADD : ClassVar[str] = 'Form_Basket_Add'
|
||||
TYPE_FORM_BASKET_EDIT : ClassVar[str] = 'Form_Basket_Edit'
|
||||
# development variables
|
||||
# valid_product_id_list = ['prod_PB0NUOSEs06ymG']
|
||||
|
||||
# Attributes
|
||||
# id_user: str
|
||||
# db: SQLAlchemy
|
||||
# basket: Basket # list # dict
|
||||
# basket_total: float
|
||||
"""
|
||||
id_currency: bool
|
||||
id_region_delivery: bool
|
||||
is_included_VAT: bool
|
||||
show_delivery_option: bool # for checkout page
|
||||
"""
|
||||
"""
|
||||
def __new__(cls, db, info_user, app, id_currency, id_region_delivery, is_included_VAT): # , *args, **kwargs``
|
||||
# Initialiser - validation
|
||||
_m = 'Model_View_Store.__new__'
|
||||
v_arg_type = 'class attribute'
|
||||
Helper_App.console_log(f'{_m}\nstarting')
|
||||
# av.val_str(id_user, 'id_user', _m)
|
||||
# return super().__new__(cls, *args, **kwargs)
|
||||
# cls.FLAG_BUTTON_BASKET_ADD = cls.FLAG_BUTTON_SUBMIT + '.buttonAddToBasket'
|
||||
return super().__new__(cls, db, info_user, app) # Model_View_Store, cls
|
||||
"""
|
||||
|
||||
@property
|
||||
def title(self):
|
||||
raise NotImplementedError('title must be implemented in child class')
|
||||
|
||||
def __init__(self, hash_page_current, **kwargs): # , id_currency, id_region_delivery, is_included_VAT):
|
||||
# Constructor
|
||||
def __init__(self, hash_page_current, **kwargs):
|
||||
_m = 'Model_View_Store.__init__'
|
||||
Helper_App.console_log(f'{_m}\nstarting')
|
||||
super().__init__(hash_page_current=hash_page_current, **kwargs)
|
||||
self.is_page_store = True
|
||||
"""
|
||||
self.basket = Basket(id_currency, id_region_delivery, is_included_VAT)
|
||||
# self.basket_total = 0
|
||||
# self.db = db
|
||||
# if logged in:
|
||||
# else:
|
||||
self.id_currency = id_currency
|
||||
self.id_region_delivery = id_region_delivery
|
||||
self.is_included_VAT = is_included_VAT
|
||||
self.show_delivery_option = True
|
||||
self.form_is_included_VAT = Form_Is_Included_VAT()
|
||||
regions, currencies = self.get_many_region_and_currency()
|
||||
self.form_currency = Form_Currency(id_currency=self.id_currency)
|
||||
self.form_currency.id_currency.choices = [(currency.id_currency, f'{currency.code} - {currency.name}') for currency in currencies]
|
||||
self.form_currency.id_currency.data = str(self.id_currency) if len(currencies) > 0 else None
|
||||
self.form_delivery_region = Form_Delivery_Region(id_region_delivery=self.id_region_delivery)
|
||||
self.form_delivery_region.id_region_delivery.choices = [(region.id_region, f'{region.code} - {region.name}') for region in regions]
|
||||
self.form_delivery_region.id_region_delivery.data = str(self.id_region_delivery) if len(regions) > 0 else None
|
||||
"""
|
||||
|
||||
def get_many_product(self, product_filters): # category_ids = '', product_ids = '', get_all_category = True, get_all_product = True, max_products_per_category = -1):
|
||||
def get_many_product(self, product_filters):
|
||||
_m = 'Model_View_Store.get_many_product'
|
||||
av.val_instance(product_filters, 'product_filters', _m, Parameters_Product)
|
||||
"""
|
||||
av.val_str(category_ids, 'category_ids', _m)
|
||||
av.val_str(product_ids, 'product_ids', _m)
|
||||
av.val_bool(get_all_category, 'get_all_category', _m)
|
||||
av.val_bool(get_all_product, 'get_all_product', _m)
|
||||
av.val_int(max_products_per_category, 'max_products_per_category', _m)
|
||||
"""
|
||||
# get products from database
|
||||
# call datastore method
|
||||
# return [Product.template()]
|
||||
self.category_list, errors = DataStore_Store_Base().get_many_product(product_filters) # category_ids, product_ids, get_all_category, get_all_product, max_products_per_category)
|
||||
# self.categories = categories
|
||||
# self.category_index = category_index
|
||||
|
||||
return
|
||||
if get_all_category or get_all_product:
|
||||
prod = Product.template()
|
||||
prod_list = [ prod, prod ]
|
||||
return { 'MISCELLANEOUS': prod_list if max_products_per_category < 0 else prod_list[:max_products_per_category] }
|
||||
if product_ids == 'panties123':
|
||||
prod = Product.template()
|
||||
return { 'MISCELLANEOUS': [ prod] }
|
||||
|
||||
# def product_category_getMany(self, category_ids = '', product_ids = '', get_all_category = True, get_all_product = True):
|
||||
# return Model_View_Store.product_category_getMany(category_ids, product_ids, get_all_category, get_all_product)
|
||||
self.category_list, errors = DataStore_Store_Base().get_many_product(product_filters)
|
||||
|
||||
def get_many_product_image_src(self, product_id, image_ids = '', get_primary_only = True, resolution_level = ''):
|
||||
_m = 'Model_View_Store.get_many_product_image'
|
||||
# Helper_App.console_log(f'{_m}\n')
|
||||
# av.val_instance(filters, 'filters', _m, Product_Image_Filters)
|
||||
av.val_int(product_id, 'product_id', _m)
|
||||
# av.full_val_int(product_id, 'product_id', _m)
|
||||
# product_id = int(product_id)
|
||||
av.val_str(image_ids, 'image_ids', _m)
|
||||
av.full_val_bool(get_primary_only, 'get_primary_only', _m)
|
||||
get_primary_only = bool(get_primary_only)
|
||||
resolution_level = Resolution_Level_Enum.get_member_by_text(resolution_level)
|
||||
av.val_instance(resolution_level, 'resolution_level', _m, Resolution_Level_Enum)
|
||||
# if (filters.product_id < 0 or filters.product_id not in self.valid_product_id_list):
|
||||
if (product_id not in Model_View_Store.valid_product_id_list): # product_id < 0 or
|
||||
if (product_id not in Model_View_Store.valid_product_id_list):
|
||||
return ''
|
||||
path_suffix = 'jpg' # get_suffix_from_product_id(product_id)
|
||||
path_suffix = 'jpg'
|
||||
path_file = f'/static/images/{product_id}.{path_suffix}'
|
||||
return path_file
|
||||
# return send_file(path_file, mimetype=f'image/{path_suffix}')
|
||||
|
||||
"""
|
||||
def get_product_category_text(self, category):
|
||||
return Enum_Product_Product_Category.get_member_by_text(category).text()
|
||||
|
||||
def add_2_basket(product_id, quantity, basket_local):
|
||||
_m = 'Model_View_Store.add_2_basket'
|
||||
av.full_val_int(product_id, 'product_id', _m)
|
||||
product_id = str(product_id)
|
||||
av.full_val_int(quantity, 'quantity', _m)
|
||||
quantity = int(quantity)
|
||||
av.val_instance(basket_local, 'basket_local', _m, dict)
|
||||
# send to database
|
||||
|
||||
# update basket on webpage with new database status
|
||||
if product_id in basket_local:
|
||||
basket_local[product_id] += quantity
|
||||
else:
|
||||
basket_local[product_id] = quantity
|
||||
return basket_local // jsonify(basket_local)
|
||||
"""
|
||||
|
||||
|
||||
def basket_item_edit(self, permutation_id, quantity, quantity_sum_not_replace):
|
||||
_m = 'Model_View_Store.basket_item_edit'
|
||||
# av.full_val_int(product_id, 'product_id', _m)
|
||||
# product_id = int(product_id)
|
||||
# av.val_instance(db, 'db', _m, SQLAlchemy)
|
||||
Helper_App.console_log(f'{_m} starting')
|
||||
# Helper_App.console_log(f'product_id: {product_id}\npermutation_id: {permutation_id}\nquantity = {quantity}')
|
||||
# av.full_val_int(product_id, 'product_id', _m)
|
||||
# Helper_App.console_log('valid product id')
|
||||
av.full_val_int(quantity, 'quantity', _m)
|
||||
quantity = int(quantity)
|
||||
# item_added = False
|
||||
Helper_App.console_log(f'basket: {self.basket}')
|
||||
ids_permutation, quantities_permutation = self.basket.to_csv()
|
||||
self.basket = DataStore_Store_Basket().edit_basket(ids_permutation, quantities_permutation, permutation_id, quantity, quantity_sum_not_replace, self.id_currency, self.id_region_delivery, self.is_included_VAT)
|
||||
return True
|
||||
|
||||
def get_basket(self, json_data):
|
||||
self.import_JSON_basket(json_data)
|
||||
if self.is_user_logged_in:
|
||||
ids_permutation, quantities_permutation = self.basket.to_csv()
|
||||
self.basket = DataStore_Store_Basket().edit_basket(ids_permutation, quantities_permutation, None, None, None, self.id_currency, self.id_region_delivery, self.is_included_VAT)
|
||||
# return self.basket
|
||||
|
||||
def _get_json_basket_id_CSVs_product_permutation(self, basket):
|
||||
product_ids = ''
|
||||
permutation_ids = ''
|
||||
item_index_dict = {}
|
||||
if len(basket) > 0:
|
||||
for index_item in range(len(basket)):
|
||||
if index_item > 0:
|
||||
product_ids += ','
|
||||
permutation_ids += ','
|
||||
basket_item = basket[index_item]
|
||||
id_product = basket_item[self.KEY_ID_PRODUCT]
|
||||
id_permutation = basket_item[self.KEY_ID_PERMUTATION]
|
||||
id_permutation = '' if (id_permutation is None or id_permutation == 'None') else str(id_permutation)
|
||||
product_ids += str(id_product) # str(basket[b].product.id)
|
||||
permutation_ids += id_permutation # str(basket[b].product.id)
|
||||
# item_index_dict[Basket.get_key_product_index_from_ids_product_permutation(id_product, id_permutation)] = index_item
|
||||
item_index_dict[id_permutation] = index_item
|
||||
Helper_App.console_log(f'product_ids = {product_ids}')
|
||||
Helper_App.console_log(f'permutation_ids = {permutation_ids}')
|
||||
return product_ids, permutation_ids, item_index_dict
|
||||
|
||||
def _get_basket_from_json(self, json_data):
|
||||
basket = json_data[self.KEY_BASKET]['items']
|
||||
av.val_instance(basket, 'basket', 'Model_View_Store._get_basket_from_json', list)
|
||||
Helper_App.console_log(f'basket = {basket}')
|
||||
return basket
|
||||
|
||||
def import_JSON_basket(self, json_data):
|
||||
_m = 'Model_View_Store.import_JSON_basket'
|
||||
# av.val_instance(db, 'db', _m, SQLAlchemy)
|
||||
items = self._get_basket_from_json(json_data)
|
||||
basket = json_data[self.KEY_BASKET]
|
||||
id_currency = basket[self.KEY_ID_CURRENCY]
|
||||
id_region_delivery = basket[self.KEY_ID_REGION_DELIVERY]
|
||||
is_included_VAT = basket[self.KEY_IS_INCLUDED_VAT]
|
||||
Helper_App.console_log(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(Parameters_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
|
||||
False, permutation_ids, False, # :a_get_all_permutation, :a_ids_permutation, :a_get_inactive_permutation
|
||||
False, '', False, True, # :a_get_all_image, :a_ids_image, :a_get_inactive_image, :a_get_first_image_only
|
||||
False, str(id_region_delivery), False, # :a_get_all_delivery_region, :a_ids_delivery_region, :a_get_inactive_delivery_region
|
||||
False, str(id_currency), False, # :a_get_all_currency, :a_ids_currency, :a_get_inactive_currency
|
||||
True, '', False # :a_get_all_discount, :a_ids_discount, :a_get_inactive_discount
|
||||
)) # product_ids=product_ids, get_all_category=False, get_all_product=False)
|
||||
# Helper_App.console_log(f'categories = {categories}')
|
||||
self.basket = Basket(id_currency, id_region_delivery, is_included_VAT)
|
||||
if len(category_list.categories) > 0: # not (categories is None):
|
||||
for category in category_list.categories:
|
||||
for product in category.products:
|
||||
# product = Product.from_json(items[index_item])
|
||||
product.form_basket_edit = Form_Basket_Edit()
|
||||
# key_index_product = Basket.get_key_product_index_from_ids_product_permutation(product.id_product, product.get_id_permutation())
|
||||
permutation = product.get_permutation_selected()
|
||||
self.basket.add_item(Basket_Item.from_product_and_quantity_and_VAT_included(product, items[item_index_dict[str(permutation.id_permutation)]][self.KEY_QUANTITY], self.is_included_VAT))
|
||||
"""
|
||||
if len(items) > 0:
|
||||
for index_item in range(len(items)):
|
||||
"""
|
||||
Helper_App.console_log(f'basket data: {json_data}')
|
||||
Helper_App.console_log(f'basket: {self.basket}')
|
||||
|
||||
# ids_permutation_unavailable_region_or_currency = []
|
||||
# id_permutation_unavailable_otherwise = []
|
||||
if len(errors) > 0:
|
||||
for error in errors:
|
||||
if error[1] == 'PRODUCT_AVAILABILITY':
|
||||
ids_permutation = DataStore_Store_Base.get_ids_permutation_from_error_availability(error[2])
|
||||
for id_permutation in ids_permutation:
|
||||
for item in self.basket.items:
|
||||
permutation = item.product.get_permutation_selected()
|
||||
if id_permutation == permutation.id_permutation:
|
||||
item.is_available = False
|
||||
if 'region' in error[2] or 'currency' in error[2]:
|
||||
item.is_unavailable_in_currency_or_region = True
|
||||
# ids_permutation_unavailable_region_or_currency.append(id_permutation)
|
||||
# else:
|
||||
# for id_permutation in ids_permutation:
|
||||
# id_permutation_unavailable_otherwise.append(id_permutation)
|
||||
"""
|
||||
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(Parameters_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
|
||||
False, ','.join(ids_permutation_unavailable), False, # :a_get_all_permutation, :a_ids_permutation, :a_get_inactive_permutation
|
||||
False, '', False, True, # :a_get_all_image, :a_ids_image, :a_get_inactive_image, :a_get_first_image_only
|
||||
True, '', False, # :a_get_all_delivery_region, :a_ids_delivery_region, :a_get_inactive_delivery_region
|
||||
True, '', False, # :a_get_all_currency, :a_ids_currency, :a_get_inactive_currency
|
||||
True, '', False # :a_get_all_discount, :a_ids_discount, :a_get_inactive_discount
|
||||
)) # product_ids=product_ids, get_all_category=False, get_all_product=False)
|
||||
else:
|
||||
category_list_unavailable = None
|
||||
errors_unavailable = []
|
||||
"""
|
||||
|
||||
|
||||
def import_JSON_basket_item(self, json_data, form_basket = None):
|
||||
_m = 'Model_View_Store.import_JSON_basket_item'
|
||||
Helper_App.console_log(f'starting {_m}')
|
||||
# Helper_App.console_log('getting product id')
|
||||
# product_id = av.input_int(json_data[self.key_id_product], self.key_id_product, _m)
|
||||
|
||||
# Helper_App.console_log(f'product id: {product_id}, type: {str(type(product_id))}')
|
||||
try:
|
||||
permutation_id = json_data[self.KEY_ID_PERMUTATION]
|
||||
av.full_val_int(permutation_id, self.KEY_ID_PERMUTATION, _m)
|
||||
permutation_id = int(permutation_id)
|
||||
except:
|
||||
permutation_id = None
|
||||
if not permutation_id == 'None':
|
||||
Helper_App.console_log(f'permutation_id invalid: {permutation_id}')
|
||||
raise ValueError("Invalid permutation id")
|
||||
Helper_App.console_log(f'permutation_id: {permutation_id}')
|
||||
|
||||
try:
|
||||
Helper_App.console_log(f'form_basket: {form_basket}')
|
||||
Helper_App.console_log('getting quantity')
|
||||
Helper_App.console_log(f'form_basket.quantity: {form_basket.quantity}')
|
||||
Helper_App.console_log(f'form_basket.quantity.data: {form_basket.quantity.data}')
|
||||
quantity = int(form_basket.quantity.data)
|
||||
except:
|
||||
quantity = 0
|
||||
Helper_App.console_log(f'quantity: {quantity}')
|
||||
|
||||
Helper_App.console_log(f'permutation_id: {permutation_id}\nquantity: {quantity}')
|
||||
|
||||
return permutation_id, quantity
|
||||
|
||||
def output_basket_total(self):
|
||||
return self.basket.output_total()
|
||||
|
||||
|
||||
def init_forms_basket_add(self):
|
||||
for cat in self.categories:
|
||||
c = self.category_index
|
||||
|
||||
def get_many_user_order(self, ids_order, n_order_max, id_checkout_session):
|
||||
# _m = 'Model_View_Store.get_many_user_order'
|
||||
# av.val_str(id_user)
|
||||
# validation conducted by server
|
||||
return DataStore_User().get_many_user_order(self.info_user['sub'], ids_order, n_order_max, id_checkout_session)
|
||||
|
||||
def get_many_plant(self, get_inactive = False):
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: View Models
|
||||
Feature: Store Basket View Model
|
||||
|
||||
Description:
|
||||
Data model for store basket view
|
||||
"""
|
||||
|
||||
# IMPORTS
|
||||
# VARIABLE INSTANTIATION
|
||||
# METHODS
|
||||
|
||||
# IMPORTS
|
||||
# internal
|
||||
from models.model_view_store import Model_View_Store
|
||||
# from routes import bp_home
|
||||
from business_objects.store.product import Product
|
||||
from forms.forms import Form_Billing # Form_Product
|
||||
# external
|
||||
|
||||
|
||||
# VARIABLE INSTANTIATION
|
||||
|
||||
|
||||
# CLASSES
|
||||
class Model_View_Store_Basket(Model_View_Store):
|
||||
# Attributes
|
||||
# product_categories: list # (str)
|
||||
form_delivery: Form_Billing
|
||||
form_billing: Form_Billing
|
||||
forms_delivery_method: list # []
|
||||
is_collapsed_info_billing: bool
|
||||
is_collapsed_info_delivery: bool
|
||||
# Global constants
|
||||
# category_products: dict { category_enum_id: List[Product] }
|
||||
hash_page_store_checkout = '/store/checkout'
|
||||
hash_page_store_checkout_session = '/store/checkout_session'
|
||||
hash_store_basket_info = '/store/basket_info'
|
||||
id_container_info_billing = 'containerInfoBilling'
|
||||
id_container_info_delivery = 'containerInfoDelivery'
|
||||
id_overlay_info_delivery = 'overlayInfoDelivery'
|
||||
id_overlay_info_billing = 'overlayInfoBilling'
|
||||
key_address1 = 'address_1'
|
||||
key_address2 = 'address_2'
|
||||
key_city = 'city'
|
||||
key_county = 'county'
|
||||
key_id_checkout = 'checkout-session-id'
|
||||
key_info_billing = 'billing-info'
|
||||
key_info_delivery = 'delivery-info'
|
||||
key_info_identical = 'identical'
|
||||
key_info_type = 'type-info'
|
||||
key_is_subscription = 'is-subscription'
|
||||
key_name_full = 'name_full'
|
||||
key_phone_number = 'phone_number'
|
||||
key_postcode = 'postcode'
|
||||
key_region = 'region'
|
||||
key_url_checkout = 'checkout-url'
|
||||
|
||||
# Attributes
|
||||
@property
|
||||
def title(self):
|
||||
return 'Store Basket'
|
||||
|
||||
def __init__(self, id_currency, id_region_delivery, is_included_VAT, hash_page_current=Model_View_Store.HASH_PAGE_STORE_BASKET):
|
||||
# Constructor
|
||||
super().__init__(hash_page_current=hash_page_current, id_currency=id_currency, id_region_delivery=id_region_delivery, is_included_VAT=is_included_VAT)
|
||||
# self.product_categories = Model_View_Store_Basket.get_many_product(get_all_category = True, get_all_product = True)
|
||||
self.form_billing = Form_Billing()
|
||||
self.form_billing.form_type_billing_not_delivery = True
|
||||
self.form_delivery = Form_Billing()
|
||||
# if logged in:
|
||||
# else:
|
||||
self.is_collapsed_info_billing = False
|
||||
self.is_collapsed_info_delivery = False
|
||||
"""
|
||||
self.forms_product = {}
|
||||
for cat in self.product_categories:
|
||||
for product in cat:
|
||||
if len(list(product.variations.keys())) == 0:
|
||||
new_form = Form_Product()
|
||||
if new_form.validate_on_submit():
|
||||
# Handle form submission
|
||||
self.add_2_basket(product.id, )
|
||||
self.forms[str(product.id)] = new_form
|
||||
"""
|
||||
@@ -1,71 +0,0 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: View Models
|
||||
Feature: Store Checkout View Model
|
||||
|
||||
Description:
|
||||
Data model for store checkout view
|
||||
"""
|
||||
|
||||
# IMPORTS
|
||||
# VARIABLE INSTANTIATION
|
||||
# METHODS
|
||||
|
||||
# IMPORTS
|
||||
# internal
|
||||
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.forms import Form_Billing # Form_Product
|
||||
import lib.argument_validation as av
|
||||
# from datastores.datastore_store_base import DataStore_Store
|
||||
# external
|
||||
import os
|
||||
import stripe
|
||||
|
||||
# VARIABLE INSTANTIATION
|
||||
|
||||
|
||||
# CLASSES
|
||||
class Model_View_Store_Checkout(Model_View_Store_Basket):
|
||||
# Attributes
|
||||
key_secret_stripe: str
|
||||
key_public_stripe: str
|
||||
# Global constants
|
||||
key_id_price = 'price_id'
|
||||
@property
|
||||
def title(self):
|
||||
return 'Store Checkout'
|
||||
|
||||
def __init__(self, id_currency, id_region_delivery, is_included_VAT, hash_page_current=Model_View_Store.HASH_PAGE_STORE_CHECKOUT):
|
||||
# Constructor
|
||||
super().__init__(hash_page_current=hash_page_current, id_currency=id_currency, id_region_delivery=id_region_delivery, is_included_VAT=is_included_VAT)
|
||||
self.key_secret_stripe = os.environ.get("KEY_SECRET_STRIPE")
|
||||
self.key_public_stripe = os.environ.get("KEY_PUBLIC_STRIPE")
|
||||
|
||||
# For sample support and debugging, not required for production:
|
||||
stripe.set_app_info(
|
||||
'stripe-samples/checkout-one-time-payments',
|
||||
version='0.0.1',
|
||||
url='https://github.com/stripe-samples/checkout-one-time-payments')
|
||||
|
||||
stripe.api_key = self.key_secret_stripe
|
||||
|
||||
|
||||
"""
|
||||
def create_product(self, product): # _name, product_description):
|
||||
return DataStore_Store().create_product(product) # _name, product_description)
|
||||
|
||||
def create_price(self, product, currency):
|
||||
return DataStore_Store().create_price(product, currency)
|
||||
|
||||
def get_many_product_new(self):
|
||||
return DataStore_Store().get_many_product_new()
|
||||
|
||||
def get_price_id(product_ids):
|
||||
return DataStore_Store().get_many_id_price(product_ids)
|
||||
"""
|
||||
@@ -1,49 +0,0 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: View Models
|
||||
Feature: Store Checkout Success View Model
|
||||
|
||||
Description:
|
||||
Data model for store checkout success view
|
||||
"""
|
||||
|
||||
# IMPORTS
|
||||
# VARIABLE INSTANTIATION
|
||||
# METHODS
|
||||
|
||||
# IMPORTS
|
||||
# internal
|
||||
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.forms import Form_Billing # Form_Product
|
||||
import lib.argument_validation as av
|
||||
# from datastores.datastore_store_base import DataStore_Store
|
||||
# external
|
||||
import os
|
||||
|
||||
# VARIABLE INSTANTIATION
|
||||
|
||||
|
||||
# CLASSES
|
||||
class Model_View_Store_Checkout_Success(Model_View_Store_Checkout):
|
||||
# Attributes
|
||||
key_secret_stripe: str
|
||||
key_public_stripe: str
|
||||
# Global constants
|
||||
key_id_price = 'price_id'
|
||||
|
||||
@property
|
||||
def title(self):
|
||||
return 'Store Checkout Success'
|
||||
|
||||
def __init__(self, id_checkout_session, checkout_items, id_currency, id_region_delivery, is_included_VAT, hash_page_current=Model_View_Store.HASH_PAGE_STORE_CHECKOUT_SUCCESS):
|
||||
# Constructor
|
||||
super().__init__(hash_page_current=hash_page_current, id_currency=id_currency, id_region_delivery=id_region_delivery, is_included_VAT=is_included_VAT)
|
||||
self.checkout_items = checkout_items
|
||||
self.id_checkout_session = id_checkout_session
|
||||
self.order = self.get_many_user_order('', 1, id_checkout_session)
|
||||
@@ -10,11 +10,6 @@ Description:
|
||||
Data model for store home view
|
||||
"""
|
||||
|
||||
# IMPORTS
|
||||
# VARIABLE INSTANTIATION
|
||||
# METHODS
|
||||
|
||||
# IMPORTS
|
||||
# internal
|
||||
from models.model_view_store import Model_View_Store
|
||||
# from routes import bp_home
|
||||
@@ -23,37 +18,18 @@ from forms.forms import Form_Basket_Add, Form_Basket_Edit # Form_Product
|
||||
# external
|
||||
from typing import ClassVar
|
||||
|
||||
# VARIABLE INSTANTIATION
|
||||
|
||||
|
||||
# CLASSES
|
||||
class Model_View_Store_Home(Model_View_Store):
|
||||
# Global constants
|
||||
MAX_PRODUCTS_PER_CATEGORY: ClassVar[int] = -1
|
||||
# Attributes
|
||||
product_categories: list # (str)
|
||||
|
||||
product_categories: list
|
||||
forms_product: dict
|
||||
forms_basket: dict
|
||||
# category_products: dict { category_enum_id: List[Product] }
|
||||
# Attributes
|
||||
|
||||
@property
|
||||
def title(self):
|
||||
return 'Store Home'
|
||||
|
||||
def __init__(self, id_currency, id_region_delivery, is_included_VAT, hash_page_current=Model_View_Store.HASH_PAGE_STORE_HOME):
|
||||
# Constructor
|
||||
super().__init__(id_currency, id_region_delivery, is_included_VAT)
|
||||
# self.categories = Model_View_Store_Home.get_many_product(self.db, get_all_category = True, get_all_product = True)
|
||||
# self.get_many_product(get_all_category = True, get_all_product = True)
|
||||
"""
|
||||
self.forms_product = {}
|
||||
for cat in self.product_categories:
|
||||
for product in cat:
|
||||
if len(list(product.variations.keys())) == 0:
|
||||
new_form = Form_Product()
|
||||
if new_form.validate_on_submit():
|
||||
# Handle form submission
|
||||
self.add_2_basket(product.id, )
|
||||
self.forms[str(product.id)] = new_form
|
||||
"""
|
||||
|
||||
|
||||
@@ -18,11 +18,11 @@ from forms.access_level import Filters_Access_Level
|
||||
from forms.store.product import Filters_Product
|
||||
from helpers.helper_app import Helper_App
|
||||
from models.model_view_store import Model_View_Store
|
||||
# from routes import bp_home
|
||||
import lib.argument_validation as av
|
||||
# external
|
||||
from typing import ClassVar
|
||||
|
||||
|
||||
class Model_View_Store_Product(Model_View_Store):
|
||||
access_levels: list = None
|
||||
category_list: Product_Category_Container = None
|
||||
|
||||
@@ -12,12 +12,10 @@ Data model for store permutations view
|
||||
|
||||
# internal
|
||||
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 import Parameters_Product
|
||||
from business_objects.store.product_category import Product_Category_Container # , Filters_Product_Category
|
||||
from business_objects.store.product_category import Product_Category_Container
|
||||
from forms.access_level import Filters_Access_Level
|
||||
# from forms.store.product_permutation import Filters_Product_Permutation
|
||||
from forms.store.product_category import Filters_Product_Category
|
||||
# from routes import bp_home
|
||||
from helpers.helper_app import Helper_App
|
||||
@@ -28,11 +26,8 @@ from pydantic import BaseModel
|
||||
from typing import ClassVar
|
||||
|
||||
class Model_View_Store_Product_Category(Model_View_Store):
|
||||
# KEY_CATEGORIES: ClassVar[str] = 'categories'
|
||||
|
||||
access_levels: list = None
|
||||
category_list: Product_Category_Container = None # (str)
|
||||
# filters_category: Filters_Product_Category
|
||||
category_list: Product_Category_Container = None
|
||||
form_filters: Filters_Product_Category = None
|
||||
form_filters_old: Filters_Product_Category
|
||||
|
||||
@@ -43,12 +38,10 @@ class Model_View_Store_Product_Category(Model_View_Store):
|
||||
def __init__(self, form_filters_old, hash_page_current=Model_View_Store.HASH_PAGE_STORE_PRODUCT_CATEGORIES):
|
||||
_m = 'Model_View_Store_Product_Category.__init__'
|
||||
Helper_App.console_log(f'{_m}\nstarting...')
|
||||
super().__init__(hash_page_current=hash_page_current, form_filters_old=form_filters_old) # filters_category=filters_category)
|
||||
super().__init__(hash_page_current=hash_page_current, form_filters_old=form_filters_old)
|
||||
self.form_filters = form_filters_old
|
||||
# BaseModel.__init__(self, app=app, filters_product=filters_product, **kwargs)
|
||||
self.access_levels = self.get_many_access_level(Filters_Access_Level())
|
||||
datastore_store = DataStore_Store_Product_Category()
|
||||
# self.form_filters = Filters_Product_Category.from_filters(filters_category)
|
||||
filters_product = Parameters_Product.from_filters_product_category(self.form_filters)
|
||||
self.category_list, errors = datastore_store.get_many_product(filters_product)
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ 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 Product_Category_Container
|
||||
from forms.store.product_permutation import Filters_Product_Permutation
|
||||
# from routes import bp_home
|
||||
from business_objects.store.product import Product, Parameters_Product, Product_Permutation
|
||||
from helpers.helper_app import Helper_App
|
||||
import lib.argument_validation as av
|
||||
@@ -29,7 +28,6 @@ class Model_View_Store_Product_Permutation(Model_View_Store):
|
||||
category_list_filters: Product_Category_Container = None
|
||||
currencies: list = None
|
||||
currency_options: list = None
|
||||
# filters_product: Parameters_Product = None
|
||||
form_filters: Filters_Product_Permutation = None
|
||||
form_filters_old: Filters_Product_Permutation
|
||||
list_options_product: list = None
|
||||
@@ -47,7 +45,6 @@ class Model_View_Store_Product_Permutation(Model_View_Store):
|
||||
Helper_App.console_log(f'{_m}\nstarting...')
|
||||
super().__init__(hash_page_current=hash_page_current, form_filters_old=form_filters_old)
|
||||
self.form_filters = form_filters_old
|
||||
# self.form_filters = Filters_Product_Permutation()
|
||||
filters_product = Parameters_Product.from_form_filters_product_permutation(self.form_filters)
|
||||
datastore_store = DataStore_Store_Product_Permutation()
|
||||
self.category_list, errors = datastore_store.get_many_product(filters_product)
|
||||
|
||||
@@ -10,11 +10,6 @@ Description:
|
||||
Data model for store product view
|
||||
"""
|
||||
|
||||
# IMPORTS
|
||||
# VARIABLE INSTANTIATION
|
||||
# METHODS
|
||||
|
||||
# IMPORTS
|
||||
# internal
|
||||
from business_objects.store.product_variation import Product_Variation, Parameters_Product_Variation
|
||||
from business_objects.store.product_category import Product_Category_Container
|
||||
@@ -23,7 +18,6 @@ from forms.access_level import Filters_Access_Level
|
||||
from forms.store.product_variation import Filters_Product_Variation
|
||||
from helpers.helper_app import Helper_App
|
||||
from models.model_view_store import Model_View_Store
|
||||
# from routes import bp_home
|
||||
import lib.argument_validation as av
|
||||
# external
|
||||
from typing import ClassVar
|
||||
|
||||
@@ -48,42 +48,23 @@ class Model_View_Store_Stock_Item(Model_View_Store):
|
||||
_m = 'Model_View_Store_Stock_Item.__init__'
|
||||
Helper_App.console_log(f'{_m}\nstarting...')
|
||||
super().__init__(hash_page_current=hash_page_current, form_filters_old=form_filters_old)
|
||||
# BaseModel.__init__(self, app=app, form_filters_old=form_filters_old, **kwargs)
|
||||
self.form_filters = form_filters_old # Filters_Stock_Item.from_json(form_filters_old.to_json()) # .from_form_stock_item(form_filters_old)
|
||||
self.form_filters = form_filters_old
|
||||
datastore_store = DataStore_Store_Stock_Item()
|
||||
tmp_category_list_stock_item, errors = datastore_store.get_many_product(Parameters_Product.from_filters_stock_item(self.form_filters))
|
||||
self.category_list, errors = datastore_store.get_many_stock_item(Parameters_Stock_Item.from_form_stock_item(self.form_filters), tmp_category_list_stock_item)
|
||||
self.category_list_filters, errors_filters = datastore_store.get_many_product(Parameters_Product.get_default())
|
||||
"""
|
||||
Parameters_Stock_Item(
|
||||
# self.info_user['sub'],
|
||||
True, False, False, '', # get_all_category, get_inactive_category, get_first_category_only, ids_category
|
||||
True, False, False, '', # get_all_product, get_inactive_product, get_first_product_only, ids_product
|
||||
True, False, False, '', # get_all_permutation, get_inactive_permutation, get_first_permutation_only, ids_permutation
|
||||
False, False, False, '', # get_all_stock_item, get_inactive_stock_item, get_first_stock_item_only, ids_stock_item
|
||||
False, False, False, '', # get_all_region_storage, get_inactive_region_storage, get_first_region_storage_only, ids_region_storage
|
||||
False, False, False, '', # get_all_plant_storage, get_inactive_plant_storage, get_first_plant_storage_only, ids_plant_storage
|
||||
False, False, False, '', # get_all_location_storage, get_inactive_location_storage, get_first_location_storage_only, ids_location_storage
|
||||
None, # date_received_to
|
||||
False, False, # get_sealed_stock_item_only, get_unsealed_stock_item_only
|
||||
False, False, # get_expired_stock_item_only, get_nonexpired_stock_item_only
|
||||
False, False # get_consumed_stock_item_only, get_nonconsumed_stock_item_only
|
||||
)
|
||||
"""
|
||||
|
||||
Helper_App.console_log(f'category_list_filters: {self.category_list_filters.categories}')
|
||||
self.form_filters.id_category.choices += [(str(category.id_category), category.name) for category in self.category_list_filters.categories] # [Filters_Stock_Item.get_choice_all()] +
|
||||
self.form_filters.id_category.choices += [(str(category.id_category), category.name) for category in self.category_list_filters.categories]
|
||||
Helper_App.console_log(f'category options: {self.form_filters.id_category.choices}')
|
||||
product_list = self.category_list_filters.to_product_option_list()
|
||||
filtered_product_list = []
|
||||
if product_list is not None:
|
||||
for product in product_list:
|
||||
# Helper_App.console_log(f'product: {product}\n{product[Stock_Item.ATTR_ID_PRODUCT_CATEGORY]}\n{self.form_filters.id_category.data}\n{str(type(product[Stock_Item.ATTR_ID_PRODUCT_CATEGORY]))}\n{str(type(self.form_filters.id_category.data))}')
|
||||
if (self.form_filters.id_category.data == '' or str(product[Stock_Item.ATTR_ID_PRODUCT_CATEGORY]) == self.form_filters.id_category.data):
|
||||
filtered_product_list.append(product)
|
||||
Helper_App.console_log(f'product_list: {product_list}\nfiltered_product_list: {filtered_product_list}')
|
||||
self.form_filters.id_product.choices += [(str(product['value']), product['text']) for product in filtered_product_list] # [Filters_Stock_Item.get_choice_all()] +
|
||||
# self.form_filters.import_values(form_filters_old)
|
||||
self.form_filters.id_product.choices += [(str(product['value']), product['text']) for product in filtered_product_list]
|
||||
self.variation_types, self.variations, errors = self.get_many_product_variation()
|
||||
self.units_measurement = self.get_many_unit_measurement()
|
||||
self.units_measurement_time = [unit_measurement for unit_measurement in self.units_measurement if unit_measurement.is_unit_of_time]
|
||||
|
||||
@@ -42,15 +42,10 @@ class Model_View_Store_Supplier(Model_View_Store):
|
||||
_m = 'Model_View_Store_Supplier.__init__'
|
||||
Helper_App.console_log(f'{_m}\nstarting...')
|
||||
super().__init__(hash_page_current = hash_page_current, form_filters_old = form_filters_old)
|
||||
self.form_filters = form_filters_old # Filters_Supplier.from_json(form_filters_old.to_json())
|
||||
self.form_filters = form_filters_old
|
||||
parameters_supplier = Parameters_Supplier.from_filters_supplier(self.form_filters)
|
||||
datastore_supplier = DataStore_Store_Supplier()
|
||||
self.suppliers, errors = datastore_supplier.get_many_supplier(parameters_supplier)
|
||||
|
||||
"""
|
||||
self.units_measurement = self.get_many_unit_measurement()
|
||||
self.units_measurement_time = [unit_measurement for unit_measurement in self.units_measurement if unit_measurement.is_unit_of_time]
|
||||
"""
|
||||
self.currencies = self.get_many_currency()
|
||||
self.currency_options = [currency.to_json_option() for currency in self.currencies]
|
||||
self.supplier_addresses = {}
|
||||
|
||||
@@ -43,7 +43,7 @@ class Model_View_Store_Supplier_Purchase_Order(Model_View_Store):
|
||||
_m = 'Model_View_Store_Supplier.__init__'
|
||||
Helper_App.console_log(f'{_m}\nstarting...')
|
||||
super().__init__(hash_page_current = hash_page_current, form_filters_old = form_filters_old)
|
||||
self.form_filters = form_filters_old # Filters_Supplier_Purchase_Order.from_json(form_filters_old.to_json())
|
||||
self.form_filters = form_filters_old
|
||||
parameters_supplier_purchase_order = Parameters_Supplier_Purchase_Order.from_filters_supplier_purchase_order(self.form_filters)
|
||||
datastore_supplier_purchase_order = DataStore_Store_Supplier_Purchase_Order()
|
||||
self.supplier_purchase_orders, errors = datastore_supplier_purchase_order.get_many_supplier_purchase_order(parameters_supplier_purchase_order)
|
||||
|
||||
@@ -24,7 +24,6 @@ class Model_View_User(Model_View_Store):
|
||||
FLAG_FIRSTNAME: ClassVar[str] = 'firstname'
|
||||
FLAG_SURNAME: ClassVar[str] = 'surname'
|
||||
FLAG_STATE_OAUTH: ClassVar[str] = 'state'
|
||||
# Attributes
|
||||
currencies: list = None
|
||||
regions: list = None
|
||||
users: list = None
|
||||
@@ -33,7 +32,6 @@ class Model_View_User(Model_View_Store):
|
||||
return 'User'
|
||||
|
||||
def __init__(self, hash_page_current=Model_View_Store.HASH_PAGE_USER_ACCOUNT):
|
||||
# Constructor
|
||||
super().__init__(hash_page_current=hash_page_current, form_filters_old = None)
|
||||
datastore_user = DataStore_User()
|
||||
self.currencies = datastore_user.get_many_currency()
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
// Shared JS file names: routing, main, shared, localStorage, appDialogs
|
||||
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
// main.js
|
||||
|
||||
import { initializeAPI } from './shared/api.js';
|
||||
import { setupEventListeners } from './shared/events.js';
|
||||
import { initializeComponents } from './components/componentInitializer.js';
|
||||
import { router } from './shared/router.js';
|
||||
import { CONFIG } from './config/config.js';
|
||||
|
||||
// DOM ready function
|
||||
function domReady(fn) {
|
||||
if (document.readyState !== 'loading') {
|
||||
fn();
|
||||
} else {
|
||||
document.addEventListener('DOMContentLoaded', fn);
|
||||
}
|
||||
}
|
||||
|
||||
// Main initialization function
|
||||
function initializeApp() {
|
||||
console.log('Initializing application...');
|
||||
|
||||
// Initialize API with base URL
|
||||
initializeAPI(CONFIG.API_BASE_URL);
|
||||
|
||||
// Setup global event listeners
|
||||
setupEventListeners();
|
||||
|
||||
// Initialize reusable components
|
||||
initializeComponents();
|
||||
|
||||
// Initialize router
|
||||
router.init();
|
||||
|
||||
// Page-specific initialization
|
||||
const currentPage = document.body.dataset.page;
|
||||
switch (currentPage) {
|
||||
case 'home':
|
||||
import('./pages/home.js').then(module => module.initHomePage());
|
||||
break;
|
||||
case 'about':
|
||||
import('./pages/about.js').then(module => module.initAboutPage());
|
||||
break;
|
||||
case 'contact':
|
||||
import('./pages/contact.js').then(module => module.initContactPage());
|
||||
break;
|
||||
default:
|
||||
console.log('No specific initialization for this page');
|
||||
}
|
||||
|
||||
console.log('Application initialized');
|
||||
}
|
||||
|
||||
// Run the initialization when the DOM is ready
|
||||
domReady(initializeApp);
|
||||
|
||||
// Expose a global app object if needed
|
||||
window.app = {
|
||||
// Add methods or properties that need to be globally accessible
|
||||
reloadPage: () => {
|
||||
window.location.reload();
|
||||
},
|
||||
navigateTo: (url) => {
|
||||
router.navigateTo(url);
|
||||
}
|
||||
};
|
||||
@@ -1,111 +0,0 @@
|
||||
|
||||
import Validation from "./lib/validation.js";
|
||||
|
||||
function mapHashToController(hash) {
|
||||
if (hash == null) return mapHashToController(hashPageHome);
|
||||
|
||||
url = _pathHost; // + '/';
|
||||
console.log("url: " + url + "\nhash: " + hash);
|
||||
return url + hash;
|
||||
|
||||
switch (hash) {
|
||||
case hashPageErrorNoPermission:
|
||||
url += 'error';
|
||||
break;
|
||||
case hashPageStoreHome:
|
||||
url += 'store/home';
|
||||
break;
|
||||
case hashPageStoreProduct:
|
||||
url += 'store/product';
|
||||
break;
|
||||
case hashStoreBasketLoad:
|
||||
url += 'store/basket_load';
|
||||
break;
|
||||
case hashStoreBasketAdd:
|
||||
url += 'store/product';
|
||||
break;
|
||||
default:
|
||||
url += '';
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
/*
|
||||
function goToPage(pageHash, parameters) {
|
||||
window.location.href = "{{ url_for(" + pageHash + (parameters == '' ? '' : ',' + parameters) + ") }}"; // getPageRoute(pageHash, parameters);
|
||||
}
|
||||
*/
|
||||
function goToPage(pageHash, parametersJSON) {
|
||||
// window.location.href = "{{ url_for(" + pageHash + (parameters == '' ? '' : ',' + parameters) + ") }}"; // getPageRoute(pageHash, parameters);
|
||||
// ajaxJSONData(pageHash, mapHashToController(pageHash), parameters, null, false);
|
||||
url = mapHashToController(pageHash);
|
||||
|
||||
|
||||
if (!Validation.isEmpty(parametersJSON)) {
|
||||
url += '%3F'; // '?';
|
||||
let firstParameter = true;
|
||||
for (var p in parametersJSON) {
|
||||
// url += p + '=' + parametersJSON[p];
|
||||
if (!firstParameter) {
|
||||
url += '&';
|
||||
} else {
|
||||
firstParameter = false;
|
||||
}
|
||||
url += parametersJSON[p];
|
||||
}
|
||||
}
|
||||
|
||||
leavePage();
|
||||
|
||||
window.location.href = url;
|
||||
// ajaxJSONData(pageHash, url, parametersJSON, loadPageBody, false);
|
||||
}
|
||||
function leavePage() {}
|
||||
|
||||
function goToUrl(parameterisedUrl) {
|
||||
|
||||
leavePage();
|
||||
|
||||
window.location.href = parameterisedUrl;
|
||||
}
|
||||
|
||||
function htmlEncode(value) {
|
||||
return document.createElement('<div/>').text(value).innerHTML;
|
||||
}
|
||||
|
||||
var _domParser = null;
|
||||
function htmlDecode(value) {
|
||||
if (_domParser == null) _domParser = DOMParser(); // https://www.w3docs.com/snippets/javascript/how-to-html-encode-a-string.html
|
||||
return _domParser.parseFromString(value, 'text/html').documentElement.textContent;
|
||||
}
|
||||
|
||||
function convertForm2JSON(elemForm) {
|
||||
|
||||
formData = {}
|
||||
|
||||
formDataTmp = elemForm.serializeArray();
|
||||
|
||||
$.each(formDataTmp, function(index, field) {
|
||||
formData[field.name] = field.value;
|
||||
/*
|
||||
console.log('field name: ' + field.name);
|
||||
console.log('field value: ' + field.value);
|
||||
console.log('field currentval: ' + getElementValueCurrent(field));
|
||||
*/
|
||||
});
|
||||
|
||||
return formData;
|
||||
}
|
||||
|
||||
function loadPageBody(response) {
|
||||
|
||||
let pageBody = document.querySelectorAll(idPageBody);
|
||||
|
||||
console.log('ajax:');
|
||||
console.log(response.data);
|
||||
|
||||
pageBody.innerHTML = response.data['html_block'];
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ dir_parent = os.path.abspath(__file__ + '/../..')
|
||||
dir_sql = os.path.abspath(dir_parent + '/sql')
|
||||
|
||||
|
||||
# METHODS
|
||||
for entry in os.scandir(dir_sql):
|
||||
if entry.is_file():
|
||||
if '_tbl_' in entry.name:
|
||||
@@ -17,5 +16,3 @@ for entry in os.scandir(dir_sql):
|
||||
os.rename(entry.path, dir_sql + '/' + new_name)
|
||||
if entry.is_dir():
|
||||
pass
|
||||
|
||||
# SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Msg_Error_Type';
|
||||
Reference in New Issue
Block a user