Feat(SQL, UI): 1. Calc and Get Many Stored Procedures created for Weather, Lighting Level, Assessment, Distraction Type, Distraction Intensity Level, Distraction, Bribe, Assessment Command Modality Link, Response Quality Metric, Obedience Level, and Assessment Response. \n 2. Assessments and Assessment pages created with data loading and hooked up, but not saving.
This commit is contained in:
190
business_objects/dog/command_modality.py
Normal file
190
business_objects/dog/command_modality.py
Normal file
@@ -0,0 +1,190 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Business Objects
|
||||
Feature: Command Modality Business Object
|
||||
"""
|
||||
|
||||
# internal
|
||||
from business_objects.base import Base
|
||||
from business_objects.db_base import SQLAlchemy_ABC, Get_Many_Parameters_Base
|
||||
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_Modality(SQLAlchemy_ABC, Base):
|
||||
ATTR_ID_COMMAND_MODALITY: ClassVar[str] = 'id_command_modality'
|
||||
FLAG_COMMAND_MODALITY: ClassVar[str] = 'command-modality'
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = ATTR_ID_COMMAND_MODALITY
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = Base.FLAG_NAME
|
||||
|
||||
__tablename__ = 'DOG_Command_Modality'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
|
||||
id_command_modality = 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_modality = 0
|
||||
self.is_new = False
|
||||
super().__init__()
|
||||
|
||||
@classmethod
|
||||
def from_db_command_modality(cls, query_row):
|
||||
_m = f'{cls.__qualname__}.from_db_command_modality'
|
||||
category = cls()
|
||||
category.id_command_modality = 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_distraction(cls, query_row):
|
||||
_m = f'{cls.__qualname__}.from_db_distraction'
|
||||
level = cls()
|
||||
level.id_command_modality = query_row[2]
|
||||
level.name = query_row[3]
|
||||
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_modality = query_row[7]
|
||||
level.name = query_row[8]
|
||||
level.active = True
|
||||
return level
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
_m = 'Command_Modality.from_json'
|
||||
command_modality = cls()
|
||||
if json is None: return Command_Modality
|
||||
# Helper_App.console_log(f'{_m}\njson: {json}')
|
||||
command_modality.id_command_modality = json.get(cls.ATTR_ID_COMMAND_MODALITY, -1)
|
||||
command_modality.name = json[cls.FLAG_NAME]
|
||||
command_modality.code = json.get(cls.FLAG_CODE, command_modality.name.upper().replace(" ", "_"))
|
||||
command_modality.active = json[cls.FLAG_ACTIVE]
|
||||
# Helper_App.console_log(f'Command_Modality: {command_modality}')
|
||||
return command_modality
|
||||
|
||||
|
||||
def to_json(self):
|
||||
as_json = {
|
||||
**self.get_shared_json_attributes(self)
|
||||
, self.ATTR_ID_COMMAND_MODALITY: self.id_command_modality
|
||||
, 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_MODALITY}: {self.id_command_modality}
|
||||
{self.FLAG_CODE}: {self.code}
|
||||
{self.FLAG_NAME}: {self.name}
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
)
|
||||
'''
|
||||
|
||||
|
||||
class Command_Modality_Temp(db.Model, Base):
|
||||
__tablename__ = 'DOG_Command_Modality_Temp'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_temp = db.Column(db.Integer, primary_key=True)
|
||||
id_command_modality = 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_modality(cls, command_modality):
|
||||
_m = 'Command_Modality_Temp.from_Command_Modality'
|
||||
temp = cls()
|
||||
temp.id_command_modality = command_modality.id_command_modality
|
||||
temp.code = command_modality.code
|
||||
temp.name = command_modality.name
|
||||
temp.active = command_modality.active
|
||||
return temp
|
||||
|
||||
|
||||
class Parameters_Command_Modality(Get_Many_Parameters_Base):
|
||||
get_all_command_modality: bool
|
||||
get_inactive_command_modality: bool
|
||||
ids_command_modality: str
|
||||
names_command_modality: str
|
||||
require_all_id_search_filters_met: bool
|
||||
require_any_id_search_filters_met: bool
|
||||
require_all_non_id_search_filters_met: bool
|
||||
require_any_non_id_search_filters_met: bool
|
||||
|
||||
@classmethod
|
||||
def get_default(cls):
|
||||
return cls(
|
||||
get_all_command_modality = True
|
||||
, get_inactive_command_modality = False
|
||||
, ids_command_modality = ''
|
||||
, names_command_modality = ''
|
||||
, require_all_id_search_filters_met = True
|
||||
, require_any_id_search_filters_met = True
|
||||
, require_all_non_id_search_filters_met = False
|
||||
, require_any_non_id_search_filters_met = True
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
return cls(
|
||||
get_all_command_modality = json.get('a_get_all_command_modality', False)
|
||||
, get_inactive_command_modality = json.get('a_get_inactive_command_modality', False)
|
||||
, ids_command_modality = json.get('a_ids_command_modality', '')
|
||||
, names_command_modality = json.get('a_names_command_modality', '')
|
||||
, require_all_id_search_filters_met = json.get('a_require_all_id_search_filters_met', True)
|
||||
, require_any_id_search_filters_met = json.get('a_require_any_id_search_filters_met', True)
|
||||
, require_all_non_id_search_filters_met = json.get('a_require_all_non_id_search_filters_met', False)
|
||||
, require_any_non_id_search_filters_met = json.get('a_require_any_non_id_search_filters_met', True)
|
||||
)
|
||||
|
||||
"""
|
||||
@classmethod
|
||||
def from_form_filters_command_modality(cls, form):
|
||||
av.val_instance(form, 'form', 'Parameters_Command_Modality.from_form_filters_command_modality', Filters_Command_Modality)
|
||||
has_filter_search_text = not (form.search.data == '' or form.search.data is None)
|
||||
active_only = av.input_bool(form.active_only.data, "active", "Parameters_Command_Modality.from_form_filters_command_modality")
|
||||
filters = cls.get_default()
|
||||
filters.get_all_command_modality = True
|
||||
filters.get_inactive_command_modality = not active_only
|
||||
filters.ids_command_modality = ''
|
||||
filters.names_command_modality = form.search.data if has_filter_search_text else ''
|
||||
filters.notes_command_modality = form.search.data if has_filter_search_text else ''
|
||||
return filters
|
||||
"""
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
'a_get_all_command_modality': self.get_all_command_modality
|
||||
, 'a_get_inactive_command_modality': self.get_inactive_command_modality
|
||||
, 'a_ids_command_modality': self.ids_command_modality
|
||||
, 'a_names_command_modality': self.names_command_modality
|
||||
, 'a_require_all_id_search_filters_met': self.require_all_id_search_filters_met
|
||||
, 'a_require_any_id_search_filters_met': self.require_any_id_search_filters_met
|
||||
, 'a_require_all_non_id_search_filters_met': self.require_all_non_id_search_filters_met
|
||||
, 'a_require_any_non_id_search_filters_met': self.require_any_non_id_search_filters_met
|
||||
}
|
||||
Reference in New Issue
Block a user