Files
dog_training/business_objects/dog/command_category.py

104 lines
3.4 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 dog_training.business_objects.base import Base
from dog_training.business_objects.db_base import SQLAlchemy_ABC
import dog_training.lib.argument_validation as av
from dog_training.extensions import db
from dog_training.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_link(query_row):
_m = 'Command_Category.from_db_dog_command_link'
level = Command_Category()
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_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