Feat(SQL, UI): Redesign database with much more detailed command response quality analysis and created successfully loading Dog Command Links page
This commit is contained in:
@@ -8,16 +8,16 @@ Feature: Dog Command Link Business Object
|
||||
"""
|
||||
|
||||
# internal
|
||||
from business_objects.base import Base
|
||||
from business_objects.dog.command import Command
|
||||
from business_objects.dog.command_category import Command_Category
|
||||
from business_objects.db_base import SQLAlchemy_ABC
|
||||
from business_objects.dog.dog import Dog
|
||||
from business_objects.dog.obedience_level import Obedience_Level
|
||||
from business_objects.dog.understanding_level import Understanding_Level
|
||||
import lib.argument_validation as av
|
||||
from extensions import db
|
||||
from helpers.helper_app import Helper_App
|
||||
from dog_training.business_objects.base import Base
|
||||
from dog_training.business_objects.dog.command import Command
|
||||
# from dog_training.business_objects.dog.command_category import Command_Category
|
||||
from dog_training.business_objects.db_base import SQLAlchemy_ABC, Get_Many_Parameters_Base
|
||||
from dog_training.business_objects.dog.dog import Dog
|
||||
from dog_training.business_objects.dog.obedience_level import Obedience_Level
|
||||
from dog_training.extensions import db
|
||||
from dog_training.forms.dog.dog_command_link import Filters_Dog_Command_Link
|
||||
from dog_training.helpers.helper_app import Helper_App
|
||||
import dog_training.lib.argument_validation as av
|
||||
# external
|
||||
from dataclasses import dataclass
|
||||
from typing import ClassVar
|
||||
@@ -26,42 +26,40 @@ from typing import ClassVar
|
||||
class Dog_Command_Link(SQLAlchemy_ABC, Base):
|
||||
FLAG_DOG_COMMAND_LINK: ClassVar[str] = 'dog_command_link'
|
||||
FLAG_HAND_SIGNAL_DESCRIPTION: ClassVar[str] = 'hand-signal-description'
|
||||
FLAG_CAN_HAVE_BUTTON: ClassVar[str] = 'can-have-button'
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = FLAG_DOG_COMMAND_LINK
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = Base.FLAG_NAME
|
||||
|
||||
__tablename__ = 'DOG_Dog_Command_Link'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
|
||||
id_dog_command_link = db.Column(db.Integer, primary_key=True)
|
||||
id_link = db.Column(db.Integer, primary_key=True)
|
||||
id_dog = db.Column(db.Integer)
|
||||
id_command = db.Column(db.Integer)
|
||||
id_understanding_level = db.Column(db.Integer)
|
||||
id_obedience_level = db.Column(db.Integer)
|
||||
hand_signal_description = db.Column(db.Text)
|
||||
notes = db.Column(db.Text)
|
||||
active = db.Column(db.Boolean)
|
||||
created_on = db.Column(db.DateTime)
|
||||
|
||||
def __init__(self):
|
||||
self.id_dog_command_link = 0
|
||||
self.id_link = 0
|
||||
self.is_new = False
|
||||
#self.id_command_category = None
|
||||
self.dog = None
|
||||
self.command = None
|
||||
super().__init__()
|
||||
|
||||
def from_DB_Dog_Command(query_row):
|
||||
_m = 'Dog_Command_Link.from_DB_Dog_Command'
|
||||
def from_db_dog_command_link(query_row):
|
||||
_m = 'Dog_Command_Link.from_db_dog_command_link'
|
||||
dog_command_link = Dog_Command_Link()
|
||||
dog_command_link.id_dog_command_link = query_row[0]
|
||||
dog_command_link.id_link = query_row[0]
|
||||
dog_command_link.id_dog = query_row[1]
|
||||
#dog_command_link.id_command_category = query_row[3]
|
||||
dog_command_link.id_command = query_row[5]
|
||||
dog_command_link.id_understanding_level = query_row[8]
|
||||
dog_command_link.id_obedience_level = query_row[11]
|
||||
dog_command_link.hand_signal_description = query_row[14]
|
||||
dog_command_link.notes = query_row[15]
|
||||
dog_command_link.active = av.input_bool(query_row[16], 'active', _m)
|
||||
dog_command_link.hand_signal_description = query_row[8]
|
||||
dog_command_link.notes = query_row[9]
|
||||
dog_command_link.active = av.input_bool(query_row[10], 'active', _m)
|
||||
# dog_command_link.created_on = query_row[7]
|
||||
dog_command_link.dog = Dog.from_db_dog_command_link(query_row)
|
||||
dog_command_link.command = Command.from_db_dog_command_link(query_row)
|
||||
return dog_command_link
|
||||
|
||||
@classmethod
|
||||
@@ -70,11 +68,9 @@ class Dog_Command_Link(SQLAlchemy_ABC, Base):
|
||||
dog_command_link = cls()
|
||||
if json is None: return dog_command_link
|
||||
Helper_App.console_log(f'{_m}\njson: {json}')
|
||||
dog_command_link.id_dog_command_link = -1
|
||||
dog_command_link.id_link = -1
|
||||
dog_command_link.id_dog = json[Dog.FLAG_DOG]
|
||||
dog_command_link.id_command = json[Command.FLAG_COMMAND]
|
||||
dog_command_link.id_understanding_level = json[Understanding_Level.FLAG_UNDERSTANDING_LEVEL]
|
||||
dog_command_link.id_obedience_level = json[Obedience_Level.FLAG_OBEDIENCE_LEVEL]
|
||||
dog_command_link.hand_signal_description = json[cls.FLAG_HAND_SIGNAL_DESCRIPTION]
|
||||
dog_command_link.notes = json[cls.FLAG_NOTES]
|
||||
dog_command_link.active = json[cls.FLAG_ACTIVE]
|
||||
@@ -85,11 +81,9 @@ class Dog_Command_Link(SQLAlchemy_ABC, Base):
|
||||
|
||||
def to_json(self):
|
||||
as_json = {
|
||||
self.FLAG_DOG_COMMAND_LINK: self.id_dog_command_link
|
||||
self.FLAG_DOG_COMMAND_LINK: self.id_link
|
||||
, Dog.FLAG_DOG: self.id_dog
|
||||
, Command.FLAG_COMMAND: self.id_command
|
||||
, Understanding_Level.FLAG_UNDERSTANDING_LEVEL: self.id_understanding_level
|
||||
, Obedience_Level.FLAG_OBEDIENCE_LEVEL: self.id_obedience_level
|
||||
, self.FLAG_HAND_SIGNAL_DESCRIPTION: self.hand_signal_description
|
||||
, self.FLAG_NOTES: self.notes
|
||||
, self.FLAG_ACTIVE: self.active
|
||||
@@ -102,11 +96,9 @@ class Dog_Command_Link(SQLAlchemy_ABC, Base):
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.__class__.__name__}(
|
||||
{self.FLAG_DOG_COMMAND_LINK}: {self.id_dog_command_link}
|
||||
{Dog.FLAG_DOG}: {self.id_dog}
|
||||
{Command.FLAG_COMMAND}: {self.id_command}
|
||||
{Understanding_Level.FLAG_UNDERSTANDING_LEVEL}: {self.id_understanding_level}
|
||||
{Obedience_Level.FLAG_OBEDIENCE_LEVEL}: {self.id_obedience_level}
|
||||
{self.FLAG_DOG_COMMAND_LINK}: {self.id_link}
|
||||
{Dog.FLAG_DOG}: {self.dog}
|
||||
{Command.FLAG_COMMAND}: {self.command}
|
||||
{self.FLAG_HAND_SIGNAL_DESCRIPTION}: {self.hand_signal_description}
|
||||
{self.FLAG_NOTES}: {self.notes}
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
@@ -119,11 +111,9 @@ class Dog_Command_Link_Temp(db.Model, Base):
|
||||
__tablename__ = 'DOG_Dog_Command_Link_Temp'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_temp = db.Column(db.Integer, primary_key=True)
|
||||
id_dog_command_link = db.Column(db.Integer)
|
||||
id_link = db.Column(db.Integer)
|
||||
id_dog = db.Column(db.Integer)
|
||||
id_command = db.Column(db.Integer)
|
||||
id_understanding_level = db.Column(db.Integer)
|
||||
id_obedience_level = db.Column(db.Integer)
|
||||
hand_signal_description = db.Column(db.Text)
|
||||
notes = db.Column(db.Text)
|
||||
active = db.Column(db.Boolean)
|
||||
@@ -137,13 +127,68 @@ class Dog_Command_Link_Temp(db.Model, Base):
|
||||
def from_Dog_Command_Link(cls, dog_command_link):
|
||||
_m = 'Dog_Command_Link_Temp.from_Dog_Command_Link'
|
||||
temp = cls()
|
||||
temp.id_dog_command_link = dog_command_link.id_dog_command_link
|
||||
temp.id_link = dog_command_link.id_link
|
||||
temp.id_dog = dog_command_link.id_dog
|
||||
temp.id_command = dog_command_link.id_command
|
||||
temp.id_understanding_level = dog_command_link.id_understanding_level
|
||||
temp.id_obedience_level = dog_command_link.id_obedience_level
|
||||
temp.hand_signal_description = dog_command_link.hand_signal_description
|
||||
temp.notes = dog_command_link.notes
|
||||
temp.active = dog_command_link.active
|
||||
temp.created_on = dog_command_link.created_on
|
||||
return temp
|
||||
return temp
|
||||
|
||||
|
||||
class Parameters_Dog_Command_Link(Get_Many_Parameters_Base):
|
||||
get_all_dog: bool
|
||||
get_inactive_dog: bool
|
||||
ids_dog: str
|
||||
get_all_command: bool
|
||||
get_inactive_command: bool
|
||||
ids_command: str
|
||||
|
||||
@classmethod
|
||||
def get_default(cls):
|
||||
return cls(
|
||||
get_all_dog = True
|
||||
, get_inactive_dog = False
|
||||
, ids_dog = ''
|
||||
, get_all_command = True
|
||||
, get_inactive_command = False
|
||||
, ids_command = ''
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
return cls(
|
||||
get_all_dog = json.get('a_get_all_dog', False)
|
||||
, get_inactive_dog = json.get('a_get_inactive_dog', False)
|
||||
, ids_dog = json.get('a_ids_dog', '')
|
||||
, get_all_command = json.get('a_get_all_command', False)
|
||||
, get_inactive_command = json.get('a_get_inactive_command', False)
|
||||
, ids_command = json.get('a_ids_command', '')
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_form_filters_dog_command_link(cls, form):
|
||||
av.val_instance(form, 'form', 'Parameters_Dog_Command_Link.from_form_filters_dog_command_link', Filters_Dog_Command_Link)
|
||||
has_filter_dog = not (form.id_dog.data == '0' or form.id_dog.data == '' or form.id_dog.data is None)
|
||||
has_filter_command = not (form.id_command.data == '0' or form.id_command.data == '' or form.id_command.data is None)
|
||||
active_only = av.input_bool(form.active.data, "active", "Parameters_Dog_Command_Link.from_form_filters_dog_command_link")
|
||||
return cls(
|
||||
get_all_dog = not has_filter_dog
|
||||
, get_inactive_dog = not active_only
|
||||
, ids_dog = form.id_dog.data if has_filter_dog else ''
|
||||
, get_all_command = not has_filter_command
|
||||
, get_inactive_command = not active_only
|
||||
, ids_command = form.id_command.data if has_filter_command else ''
|
||||
)
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
'a_get_all_dog': self.get_all_dog
|
||||
, 'a_get_inactive_dog': self.get_inactive_dog
|
||||
, 'a_ids_dog': self.ids_dog
|
||||
, 'a_get_all_command': self.get_all_command
|
||||
, 'a_get_inactive_command': self.get_inactive_command
|
||||
, 'a_ids_command': self.ids_command
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user