413 lines
20 KiB
Python
413 lines
20 KiB
Python
"""
|
|
Project: PARTS Website
|
|
Author: Edward Middleton-Smith
|
|
Precision And Research Technology Systems Limited
|
|
|
|
Technology: Business Objects
|
|
Feature: Dog Command Link Business Object
|
|
"""
|
|
|
|
# internal
|
|
from business_objects.base import Base
|
|
from business_objects.dog.button_icon import Button_Icon
|
|
from business_objects.dog.button_shape import Button_Shape
|
|
from business_objects.dog.colour import Colour
|
|
from business_objects.dog.command import Command
|
|
# from business_objects.dog.command_category import Command_Category
|
|
from business_objects.db_base import SQLAlchemy_ABC, Get_Many_Parameters_Base
|
|
from business_objects.dog.dog import Dog
|
|
from business_objects.dog.location import Location
|
|
from business_objects.dog.obedience_level import Obedience_Level
|
|
from extensions import db
|
|
from forms.dog.command_button_link import Filters_Command_Button_Link
|
|
from helpers.helper_app import Helper_App
|
|
import lib.argument_validation as av
|
|
# external
|
|
from dataclasses import dataclass
|
|
from typing import ClassVar
|
|
|
|
|
|
class Command_Button_Link(SQLAlchemy_ABC, Base):
|
|
ATTR_ID_COMMAND_BUTTON_LINK: ClassVar[str] = 'id_link'
|
|
FLAG_COMMAND_BUTTON_LINK: ClassVar[str] = 'command_button_link'
|
|
NAME_ATTR_OPTION_VALUE: ClassVar[str] = ATTR_ID_COMMAND_BUTTON_LINK
|
|
NAME_ATTR_OPTION_TEXT: ClassVar[str] = ATTR_ID_COMMAND_BUTTON_LINK
|
|
|
|
__tablename__ = 'DOG_Command_Button_Link'
|
|
__table_args__ = { 'extend_existing': True }
|
|
|
|
id_link = db.Column(db.Integer, primary_key=True)
|
|
id_command = db.Column(db.Integer)
|
|
id_button_shape = db.Column(db.Integer)
|
|
id_button_colour = db.Column(db.Integer)
|
|
id_button_icon = db.Column(db.Integer)
|
|
id_location = db.Column(db.Integer)
|
|
active = db.Column(db.Boolean)
|
|
created_on = db.Column(db.DateTime)
|
|
|
|
def __init__(self):
|
|
self.id_link = 0
|
|
self.is_new = False
|
|
self.command = None
|
|
self.button_shape = None
|
|
self.colour = None
|
|
self.button_icon = None
|
|
self.location = None
|
|
super().__init__()
|
|
|
|
@classmethod
|
|
def from_db_command_button_link(cls, query_row):
|
|
_m = 'Command_Button_Link.from_db_command_button_link'
|
|
command_button_link = cls()
|
|
command_button_link.id_link = query_row[0]
|
|
command_button_link.id_command = query_row[3]
|
|
command_button_link.id_button_shape = query_row[5]
|
|
command_button_link.id_button_colour = query_row[7]
|
|
command_button_link.id_button_icon = query_row[9]
|
|
command_button_link.id_location = query_row[14]
|
|
command_button_link.active = av.input_bool(query_row[16], 'active', _m)
|
|
# command_button_link.created_on = query_row[7]
|
|
command_button_link.command = Command.from_db_command_button_link(query_row)
|
|
command_button_link.button_shape = Button_Shape.from_db_command_button_link(query_row)
|
|
command_button_link.colour = Colour.from_db_command_button_link(query_row)
|
|
command_button_link.button_icon = Button_Icon.from_db_command_button_link(query_row)
|
|
command_button_link.location = Location.from_db_command_button_link(query_row)
|
|
return command_button_link
|
|
|
|
@classmethod
|
|
def from_json(cls, json):
|
|
_m = 'Command_Button_Link.from_json'
|
|
command_button_link = cls()
|
|
if json is None: return command_button_link
|
|
# Helper_App.console_log(f'{_m}\njson: {json}')
|
|
command_button_link.id_link = json.get(Command_Button_Link.ATTR_ID_COMMAND_BUTTON_LINK, -1)
|
|
command_button_link.id_command = json[Command.FLAG_COMMAND]
|
|
command_button_link.id_button_shape = json[Button_Shape.FLAG_BUTTON_SHAPE]
|
|
command_button_link.id_button_colour = json[Colour.FLAG_COLOUR]
|
|
command_button_link.id_button_icon = json[Button_Icon.FLAG_BUTTON_ICON]
|
|
command_button_link.id_location = json[Location.FLAG_LOCATION]
|
|
command_button_link.active = json[cls.FLAG_ACTIVE]
|
|
command_button_link.created_on = json.get(cls.FLAG_CREATED_ON, None)
|
|
# command_button_link.id_command_category = json[Command_Category.FLAG_COMMAND_CATEGORY]
|
|
# Helper_App.console_log(f'Dog Command Link: {command_button_link}')
|
|
return command_button_link
|
|
|
|
def to_json(self):
|
|
as_json = {
|
|
**self.get_shared_json_attributes(self)
|
|
, self.ATTR_ID_COMMAND_BUTTON_LINK: self.id_link
|
|
, Command.FLAG_COMMAND: self.id_command
|
|
, Button_Shape.FLAG_BUTTON_SHAPE: self.id_button_shape
|
|
, Colour.FLAG_COLOUR: self.id_button_colour
|
|
, Button_Icon.FLAG_BUTTON_ICON: self.id_button_icon
|
|
, Location.FLAG_LOCATION: self.id_location
|
|
, self.FLAG_ACTIVE: self.active
|
|
, self.FLAG_CREATED_ON: self.created_on
|
|
}
|
|
# , Command_Category.FLAG_COMMAND_CATEGORY: self.id_command_category
|
|
# Helper_App.console_log(f'as_json: {as_json}')
|
|
return as_json
|
|
|
|
def __repr__(self):
|
|
return f'''
|
|
{self.__class__.__name__}(
|
|
{self.FLAG_COMMAND_BUTTON_LINK}: {self.id_link}
|
|
{Command.FLAG_COMMAND}: {self.command}
|
|
{Button_Shape.FLAG_BUTTON_SHAPE}: {self.button_shape}
|
|
{Colour.FLAG_COLOUR}: {self.colour}
|
|
{Button_Icon.FLAG_BUTTON_ICON}: {self.button_icon}
|
|
{Location.FLAG_LOCATION}: {self.location}
|
|
{self.FLAG_ACTIVE}: {self.active}
|
|
{self.FLAG_CREATED_ON}: {self.created_on}
|
|
)
|
|
'''
|
|
# {Command_Category.FLAG_COMMAND_CATEGORY}: {self.id_command_category}
|
|
|
|
class Command_Button_Link_Temp(db.Model, Base):
|
|
__tablename__ = 'DOG_Command_Button_Link_Temp'
|
|
__table_args__ = { 'extend_existing': True }
|
|
id_temp = db.Column(db.Integer, primary_key=True)
|
|
id_link = db.Column(db.Integer)
|
|
id_command = db.Column(db.Integer)
|
|
id_button_shape = db.Column(db.Integer)
|
|
id_button_colour = db.Column(db.Integer)
|
|
id_button_icon = db.Column(db.Integer)
|
|
id_location = db.Column(db.Integer)
|
|
active = db.Column(db.Boolean)
|
|
# created_on = db.Column(db.DateTime)
|
|
guid: str = db.Column(db.String(36))
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
@classmethod
|
|
def from_command_button_link(cls, command_button_link):
|
|
_m = 'Command_Button_Link_Temp.from_command_button_link'
|
|
temp = cls()
|
|
temp.id_link = command_button_link.id_link
|
|
temp.id_command = command_button_link.id_command
|
|
temp.id_button_shape = command_button_link.id_button_shape
|
|
temp.id_button_colour = command_button_link.id_button_colour
|
|
temp.id_button_icon = command_button_link.id_button_icon
|
|
temp.id_location = command_button_link.id_location
|
|
temp.active = command_button_link.active
|
|
# temp.created_on = command_button_link.created_on
|
|
return temp
|
|
|
|
|
|
class Parameters_Command_Button_Link(Get_Many_Parameters_Base):
|
|
get_all_link: bool
|
|
get_inactive_link: bool
|
|
ids_link: str
|
|
get_all_command_category: bool
|
|
get_inactive_command_category: bool
|
|
ids_command_category: str
|
|
names_command_category: str
|
|
get_all_command: bool
|
|
get_inactive_command: bool
|
|
ids_command: str
|
|
names_command: str
|
|
hand_signal_default_descriptions_command: str
|
|
notes_command: str
|
|
get_all_button_shape: bool
|
|
get_inactive_button_shape: bool
|
|
ids_button_shape: str
|
|
names_button_shape: str
|
|
notes_button_shape: str
|
|
get_all_colour: bool
|
|
get_inactive_colour: bool
|
|
ids_colour: str
|
|
names_colour: str
|
|
get_all_file_type: bool
|
|
get_inactive_file_type: bool
|
|
ids_file_type: str
|
|
names_file_type: str
|
|
get_all_image: bool
|
|
get_inactive_image: bool
|
|
ids_image: str
|
|
names_image: str
|
|
get_all_button_icon: bool
|
|
get_inactive_button_icon: bool
|
|
ids_button_icon: str
|
|
names_button_icon: str
|
|
notes_button_icon: str
|
|
get_all_location: bool
|
|
get_inactive_location: bool
|
|
ids_location: str
|
|
names_location: 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_link = True
|
|
, get_inactive_link = False
|
|
, ids_link = ''
|
|
, get_all_command_category = True
|
|
, get_inactive_command_category = False
|
|
, ids_command_category = ''
|
|
, names_command_category = ''
|
|
, get_all_command = True
|
|
, get_inactive_command = False
|
|
, ids_command = ''
|
|
, names_command = ''
|
|
, hand_signal_default_descriptions_command = ''
|
|
, notes_command = ''
|
|
, get_all_button_shape = True
|
|
, get_inactive_button_shape = False
|
|
, ids_button_shape = ''
|
|
, names_button_shape = ''
|
|
, notes_button_shape = ''
|
|
, get_all_colour = True
|
|
, get_inactive_colour = False
|
|
, ids_colour = ''
|
|
, names_colour = ''
|
|
, get_all_file_type = True
|
|
, get_inactive_file_type = False
|
|
, ids_file_type = ''
|
|
, names_file_type = ''
|
|
, get_all_image = True
|
|
, get_inactive_image = False
|
|
, ids_image = ''
|
|
, names_image = ''
|
|
, get_all_button_icon = True
|
|
, get_inactive_button_icon = False
|
|
, ids_button_icon = ''
|
|
, names_button_icon = ''
|
|
, notes_button_icon = ''
|
|
, get_all_location = True
|
|
, get_inactive_location = False
|
|
, ids_location = ''
|
|
, names_location = ''
|
|
, 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_link = json.get('a_get_all_link', False)
|
|
, get_inactive_link = json.get('a_get_inactive_link', False)
|
|
, ids_link = json.get('a_ids_link', '')
|
|
, get_all_command_category = json.get('a_get_all_command_category', False)
|
|
, get_inactive_command_category = json.get('a_get_inactive_command_category', False)
|
|
, ids_command_category = json.get('a_ids_command_category', '')
|
|
, names_command_category = json.get('a_names_command_category', '')
|
|
, 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', '')
|
|
, names_command = json.get('a_names_command', '')
|
|
, hand_signal_default_descriptions_command = json.get('a_hand_signal_default_descriptions_command', '')
|
|
, notes_command = json.get('a_notes_command', '')
|
|
, get_all_button_shape = json.get('a_get_all_button_shape', False)
|
|
, get_inactive_button_shape = json.get('a_get_inactive_button_shape', False)
|
|
, ids_button_shape = json.get('a_ids_button_shape', '')
|
|
, names_button_shape = json.get('a_names_button_shape', '')
|
|
, notes_button_shape = json.get('a_notes_button_shape', '')
|
|
, get_all_colour = json.get('a_get_all_colour', False)
|
|
, get_inactive_colour = json.get('a_get_inactive_colour', False)
|
|
, ids_colour = json.get('a_ids_colour', '')
|
|
, names_colour = json.get('a_names_colour', '')
|
|
, get_all_file_type = json.get('a_get_all_file_type', False)
|
|
, get_inactive_file_type = json.get('a_get_inactive_file_type', False)
|
|
, ids_file_type = json.get('a_ids_file_type', '')
|
|
, names_file_type = json.get('a_names_file_type', '')
|
|
, get_all_image = json.get('a_get_all_image', False)
|
|
, get_inactive_image = json.get('a_get_inactive_image', False)
|
|
, ids_image = json.get('a_ids_image', '')
|
|
, names_image = json.get('a_names_image', '')
|
|
, get_all_button_icon = json.get('a_get_all_button_icon', False)
|
|
, get_inactive_button_icon = json.get('a_get_inactive_button_icon', False)
|
|
, ids_button_icon = json.get('a_ids_button_icon', '')
|
|
, names_button_icon = json.get('a_names_button_icon', '')
|
|
, notes_button_icon = json.get('a_notes_button_icon', '')
|
|
, get_all_location = json.get('a_get_all_location', False)
|
|
, get_inactive_location = json.get('a_get_inactive_location', False)
|
|
, ids_location = json.get('a_ids_location', '')
|
|
, names_location = json.get('a_names_location', '')
|
|
, 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_button_link(cls, form):
|
|
_m = f'{cls.__qualname__}.from_form_filters_command_button_link'
|
|
Helper_App.console_log(_m)
|
|
Helper_App.console_log(f'Filters: {form}')
|
|
av.val_instance(form, 'form', _m, Filters_Command_Button_Link)
|
|
has_filter_search_text = not (form.search.data == '' or form.search.data is None)
|
|
has_filter_command_category = not (form.id_command_category.data == '0' or form.id_command_category.data == '' or form.id_command_category.data is None)
|
|
has_filter_command = not (form.id_command.data == '0' or form.id_command.data == '' or form.id_command.data is None)
|
|
has_filter_button_shape = not (form.id_button_shape.data == '0' or form.id_button_shape.data == '' or form.id_button_shape.data is None)
|
|
has_filter_colour = not (form.id_colour.data == '0' or form.id_colour.data == '' or form.id_colour.data is None)
|
|
has_filter_button_icon = not (form.id_button_icon.data == '0' or form.id_button_icon.data == '' or form.id_button_icon.data is None)
|
|
has_filter_location = not (form.id_location.data == '0' or form.id_location.data == '' or form.id_location.data is None)
|
|
active_only = av.input_bool(form.active_only.data, "active", _m)
|
|
Helper_App.console_log(f'''
|
|
has_filter_search_text: {has_filter_search_text}
|
|
has_filter_command_category: {has_filter_command_category}
|
|
has_filter_command: {has_filter_command}
|
|
has_filter_button_shape: {has_filter_button_shape}
|
|
has_filter_colour: {has_filter_colour}
|
|
has_filter_button_icon: {has_filter_button_icon}
|
|
has_filter_location: {has_filter_location}
|
|
active_only: {active_only}
|
|
''')
|
|
filters = cls.get_default()
|
|
filters.get_all_link = True
|
|
filters.get_inactive_link = not active_only
|
|
filters.ids_link = ''
|
|
filters.get_all_command_category = not has_filter_command_category
|
|
filters.get_inactive_command_category = not active_only
|
|
filters.ids_command_category = form.id_command_category.data if has_filter_command_category else ''
|
|
filters.names_command_category = form.search.data if has_filter_search_text else ''
|
|
filters.get_all_command = not has_filter_command
|
|
filters.get_inactive_command = not active_only
|
|
filters.ids_command = form.id_command.data if has_filter_command else ''
|
|
filters.names_command = form.search.data if has_filter_search_text else ''
|
|
filters.hand_signal_default_descriptions_command = form.search.data if has_filter_search_text else ''
|
|
filters.notes_command = form.search.data if has_filter_search_text else ''
|
|
filters.get_all_button_shape = not has_filter_button_shape
|
|
filters.get_inactive_button_shape = not active_only
|
|
filters.ids_button_shape = form.id_button_shape.data if has_filter_button_shape else ''
|
|
filters.names_button_shape = form.search.data if has_filter_search_text else ''
|
|
filters.notes_button_shape = form.search.data if has_filter_search_text else ''
|
|
filters.get_all_colour = not has_filter_colour
|
|
filters.get_inactive_colour = not active_only
|
|
filters.ids_colour = form.id_colour.data if has_filter_colour else ''
|
|
filters.names_colour = form.search.data if has_filter_search_text else ''
|
|
filters.get_all_file_type = True
|
|
filters.get_inactive_file_type = False
|
|
filters.ids_file_type = ''
|
|
filters.names_file_type = ''
|
|
filters.get_all_image = True
|
|
filters.get_inactive_image = False
|
|
filters.ids_image = ''
|
|
filters.names_image = ''
|
|
filters.get_all_button_icon = not has_filter_button_icon
|
|
filters.get_inactive_button_icon = not active_only
|
|
filters.ids_button_icon = form.id_button_icon.data if has_filter_button_icon else ''
|
|
filters.names_button_icon = form.search.data if has_filter_search_text else ''
|
|
filters.notes_button_icon = form.search.data if has_filter_search_text else ''
|
|
filters.get_all_location = not has_filter_location
|
|
filters.get_inactive_location = not active_only
|
|
filters.ids_location = form.id_location.data if has_filter_location else ''
|
|
filters.names_location = form.search.data if has_filter_search_text else ''
|
|
return filters
|
|
|
|
def to_json(self):
|
|
return {
|
|
'a_get_all_link': self.get_all_link
|
|
, 'a_get_inactive_link': self.get_inactive_link
|
|
, 'a_ids_link': self.ids_link
|
|
, 'a_get_all_command_category': self.get_all_command_category
|
|
, 'a_get_inactive_command_category': self.get_inactive_command_category
|
|
, 'a_ids_command_category': self.ids_command_category
|
|
, 'a_names_command_category': self.names_command_category
|
|
, 'a_get_all_command': self.get_all_command
|
|
, 'a_get_inactive_command': self.get_inactive_command
|
|
, 'a_ids_command': self.ids_command
|
|
, 'a_names_command': self.names_command
|
|
, 'a_hand_signal_default_descriptions_command': self.hand_signal_default_descriptions_command
|
|
, 'a_notes_command': self.notes_command
|
|
, 'a_get_all_button_shape': self.get_all_button_shape
|
|
, 'a_get_inactive_button_shape': self.get_inactive_button_shape
|
|
, 'a_ids_button_shape': self.ids_button_shape
|
|
, 'a_names_button_shape': self.names_button_shape
|
|
, 'a_notes_button_shape': self.notes_button_shape
|
|
, 'a_get_all_colour': self.get_all_colour
|
|
, 'a_get_inactive_colour': self.get_inactive_colour
|
|
, 'a_ids_colour': self.ids_colour
|
|
, 'a_names_colour': self.names_colour
|
|
, 'a_get_all_file_type': self.get_all_file_type
|
|
, 'a_get_inactive_file_type': self.get_inactive_file_type
|
|
, 'a_ids_file_type': self.ids_file_type
|
|
, 'a_names_file_type': self.names_file_type
|
|
, 'a_get_all_image': self.get_all_image
|
|
, 'a_get_inactive_image': self.get_inactive_image
|
|
, 'a_ids_image': self.ids_image
|
|
, 'a_names_image': self.names_image
|
|
, 'a_get_all_button_icon': self.get_all_button_icon
|
|
, 'a_get_inactive_button_icon': self.get_inactive_button_icon
|
|
, 'a_ids_button_icon': self.ids_button_icon
|
|
, 'a_names_button_icon': self.names_button_icon
|
|
, 'a_notes_button_icon': self.notes_button_icon
|
|
, 'a_get_all_location': self.get_all_location
|
|
, 'a_get_inactive_location': self.get_inactive_location
|
|
, 'a_ids_location': self.ids_location
|
|
, 'a_names_location': self.names_location
|
|
, '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
|
|
}
|
|
|
|
|