Feat(Python): Main business objects for Dog Command Link page created.
This commit is contained in:
104
business_objects/dog/command_category.py
Normal file
104
business_objects/dog/command_category.py
Normal file
@@ -0,0 +1,104 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Business Objects
|
||||
Feature: Command Category 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_Category(SQLAlchemy_ABC, Base):
|
||||
FLAG_COMMAND_CATEGORY: ClassVar[str] = 'command-category'
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = FLAG_COMMAND_CATEGORY
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = Base.FLAG_NAME
|
||||
|
||||
__tablename__ = 'DOG_Command_Category'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
|
||||
id_command_category = db.Column(db.Integer, primary_key=True)
|
||||
code = db.Column(db.String(100))
|
||||
name = db.Column(db.String(250))
|
||||
active = db.Column(db.Boolean)
|
||||
|
||||
def __init__(self):
|
||||
self.id_command_category = 0
|
||||
self.is_new = False
|
||||
super().__init__()
|
||||
|
||||
def from_DB_Dog_Command(query_row):
|
||||
_m = 'Command_Category.from_DB_Dog_Command'
|
||||
level = Command_Category()
|
||||
level.id_command_category = 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 = 'Command_Category.from_json'
|
||||
command_category = cls()
|
||||
if json is None: return Command_Category
|
||||
Helper_App.console_log(f'{_m}\njson: {json}')
|
||||
command_category.id_command_category = -1
|
||||
command_category.code = json[cls.FLAG_CODE]
|
||||
command_category.name = json[cls.FLAG_NAME]
|
||||
command_category.active = json[cls.FLAG_ACTIVE]
|
||||
Helper_App.console_log(f'Command_Category: {command_category}')
|
||||
return command_category
|
||||
|
||||
|
||||
def to_json(self):
|
||||
as_json = {
|
||||
self.FLAG_COMMAND_CATEGORY: self.id_command_category
|
||||
, 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_COMMAND_CATEGORY}: {self.id_command_category}
|
||||
{self.FLAG_CODE}: {self.code}
|
||||
{self.FLAG_NAME}: {self.name}
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
)
|
||||
'''
|
||||
|
||||
|
||||
class Command_Category_Temp(db.Model, Base):
|
||||
__tablename__ = 'DOG_Command_Category_Temp'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_temp = db.Column(db.Integer, primary_key=True)
|
||||
id_command_category = db.Column(db.Integer)
|
||||
code = db.Column(db.String(100))
|
||||
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_command_category(cls, command_category):
|
||||
_m = 'Command_Category_Temp.from_Command_Category'
|
||||
temp = cls()
|
||||
temp.id_command_category = command_category.id_command_category
|
||||
temp.code = command_category.code
|
||||
temp.name = command_category.name
|
||||
temp.active = command_category.active
|
||||
return temp
|
||||
Reference in New Issue
Block a user