Initial commit.
This commit is contained in:
11
business_objects/__init__.py
Normal file
11
business_objects/__init__.py
Normal file
@@ -0,0 +1,11 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Module Initialisation
|
||||
Feature: Business Objects
|
||||
|
||||
Description:
|
||||
Initialises business objects module.
|
||||
"""
|
||||
32
business_objects/api.py
Normal file
32
business_objects/api.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Business Objects
|
||||
Feature: Base Business Object
|
||||
|
||||
Description:
|
||||
Abstract business object
|
||||
"""
|
||||
|
||||
# internal
|
||||
from extensions import db
|
||||
import lib.argument_validation as av
|
||||
# external
|
||||
from typing import ClassVar
|
||||
from flask import jsonify
|
||||
|
||||
|
||||
class API():
|
||||
|
||||
@staticmethod
|
||||
def get_standard_response(success: bool, status_code: int, message: str, data: any, errors: list, meta: dict):
|
||||
return jsonify({
|
||||
"success": success,
|
||||
"status_code": status_code,
|
||||
"message": message,
|
||||
"data": data,
|
||||
"errors": errors,
|
||||
"meta": meta
|
||||
})
|
||||
90
business_objects/base.py
Normal file
90
business_objects/base.py
Normal file
@@ -0,0 +1,90 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Business Objects
|
||||
Feature: Base Business Object
|
||||
|
||||
Description:
|
||||
Abstract base class for all business objects in app
|
||||
"""
|
||||
|
||||
# internal
|
||||
from extensions import db
|
||||
import lib.argument_validation as av
|
||||
# external
|
||||
from typing import ClassVar
|
||||
|
||||
|
||||
class Base():
|
||||
ATTR_ID_ACCESS_LEVEL: ClassVar[str] = 'id_access_level'
|
||||
ATTR_ID_ADDRESS: ClassVar[str] = 'id_address'
|
||||
ATTR_ID_CURRENCY: ClassVar[str] = 'id_currency'
|
||||
ATTR_ID_MSG_ERROR_TYPE: ClassVar[str] = 'id_type'
|
||||
ATTR_ID_REGION: ClassVar[str] = 'id_region'
|
||||
ATTR_ID_USER: ClassVar[str] = 'id_user'
|
||||
ATTR_ID_USER_MANAGER: ClassVar[str] = 'id_user_manager'
|
||||
FLAG_ACCESS_LEVEL_REQUIRED: ClassVar[str] = 'access_level_required'
|
||||
FLAG_ACTIVE: ClassVar[str] = 'active'
|
||||
FLAG_ADDRESS: ClassVar[str] = 'address'
|
||||
FLAG_ADDRESS_LINE_1: ClassVar[str] = 'address_line_1'
|
||||
FLAG_ADDRESS_LINE_2: ClassVar[str] = 'address_line_2'
|
||||
FLAG_CAN_ADMIN: ClassVar[str] = 'can_admin'
|
||||
FLAG_CAN_EDIT: ClassVar[str] = 'can_edit'
|
||||
FLAG_CAN_VIEW: ClassVar[str] = 'can_view'
|
||||
FLAG_CITY: ClassVar[str] = 'city'
|
||||
FLAG_CODE: ClassVar[str] = 'code'
|
||||
FLAG_COUNTY: ClassVar[str] = 'county'
|
||||
FLAG_CREATED_BY: ClassVar[str] = 'created_by'
|
||||
FLAG_CREATED_ON: ClassVar[str] = 'created_on'
|
||||
FLAG_CURRENCY: ClassVar[str] = 'currency'
|
||||
FLAG_CURRENCY_COST: ClassVar[str] = 'currency_cost'
|
||||
FLAG_DATE_FROM: ClassVar[str] = 'date_from'
|
||||
FLAG_DATE_TO: ClassVar[str] = 'date_to'
|
||||
FLAG_DESCRIPTION: ClassVar[str] = 'description'
|
||||
FLAG_DISPLAY_ORDER: ClassVar[str] = 'display_order'
|
||||
FLAG_EDIT: ClassVar[str] = 'edit'
|
||||
FLAG_EMAIL: ClassVar[str] = 'email'
|
||||
FLAG_FAX: ClassVar[str] = 'fax'
|
||||
FLAG_GUID: ClassVar[str] = 'guid'
|
||||
FLAG_IS_NOT_EMPTY: ClassVar[str] = 'is_not_empty'
|
||||
# FLAG_KEY_PRIMARY: ClassVar[str] = 'key_primary'
|
||||
FLAG_MESSAGE: ClassVar[str] = 'message'
|
||||
FLAG_NAME: ClassVar[str] = 'name'
|
||||
FLAG_NAME_ATTR_OPTION_TEXT: ClassVar[str] = 'NAME_ATTR_OPTION_TEXT'
|
||||
FLAG_NAME_ATTR_OPTION_VALUE: ClassVar[str] = 'NAME_ATTR_OPTION_VALUE'
|
||||
FLAG_NAME_SINGULAR: ClassVar[str] = 'name_singular'
|
||||
FLAG_NAME_PLURAL: ClassVar[str] = 'name_plural'
|
||||
FLAG_PHONE_NUMBER: ClassVar[str] = 'phone_number'
|
||||
FLAG_POSTCODE: ClassVar[str] = 'postcode'
|
||||
FLAG_PRIORITY: ClassVar[str] = 'priority'
|
||||
FLAG_REGION: ClassVar[str] = 'region'
|
||||
FLAG_ROWS: ClassVar[str] = 'rows'
|
||||
FLAG_SYMBOL: ClassVar[str] = 'symbol'
|
||||
FLAG_URL: ClassVar[str] = 'url'
|
||||
FLAG_USER: ClassVar[str] = 'authorisedUser' # 'user' already used
|
||||
FLAG_VALUE_LOCAL_VAT_EXCL: ClassVar[str] = 'value_local_vat_excl'
|
||||
FLAG_VALUE_LOCAL_VAT_INCL: ClassVar[str] = 'value_local_vat_incl'
|
||||
FLAG_WEBSITE: ClassVar[str] = 'website'
|
||||
ID_USER_GUEST: ClassVar[int] = 3
|
||||
"""
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = 'name-attribute-option-text'
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = 'name-attribute-option-value'
|
||||
"""
|
||||
def __repr__(self):
|
||||
attrs = '\n'.join(f'{k}={v!r}' for k, v in self.__dict__.items())
|
||||
return f'<{self.__class__.__name__}(\n{attrs}\n)>'
|
||||
|
||||
@classmethod
|
||||
def output_bool(cls, value):
|
||||
return av.input_bool(value, f'{cls.__name__} bool attribute', f'{cls.__name__}.output_bool')
|
||||
@staticmethod
|
||||
def convert_list_objects_to_list_options(objects):
|
||||
return [object.to_json_option() for object in objects]
|
||||
@classmethod
|
||||
def get_shared_json_attributes(cls, object):
|
||||
return {
|
||||
cls.FLAG_NAME_ATTR_OPTION_TEXT: object.NAME_ATTR_OPTION_TEXT,
|
||||
cls.FLAG_NAME_ATTR_OPTION_VALUE: object.NAME_ATTR_OPTION_VALUE
|
||||
}
|
||||
48
business_objects/db_base.py
Normal file
48
business_objects/db_base.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Business Objects
|
||||
Feature: Database Base Business Objects
|
||||
|
||||
Description:
|
||||
Abstract base class for database objects
|
||||
"""
|
||||
|
||||
# internal
|
||||
# from helpers.DEPRECATED.helper_abc import Interface_ABC
|
||||
from extensions import db
|
||||
import lib.argument_validation as av
|
||||
# external
|
||||
from typing import ClassVar
|
||||
from abc import abstractmethod, ABCMeta
|
||||
from pydantic import BaseModel
|
||||
from sqlalchemy.ext.declarative import DeclarativeMeta
|
||||
# from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
|
||||
|
||||
class SQLAlchemy_ABCMeta(db.Model.__class__, ABCMeta):
|
||||
pass
|
||||
|
||||
class SQLAlchemy_ABC(db.Model, metaclass=SQLAlchemy_ABCMeta):
|
||||
__abstract__ = True
|
||||
# id = db.Column(db.Integer, primary_key=True)
|
||||
def __init__(self):
|
||||
pass
|
||||
def __repr__(self):
|
||||
pass
|
||||
def to_json(self):
|
||||
pass
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
pass
|
||||
def to_temporary_record(self):
|
||||
pass
|
||||
def to_object_with_missing_attributes(self, excluded_attributes):
|
||||
return {
|
||||
column.name: getattr(self, column.name)
|
||||
for column in self.__table__.columns
|
||||
if column.name not in excluded_attributes
|
||||
}
|
||||
82
business_objects/dog/DEPRECATED - access_level.py
Normal file
82
business_objects/dog/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__ = 'PH_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
business_objects/dog/__init__.py
Normal file
0
business_objects/dog/__init__.py
Normal file
136
business_objects/dog/command.py
Normal file
136
business_objects/dog/command.py
Normal file
@@ -0,0 +1,136 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Business Objects
|
||||
Feature: Command 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 Command(SQLAlchemy_ABC, Base):
|
||||
FLAG_ALTCHA: ClassVar[str] = 'altcha'
|
||||
FLAG_COMMAND: ClassVar[str] = 'command'
|
||||
FLAG_NAME_COMPANY: ClassVar[str] = 'name-company'
|
||||
FLAG_NAME_CONTACT: ClassVar[str] = 'name-contact'
|
||||
FLAG_MESSAGE: ClassVar[str] = 'message'
|
||||
FLAG_RECEIVE_MARKETING_COMMUNICATIONS: ClassVar[str] = 'receive-marketing-communications'
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = FLAG_COMMAND
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = Base.FLAG_EMAIL
|
||||
|
||||
__tablename__ = 'PH_Command'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
|
||||
id_command = db.Column(db.Integer, primary_key=True)
|
||||
email = db.Column(db.String(250))
|
||||
name_contact = db.Column(db.String(250))
|
||||
name_company = db.Column(db.String(250))
|
||||
message = db.Column(db.Text)
|
||||
receive_marketing_communications = db.Column(db.Boolean)
|
||||
active = db.Column(db.Boolean)
|
||||
created_on = db.Column(db.DateTime)
|
||||
|
||||
def __init__(self):
|
||||
self.id_command = 0
|
||||
self.is_new = False
|
||||
super().__init__()
|
||||
|
||||
def from_DB_Command(query_row):
|
||||
_m = 'Command.from_DB_Command'
|
||||
command = Command()
|
||||
command.id_command = query_row[0]
|
||||
command.email = query_row[1]
|
||||
command.name_contact = query_row[2]
|
||||
command.name_company = query_row[3]
|
||||
command.message = query_row[4]
|
||||
command.receive_marketing_communications = av.input_bool(query_row[5], 'receive_marketing_communications', _m)
|
||||
command.active = av.input_bool(query_row[6], 'active', _m)
|
||||
command.created_on = query_row[7]
|
||||
return command
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
_m = 'Command.from_json'
|
||||
command = cls()
|
||||
if json is None: return Command
|
||||
Helper_App.console_log(f'{_m}\njson: {json}')
|
||||
command.id_command = -1
|
||||
command.email = json[cls.FLAG_EMAIL]
|
||||
command.name_contact = json[cls.FLAG_NAME_CONTACT]
|
||||
command.name_company = json[cls.FLAG_NAME_COMPANY]
|
||||
command.message = json[cls.FLAG_MESSAGE]
|
||||
command.receive_marketing_communications = json[cls.FLAG_RECEIVE_MARKETING_COMMUNICATIONS]
|
||||
command.active = json[cls.FLAG_ACTIVE]
|
||||
command.created_on = json.get(cls.FLAG_CREATED_ON, None)
|
||||
Helper_App.console_log(f'Command: {command}')
|
||||
return command
|
||||
|
||||
|
||||
def to_json(self):
|
||||
as_json = {
|
||||
self.FLAG_COMMAND: self.id_command
|
||||
, self.FLAG_EMAIL: self.email
|
||||
, self.FLAG_NAME_CONTACT: self.name_contact
|
||||
, self.FLAG_NAME_COMPANY: self.name_company
|
||||
, self.FLAG_MESSAGE: self.message
|
||||
, self.FLAG_RECEIVE_MARKETING_COMMUNICATIONS: self.receive_marketing_communications
|
||||
, self.FLAG_ACTIVE: self.active
|
||||
, self.FLAG_CREATED_ON: self.created_on
|
||||
}
|
||||
Helper_App.console_log(f'as_json: {as_json}')
|
||||
return as_json
|
||||
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.__class__.__name__}(
|
||||
{self.FLAG_COMMAND}: {self.id_command}
|
||||
{self.FLAG_EMAIL}: {self.email}
|
||||
{self.FLAG_NAME_CONTACT}: {self.name_contact}
|
||||
{self.FLAG_NAME_COMPANY}: {self.name_company}
|
||||
{self.FLAG_MESSAGE}: {self.message}
|
||||
{self.FLAG_RECEIVE_MARKETING_COMMUNICATIONS}: {self.receive_marketing_communications}
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
{self.FLAG_CREATED_ON}: {self.created_on}
|
||||
)
|
||||
'''
|
||||
|
||||
class Command_Temp(db.Model, Base):
|
||||
__tablename__ = 'PH_Command_Temp'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_temp = db.Column(db.Integer, primary_key=True)
|
||||
id_command = db.Column(db.Integer)
|
||||
email = db.Column(db.String(250))
|
||||
name_contact = db.Column(db.String(250))
|
||||
name_company = db.Column(db.String(250))
|
||||
message = db.Column(db.Text)
|
||||
receive_marketing_communications = db.Column(db.Boolean)
|
||||
active = db.Column(db.Boolean)
|
||||
created_on = db.Column(db.DateTime)
|
||||
guid: str = db.Column(db.String(36))
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
@classmethod
|
||||
def from_command(cls, command):
|
||||
_m = 'Command_Temp.from_Command'
|
||||
temp = cls()
|
||||
temp.id_command = command.id_command
|
||||
temp.email = command.email
|
||||
temp.name_contact = command.name_contact
|
||||
temp.name_company = command.name_company
|
||||
temp.message = command.message
|
||||
temp.receive_marketing_communications = command.receive_marketing_communications
|
||||
temp.active = command.active
|
||||
temp.created_on = command.created_on
|
||||
return temp
|
||||
126
business_objects/dog/dog.py
Normal file
126
business_objects/dog/dog.py
Normal file
@@ -0,0 +1,126 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Business Objects
|
||||
Feature: Dog 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 Dog(SQLAlchemy_ABC, Base):
|
||||
FLAG_DOG: ClassVar[str] = 'dog'
|
||||
FLAG_APPEARANCE: ClassVar[str] = 'appearance'
|
||||
FLAG_MASS_KG: ClassVar[str] = 'mass-kg'
|
||||
FLAG_NOTES: ClassVar[str] = 'notes'
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = FLAG_DOG
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = Base.FLAG_EMAIL
|
||||
|
||||
__tablename__ = 'PH_Dog'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
|
||||
id_dog = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String(250))
|
||||
appearance = db.Column(db.String(1000))
|
||||
mass_kg = db.Column(db.Numeric(precision=7, scale=3))
|
||||
notes = db.Column(db.Text)
|
||||
active = db.Column(db.Boolean)
|
||||
|
||||
def __init__(self):
|
||||
self.id_dog = 0
|
||||
self.is_new = False
|
||||
super().__init__()
|
||||
|
||||
def from_DB_Dog(query_row):
|
||||
_m = 'Dog.from_DB_Dog'
|
||||
dog = Dog()
|
||||
dog.id_dog = query_row[0]
|
||||
dog.name = query_row[1]
|
||||
dog.appearance = query_row[2]
|
||||
dog.mass_kg = query_row[3]
|
||||
dog.notes = query_row[4]
|
||||
dog.active = av.input_bool(query_row[5], 'active', _m)
|
||||
return dog
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
_m = 'Dog.from_json'
|
||||
dog = cls()
|
||||
if json is None: return Dog
|
||||
Helper_App.console_log(f'{_m}\njson: {json}')
|
||||
dog.id_dog = -1
|
||||
dog.name = json[cls.FLAG_NAME]
|
||||
dog.appearance = json[cls.FLAG_APPEARANCE]
|
||||
dog.mass_kg = json[cls.FLAG_MASS_KG]
|
||||
dog.notes = json[cls.FLAG_NOTES]
|
||||
dog.active = json[cls.FLAG_ACTIVE]
|
||||
Helper_App.console_log(f'Dog: {dog}')
|
||||
return dog
|
||||
|
||||
|
||||
def to_json(self):
|
||||
as_json = {
|
||||
self.FLAG_DOG: self.id_dog
|
||||
, self.FLAG_NAME: self.name
|
||||
, self.FLAG_APPEARANCE: self.appearance
|
||||
, self.FLAG_MASS_KG: self.mass_kg
|
||||
, self.FLAG_NOTES: self.notes
|
||||
, 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_DOG}: {self.id_dog}
|
||||
{self.FLAG_NAME}: {self.name}
|
||||
{self.FLAG_APPEARANCE}: {self.appearance}
|
||||
{self.FLAG_MASS_KG}: {self.mass_kg}
|
||||
{self.FLAG_NOTES}: {self.notes}
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
)
|
||||
'''
|
||||
|
||||
"""
|
||||
class Dog_Temp(db.Model, Base):
|
||||
__tablename__ = 'PH_Dog_Temp'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_temp = db.Column(db.Integer, primary_key=True)
|
||||
id_dog = db.Column(db.Integer)
|
||||
email = db.Column(db.String(250))
|
||||
name_contact = db.Column(db.String(250))
|
||||
name_company = db.Column(db.String(250))
|
||||
message = db.Column(db.Text)
|
||||
receive_marketing_communications = db.Column(db.Boolean)
|
||||
active = db.Column(db.Boolean)
|
||||
created_on = db.Column(db.DateTime)
|
||||
guid: str = db.Column(db.String(36))
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
@classmethod
|
||||
def from_dog(cls, dog):
|
||||
_m = 'Dog_Temp.from_Dog'
|
||||
temp = cls()
|
||||
temp.id_dog = dog.id_dog
|
||||
temp.email = dog.email
|
||||
temp.name_contact = dog.name_contact
|
||||
temp.name_company = dog.name_company
|
||||
temp.message = dog.message
|
||||
temp.receive_marketing_communications = dog.receive_marketing_communications
|
||||
temp.active = dog.active
|
||||
temp.created_on = dog.created_on
|
||||
return temp
|
||||
"""
|
||||
133
business_objects/dog/user.py
Normal file
133
business_objects/dog/user.py
Normal file
@@ -0,0 +1,133 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Business Objects
|
||||
Feature: User Business Object
|
||||
"""
|
||||
|
||||
# internal
|
||||
from business_objects.base import Base
|
||||
from business_objects.db_base import SQLAlchemy_ABC
|
||||
import lib.argument_validation as av
|
||||
from forms.forms import Form_Contact
|
||||
from extensions import db
|
||||
from helpers.helper_app import Helper_App
|
||||
# external
|
||||
from dataclasses import dataclass
|
||||
from typing import ClassVar
|
||||
|
||||
|
||||
class User(SQLAlchemy_ABC, Base):
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = Base.ATTR_ID_USER
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = 'email'
|
||||
|
||||
__tablename__ = 'PH_User'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
|
||||
id_user = db.Column(db.Integer, primary_key=True)
|
||||
id_user_auth0 = db.Column(db.String(250))
|
||||
firstname = db.Column(db.String(250))
|
||||
surname = db.Column(db.String(250))
|
||||
email = db.Column(db.String(250))
|
||||
is_email_verified = db.Column(db.Boolean)
|
||||
is_super_user = db.Column(db.Boolean)
|
||||
is_new = db.Column(db.Boolean)
|
||||
|
||||
def __init__(self):
|
||||
self.id_user = 0
|
||||
self.is_new = False
|
||||
super().__init__()
|
||||
|
||||
def from_DB_user(query_row):
|
||||
_m = 'User.from_DB_user'
|
||||
user = User()
|
||||
user.id_user = query_row[0]
|
||||
user.id_user_auth0 = query_row[1]
|
||||
user.firstname = query_row[2]
|
||||
user.surname = query_row[3]
|
||||
user.email = query_row[4]
|
||||
user.is_email_verified = av.input_bool(query_row[5], 'is_email_verified', _m)
|
||||
user.is_super_user = av.input_bool(query_row[9], 'is_super_user', _m)
|
||||
user.is_new = av.input_bool(query_row[12], 'is_new', _m)
|
||||
return user
|
||||
|
||||
@staticmethod
|
||||
def from_json(json):
|
||||
_m = 'User.from_json'
|
||||
user = User()
|
||||
if json is None: return user
|
||||
Helper_App.console_log(f'{_m}\njson: {json}')
|
||||
user.id_user = json['id_user']
|
||||
user.id_user_auth0 = json['id_user_auth0']
|
||||
user.firstname = json['firstname']
|
||||
user.surname = json['surname']
|
||||
user.email = json['email']
|
||||
user.is_email_verified = av.input_bool(json['is_email_verified'], 'is_email_verified', _m)
|
||||
user.is_super_user = av.input_bool(json['is_super_user'], 'is_super_user', _m)
|
||||
Helper_App.console_log(f'user: {user}')
|
||||
return user
|
||||
|
||||
@staticmethod
|
||||
def from_json_auth0(json):
|
||||
_m = 'User.from_json_auth0'
|
||||
user = User()
|
||||
if json is None: return user
|
||||
Helper_App.console_log(f'{_m}\njson: {json}')
|
||||
user_info = json['userinfo']
|
||||
user.id_user = None
|
||||
user.id_user_auth0 = user_info['sub']
|
||||
user.firstname = None
|
||||
user.surname = None
|
||||
user.email = user_info['email']
|
||||
user.is_email_verified = av.input_bool(user_info['email_verified'], 'is_email_verified', _m)
|
||||
user.is_super_user = None
|
||||
Helper_App.console_log(f'user: {user}')
|
||||
return user
|
||||
|
||||
def to_json(self):
|
||||
as_json = {
|
||||
'id_user': self.id_user,
|
||||
'id_user_auth0': self.id_user_auth0,
|
||||
'firstname': self.firstname,
|
||||
'surname': self.surname,
|
||||
'email': self.email,
|
||||
'is_email_verified': self.is_email_verified,
|
||||
'is_super_user': self.is_super_user
|
||||
}
|
||||
Helper_App.console_log(f'as_json: {as_json}')
|
||||
return as_json
|
||||
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
id_user: {self.id_user}
|
||||
id_user_auth0: {self.id_user_auth0}
|
||||
firstname: {self.firstname}
|
||||
surname: {self.surname}
|
||||
email: {self.email}
|
||||
is_email_verified: {self.is_email_verified}
|
||||
is_super_user: {self.is_super_user}
|
||||
'''
|
||||
|
||||
def get_is_logged_in(self):
|
||||
return (self.id_user > 0 and self.id_user != Base.ID_USER_GUEST)
|
||||
|
||||
class User_Temp(db.Model, Base):
|
||||
__tablename__ = 'Shop_User_Temp'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_user = db.Column(db.Integer, primary_key=True)
|
||||
id_user_auth0 = db.Column(db.String(250))
|
||||
firstname = db.Column(db.String(250))
|
||||
surname = db.Column(db.String(250))
|
||||
email = db.Column(db.String(250))
|
||||
is_email_verified = db.Column(db.Boolean)
|
||||
is_super_user = db.Column(db.Boolean)
|
||||
id_currency_default = db.Column(db.Integer)
|
||||
id_region_default = db.Column(db.Integer)
|
||||
is_included_VAT_default = db.Column(db.Boolean)
|
||||
# is_logged_in: bool
|
||||
|
||||
def __init__(self):
|
||||
self.id_user = 0
|
||||
super().__init__()
|
||||
69
business_objects/sql_error.py
Normal file
69
business_objects/sql_error.py
Normal file
@@ -0,0 +1,69 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Business Objects
|
||||
Feature: SQL Error Business Object
|
||||
|
||||
Description:
|
||||
Business object for SQL errors returned by Get Many Stored Procedures
|
||||
"""
|
||||
|
||||
# internal
|
||||
from business_objects.base import Base
|
||||
import lib.argument_validation as av
|
||||
from lib import data_types
|
||||
from forms.forms import Form_Basket_Add, Form_Basket_Edit # Form_Product
|
||||
# external
|
||||
from enum import Enum
|
||||
from datetime import datetime, timedelta
|
||||
import locale
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
|
||||
db = SQLAlchemy()
|
||||
|
||||
|
||||
class SQL_Error(db.Model):
|
||||
display_order = db.Column(db.Integer, primary_key=True)
|
||||
id_type = db.Column(db.Integer)
|
||||
code = db.Column(db.String(50))
|
||||
msg = db.Column(db.String(4000))
|
||||
name = db.Column(db.String(500))
|
||||
description = db.Column(db.String(4000))
|
||||
|
||||
"""
|
||||
def __new__(cls, display_order, code, msg):
|
||||
_m = 'SQL_Error.__new__'
|
||||
v_arg_type = 'class attribute'
|
||||
av.val_int(display_order, 'display_order', _m)
|
||||
av.val_str(code, 'code', _m, max_len=50, v_arg_type=v_arg_type)
|
||||
av.val_str(msg, 'msg', _m, max_len=4000, v_arg_type=v_arg_type)
|
||||
return super(SQL_Error, cls).__new__(cls)
|
||||
|
||||
def __init__(self, display_order, code, msg):
|
||||
self.display_order = display_order
|
||||
self.code = code
|
||||
self.msg = msg
|
||||
super().__init__()
|
||||
"""
|
||||
|
||||
def from_DB_record(record):
|
||||
error = SQL_Error()
|
||||
error.display_order = record[0]
|
||||
error.id_type = record[1]
|
||||
error.code = record[2]
|
||||
error.msg = record[3]
|
||||
error.name = record[4]
|
||||
error.description = record[5]
|
||||
return error
|
||||
def to_json(self):
|
||||
return {
|
||||
Base.FLAG_DISPLAY_ORDER: self.display_order,
|
||||
Base.ATTR_ID_MSG_ERROR_TYPE: self.id_type,
|
||||
Base.FLAG_CODE: self.code,
|
||||
Base.FLAG_MESSAGE: self.msg,
|
||||
Base.FLAG_NAME: self.name,
|
||||
Base.FLAG_DESCRIPTION: self.description,
|
||||
}
|
||||
Reference in New Issue
Block a user