136 lines
4.6 KiB
Python
136 lines
4.6 KiB
Python
"""
|
|
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):
|
|
ATTR_ID_COMMAND_CATEGORY: ClassVar[str] = 'id_command_category'
|
|
FLAG_COMMAND_CATEGORY: ClassVar[str] = 'command-category'
|
|
NAME_ATTR_OPTION_VALUE: ClassVar[str] = ATTR_ID_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(250))
|
|
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__()
|
|
|
|
@classmethod
|
|
def from_db_command(cls, query_row):
|
|
_m = f'{cls.__qualname__}.from_db_command'
|
|
category = cls()
|
|
category.id_command_category = query_row[0]
|
|
category.code = query_row[1]
|
|
category.name = query_row[2]
|
|
category.active = av.input_bool(query_row[3], 'active', _m)
|
|
# command.created_on = query_row[7]
|
|
return category
|
|
|
|
@classmethod
|
|
def from_db_dog_command_link(cls, query_row):
|
|
_m = f'{cls.__qualname__}.from_db_dog_command_link'
|
|
level = cls()
|
|
level.id_command_category = query_row[3]
|
|
# level.code = query_row[6]
|
|
level.name = query_row[4]
|
|
level.active = True
|
|
return level
|
|
|
|
@classmethod
|
|
def from_db_command_button_link(cls, query_row):
|
|
_m = f'{cls.__qualname__}.from_db_command_button_link'
|
|
level = cls()
|
|
level.id_command_category = query_row[1]
|
|
level.name = query_row[2]
|
|
level.active = True
|
|
return level
|
|
|
|
@classmethod
|
|
def from_db_assessment_command_modality_link(cls, query_row):
|
|
_m = f'{cls.__qualname__}.from_db_assessment_command_modality_link'
|
|
level = cls()
|
|
level.id_command_category = query_row[3]
|
|
level.name = query_row[4]
|
|
level.active = True
|
|
return level
|
|
|
|
@classmethod
|
|
def from_json(cls, json):
|
|
_m = f'{cls.__qualname__}.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 = json.get(cls.ATTR_ID_COMMAND_CATEGORY, -1)
|
|
command_category.name = json[cls.FLAG_NAME]
|
|
command_category.code = json.get(cls.FLAG_CODE, command_category.name.upper().replace(" ", "_"))
|
|
command_category.active = av.input_bool(json[cls.FLAG_ACTIVE], cls.FLAG_ACTIVE, _m)
|
|
# Helper_App.console_log(f'Command_Category: {command_category}')
|
|
return command_category
|
|
|
|
|
|
def to_json(self):
|
|
as_json = {
|
|
**self.get_shared_json_attributes(self)
|
|
, self.ATTR_ID_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(250))
|
|
name = db.Column(db.String(250))
|
|
active = db.Column(db.Boolean)
|
|
guid: str = db.Column(db.String(36))
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
@classmethod
|
|
def from_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 |