Feat(SQL, UI): Button Icons page, Command Button Links page created with get and set functionality.
This commit is contained in:
@@ -58,6 +58,7 @@ class Base():
|
||||
FLAG_NAME_SINGULAR: ClassVar[str] = 'name_singular'
|
||||
FLAG_NAME_PLURAL: ClassVar[str] = 'name_plural'
|
||||
FLAG_NOTES: ClassVar[str] = "notes"
|
||||
FLAG_PATH: ClassVar[str] = 'path'
|
||||
FLAG_PHONE_NUMBER: ClassVar[str] = 'phone_number'
|
||||
FLAG_POSTCODE: ClassVar[str] = 'postcode'
|
||||
FLAG_PRIORITY: ClassVar[str] = 'priority'
|
||||
|
||||
258
business_objects/dog/button_icon.py
Normal file
258
business_objects/dog/button_icon.py
Normal file
@@ -0,0 +1,258 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Business Objects
|
||||
Feature: Button_Icon Business Object
|
||||
"""
|
||||
|
||||
# internal
|
||||
from business_objects.base import Base
|
||||
from business_objects.db_base import SQLAlchemy_ABC, Get_Many_Parameters_Base
|
||||
from business_objects.dog.image import Image
|
||||
import lib.argument_validation as av
|
||||
from extensions import db
|
||||
from forms.dog.button_icon import Filters_Button_Icon
|
||||
from helpers.helper_app import Helper_App
|
||||
# external
|
||||
from dataclasses import dataclass
|
||||
from typing import ClassVar
|
||||
|
||||
|
||||
class Button_Icon(SQLAlchemy_ABC, Base):
|
||||
ATTR_ID_BUTTON_ICON: ClassVar[str] = 'id_button_icon'
|
||||
FLAG_BUTTON_ICON: ClassVar[str] = 'button_icon'
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = ATTR_ID_BUTTON_ICON
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = Base.FLAG_NAME
|
||||
|
||||
__tablename__ = 'DOG_Button_Icon'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
|
||||
id_button_icon = db.Column(db.Integer, primary_key=True)
|
||||
id_image = db.Column(db.Integer)
|
||||
code = db.Column(db.String(250))
|
||||
name = db.Column(db.String(250))
|
||||
notes = db.Column(db.Text)
|
||||
active = db.Column(db.Boolean)
|
||||
created_on = db.Column(db.DateTime)
|
||||
|
||||
def __init__(self):
|
||||
self.id_button_icon = 0
|
||||
self.image = None
|
||||
self.is_new = False
|
||||
super().__init__()
|
||||
|
||||
@classmethod
|
||||
def from_db_button_icon(cls, query_row):
|
||||
_m = f'{cls.__qualname__}.from_db_button_icon'
|
||||
button_icon = cls()
|
||||
button_icon.id_button_icon = query_row[0]
|
||||
button_icon.id_image = query_row[1]
|
||||
button_icon.code = query_row[4]
|
||||
button_icon.name = query_row[5]
|
||||
button_icon.notes = query_row[6]
|
||||
button_icon.active = av.input_bool(query_row[7], 'active', _m)
|
||||
# button_icon.created_on = query_row[7]
|
||||
button_icon.image = Image.from_db_button_icon(query_row)
|
||||
return button_icon
|
||||
|
||||
@classmethod
|
||||
def from_db_command_button_link(cls, query_row):
|
||||
_m = f'{cls.__qualname__}.from_db_command_button_link'
|
||||
button_icon = cls()
|
||||
button_icon.id_button_icon = query_row[0]
|
||||
button_icon.name = query_row[4]
|
||||
button_icon.active = True
|
||||
button_icon.image = Image.from_db_command_button_link(query_row)
|
||||
return button_icon
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
_m = f'{cls.__qualname__}.from_json'
|
||||
button_icon = cls()
|
||||
if json is None: return button_icon
|
||||
# Helper_App.console_log(f'{_m}\njson: {json}')
|
||||
button_icon.id_button_icon = json.get(Button_Icon.ATTR_ID_BUTTON_ICON, -1)
|
||||
button_icon.id_image = json[Image.FLAG_IMAGE]
|
||||
button_icon.name = json[cls.FLAG_NAME]
|
||||
button_icon.code = json.get(cls.FLAG_CODE, button_icon.name.upper().replace(" ", "_"))
|
||||
button_icon.notes = json[cls.FLAG_NOTES]
|
||||
button_icon.active = json[cls.FLAG_ACTIVE]
|
||||
button_icon.created_on = json.get(cls.FLAG_CREATED_ON, None)
|
||||
# Helper_App.console_log(f'Button_Icon: {button_icon}')
|
||||
return button_icon
|
||||
|
||||
def to_json(self):
|
||||
as_json = {
|
||||
**self.get_shared_json_attributes(self)
|
||||
, self.ATTR_ID_BUTTON_ICON: self.id_button_icon
|
||||
, Image.FLAG_IMAGE: self.id_image
|
||||
, self.FLAG_CODE: self.code
|
||||
, self.FLAG_NAME: self.name
|
||||
, self.FLAG_NOTES: self.notes
|
||||
, self.FLAG_ACTIVE: self.active
|
||||
, self.FLAG_CREATED_ON: self.created_on
|
||||
}
|
||||
# Helper_App.console_log(f'as_json: {as_json}')
|
||||
return as_json
|
||||
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.__class__.__name__}(
|
||||
{self.FLAG_BUTTON_ICON}: {self.id_button_icon}
|
||||
{Image.FLAG_IMAGE}: {self.id_image}
|
||||
{self.FLAG_CODE}: {self.code}
|
||||
{self.FLAG_NAME}: {self.name}
|
||||
{self.FLAG_NOTES}: {self.notes}
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
{self.FLAG_CREATED_ON}: {self.created_on}
|
||||
)
|
||||
'''
|
||||
|
||||
class Button_Icon_Temp(db.Model, Base):
|
||||
__tablename__ = 'DOG_Button_Icon_Temp'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_temp = db.Column(db.Integer, primary_key=True)
|
||||
id_button_icon = db.Column(db.Integer)
|
||||
id_image = db.Column(db.Integer)
|
||||
code = db.Column(db.String(250))
|
||||
name = db.Column(db.String(250))
|
||||
notes = db.Column(db.Text)
|
||||
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_button_icon(cls, button_icon):
|
||||
_m = 'Button_Icon_Temp.from_button_icon'
|
||||
temp = cls()
|
||||
temp.id_button_icon = button_icon.id_button_icon
|
||||
temp.id_image = button_icon.id_image
|
||||
temp.code = button_icon.code
|
||||
temp.name = button_icon.name
|
||||
temp.notes = button_icon.notes
|
||||
temp.active = button_icon.active
|
||||
# temp.created_on = button_icon.created_on
|
||||
return temp
|
||||
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.__class__.__name__}(
|
||||
{Button_Icon.FLAG_BUTTON_ICON}: {self.id_button_icon}
|
||||
{Image.FLAG_IMAGE}: {self.id_image}
|
||||
{self.FLAG_CODE}: {self.code}
|
||||
{self.FLAG_NAME}: {self.name}
|
||||
{self.FLAG_NOTES}: {self.notes}
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
)
|
||||
'''
|
||||
|
||||
class Parameters_Button_Icon(Get_Many_Parameters_Base):
|
||||
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
|
||||
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_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 = ''
|
||||
, 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_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', '')
|
||||
, 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_button_icon(cls, form):
|
||||
av.val_instance(form, 'form', 'Parameters_Button_Icon.from_form_filters_button_icon', Filters_Button_Icon)
|
||||
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_Button_Icon.from_form_filters_button_icon")
|
||||
filters = cls.get_default()
|
||||
filters.get_all_file_type = True
|
||||
filters.get_inactive_file_type = not active_only
|
||||
filters.ids_file_type = ''
|
||||
filters.names_file_type = form.search.data if has_filter_search_text else ''
|
||||
filters.get_all_image = True
|
||||
filters.get_inactive_image = not active_only
|
||||
filters.ids_image = ''
|
||||
filters.names_image = form.search.data if has_filter_search_text else ''
|
||||
filters.get_all_button_icon = True
|
||||
filters.get_inactive_button_icon = not active_only
|
||||
filters.ids_button_icon = ''
|
||||
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 ''
|
||||
return filters
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
'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_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
|
||||
}
|
||||
|
||||
207
business_objects/dog/button_shape.py
Normal file
207
business_objects/dog/button_shape.py
Normal file
@@ -0,0 +1,207 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Business Objects
|
||||
Feature: Button Shape Business Object
|
||||
"""
|
||||
|
||||
# internal
|
||||
from business_objects.base import Base
|
||||
from business_objects.db_base import SQLAlchemy_ABC, Get_Many_Parameters_Base
|
||||
from business_objects.dog.image import Image
|
||||
import lib.argument_validation as av
|
||||
from extensions import db
|
||||
# from forms.dog.button_shape import Filters_Button_Shape
|
||||
from helpers.helper_app import Helper_App
|
||||
# external
|
||||
from dataclasses import dataclass
|
||||
from typing import ClassVar
|
||||
|
||||
|
||||
class Button_Shape(SQLAlchemy_ABC, Base):
|
||||
ATTR_ID_BUTTON_SHAPE: ClassVar[str] = 'id_button_shape'
|
||||
FLAG_BUTTON_SHAPE: ClassVar[str] = 'button_shape'
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = ATTR_ID_BUTTON_SHAPE
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = Base.FLAG_NAME
|
||||
|
||||
__tablename__ = 'DOG_Button_Shape'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
|
||||
id_button_shape = db.Column(db.Integer, primary_key=True)
|
||||
code = db.Column(db.String(250))
|
||||
name = db.Column(db.String(250))
|
||||
notes = db.Column(db.Text)
|
||||
active = db.Column(db.Boolean)
|
||||
created_on = db.Column(db.DateTime)
|
||||
|
||||
def __init__(self):
|
||||
self.id_button_shape = 0
|
||||
self.is_new = False
|
||||
super().__init__()
|
||||
|
||||
@classmethod
|
||||
def from_db_button_shape(cls, query_row):
|
||||
_m = f'{cls.__qualname__}.from_db_button_shape'
|
||||
button_shape = cls()
|
||||
button_shape.id_button_shape = query_row[0]
|
||||
button_shape.code = query_row[1]
|
||||
button_shape.name = query_row[2]
|
||||
button_shape.notes = query_row[3]
|
||||
button_shape.active = av.input_bool(query_row[4], 'active', _m)
|
||||
return button_shape
|
||||
|
||||
@classmethod
|
||||
def from_db_command_button_link(cls, query_row):
|
||||
_m = f'{cls.__qualname__}.from_db_command_button_link'
|
||||
button_shape = cls()
|
||||
button_shape.id_button_shape = query_row[5]
|
||||
button_shape.name = query_row[6]
|
||||
button_shape.active = True
|
||||
return button_shape
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
_m = f'{cls.__qualname__}.from_json'
|
||||
button_shape = cls()
|
||||
if json is None: return button_shape
|
||||
# Helper_App.console_log(f'{_m}\njson: {json}')
|
||||
button_shape.id_button_shape = json.get(Button_Shape.ATTR_ID_BUTTON_SHAPE, -1)
|
||||
button_shape.name = json[cls.FLAG_NAME]
|
||||
button_shape.code = json.get(cls.FLAG_CODE, button_shape.name.upper().replace(" ", "_"))
|
||||
button_shape.notes = json[cls.FLAG_NOTES]
|
||||
button_shape.active = json[cls.FLAG_ACTIVE]
|
||||
button_shape.created_on = json.get(cls.FLAG_CREATED_ON, None)
|
||||
# Helper_App.console_log(f'Button_Shape: {button_shape}')
|
||||
return button_shape
|
||||
|
||||
def to_json(self):
|
||||
as_json = {
|
||||
**self.get_shared_json_attributes(self)
|
||||
, self.ATTR_ID_BUTTON_SHAPE: self.id_button_shape
|
||||
, self.FLAG_CODE: self.code
|
||||
, self.FLAG_NAME: self.name
|
||||
, self.FLAG_NOTES: self.notes
|
||||
, self.FLAG_ACTIVE: self.active
|
||||
, self.FLAG_CREATED_ON: self.created_on
|
||||
}
|
||||
# Helper_App.console_log(f'as_json: {as_json}')
|
||||
return as_json
|
||||
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.__class__.__name__}(
|
||||
{self.FLAG_BUTTON_SHAPE}: {self.id_button_shape}
|
||||
{self.FLAG_CODE}: {self.code}
|
||||
{self.FLAG_NAME}: {self.name}
|
||||
{self.FLAG_NOTES}: {self.notes}
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
{self.FLAG_CREATED_ON}: {self.created_on}
|
||||
)
|
||||
'''
|
||||
|
||||
class Button_Shape_Temp(db.Model, Base):
|
||||
__tablename__ = 'DOG_Button_Shape_Temp'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_temp = db.Column(db.Integer, primary_key=True)
|
||||
id_button_shape = db.Column(db.Integer)
|
||||
code = db.Column(db.String(250))
|
||||
name = db.Column(db.String(250))
|
||||
notes = db.Column(db.Text)
|
||||
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_button_shape(cls, button_shape):
|
||||
_m = 'Button_Shape_Temp.from_button_shape'
|
||||
temp = cls()
|
||||
temp.id_button_shape = button_shape.id_button_shape
|
||||
temp.code = button_shape.code
|
||||
temp.name = button_shape.name
|
||||
temp.notes = button_shape.notes
|
||||
temp.active = button_shape.active
|
||||
# temp.created_on = button_shape.created_on
|
||||
return temp
|
||||
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.__class__.__name__}(
|
||||
{Button_Shape.FLAG_BUTTON_SHAPE}: {self.id_button_shape}
|
||||
{self.FLAG_CODE}: {self.code}
|
||||
{self.FLAG_NAME}: {self.name}
|
||||
{self.FLAG_NOTES}: {self.notes}
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
)
|
||||
'''
|
||||
|
||||
class Parameters_Button_Shape(Get_Many_Parameters_Base):
|
||||
get_all_button_shape: bool
|
||||
get_inactive_button_shape: bool
|
||||
ids_button_shape: str
|
||||
names_button_shape: str
|
||||
notes_button_shape: 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_button_shape = True
|
||||
, get_inactive_button_shape = False
|
||||
, ids_button_shape = ''
|
||||
, names_button_shape = ''
|
||||
, notes_button_shape = ''
|
||||
, 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_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', '')
|
||||
, 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_button_shape(cls, form):
|
||||
av.val_instance(form, 'form', 'Parameters_Button_Shape.from_form_filters_button_shape', Filters_Button_Shape)
|
||||
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_Button_Shape.from_form_filters_button_shape")
|
||||
filters = cls.get_default()
|
||||
filters.get_all_button_shape = True
|
||||
filters.get_inactive_button_shape = not active_only
|
||||
filters.ids_button_shape = ''
|
||||
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 ''
|
||||
return filters
|
||||
"""
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
'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_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
|
||||
}
|
||||
193
business_objects/dog/colour.py
Normal file
193
business_objects/dog/colour.py
Normal file
@@ -0,0 +1,193 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Business Objects
|
||||
Feature: Colour Business Object
|
||||
"""
|
||||
|
||||
# internal
|
||||
from business_objects.base import Base
|
||||
from business_objects.db_base import SQLAlchemy_ABC, Get_Many_Parameters_Base
|
||||
from business_objects.dog.image import Image
|
||||
import lib.argument_validation as av
|
||||
from extensions import db
|
||||
# from forms.dog.colour import Filters_Colour
|
||||
from helpers.helper_app import Helper_App
|
||||
# external
|
||||
from dataclasses import dataclass
|
||||
from typing import ClassVar
|
||||
|
||||
|
||||
class Colour(SQLAlchemy_ABC, Base):
|
||||
ATTR_ID_COLOUR: ClassVar[str] = 'id_colour'
|
||||
FLAG_COLOUR: ClassVar[str] = 'colour'
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = ATTR_ID_COLOUR
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = Base.FLAG_NAME
|
||||
|
||||
__tablename__ = 'DOG_Colour'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
|
||||
id_colour = db.Column(db.Integer, primary_key=True)
|
||||
code = db.Column(db.String(250))
|
||||
name = db.Column(db.String(250))
|
||||
active = db.Column(db.Boolean)
|
||||
created_on = db.Column(db.DateTime)
|
||||
|
||||
def __init__(self):
|
||||
self.id_colour = 0
|
||||
self.is_new = False
|
||||
super().__init__()
|
||||
|
||||
@classmethod
|
||||
def from_db_colour(cls, query_row):
|
||||
_m = f'{cls.__qualname__}.from_db_colour'
|
||||
colour = cls()
|
||||
colour.id_colour = query_row[0]
|
||||
colour.code = query_row[1]
|
||||
colour.name = query_row[2]
|
||||
colour.active = av.input_bool(query_row[3], 'active', _m)
|
||||
return colour
|
||||
|
||||
@classmethod
|
||||
def from_db_command_button_link(cls, query_row):
|
||||
_m = f'{cls.__qualname__}.from_db_command_button_link'
|
||||
colour = cls()
|
||||
colour.id_colour = query_row[7]
|
||||
colour.name = query_row[8]
|
||||
colour.active = True
|
||||
return colour
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
_m = f'{cls.__qualname__}.from_json'
|
||||
colour = cls()
|
||||
if json is None: return colour
|
||||
# Helper_App.console_log(f'{_m}\njson: {json}')
|
||||
colour.id_colour = json.get(Colour.ATTR_ID_COLOUR, -1)
|
||||
colour.name = json[cls.FLAG_NAME]
|
||||
colour.code = json.get(cls.FLAG_CODE, colour.name.upper().replace(" ", "_"))
|
||||
colour.active = json[cls.FLAG_ACTIVE]
|
||||
colour.created_on = json.get(cls.FLAG_CREATED_ON, None)
|
||||
# Helper_App.console_log(f'Colour: {colour}')
|
||||
return colour
|
||||
|
||||
def to_json(self):
|
||||
as_json = {
|
||||
**self.get_shared_json_attributes(self)
|
||||
, self.ATTR_ID_COLOUR: self.id_colour
|
||||
, self.FLAG_CODE: self.code
|
||||
, self.FLAG_NAME: self.name
|
||||
, self.FLAG_ACTIVE: self.active
|
||||
, self.FLAG_CREATED_ON: self.created_on
|
||||
}
|
||||
# Helper_App.console_log(f'as_json: {as_json}')
|
||||
return as_json
|
||||
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.__class__.__name__}(
|
||||
{self.FLAG_COLOUR}: {self.id_colour}
|
||||
{self.FLAG_CODE}: {self.code}
|
||||
{self.FLAG_NAME}: {self.name}
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
{self.FLAG_CREATED_ON}: {self.created_on}
|
||||
)
|
||||
'''
|
||||
|
||||
class Colour_Temp(db.Model, Base):
|
||||
__tablename__ = 'DOG_Colour_Temp'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_temp = db.Column(db.Integer, primary_key=True)
|
||||
id_colour = db.Column(db.Integer)
|
||||
code = db.Column(db.String(250))
|
||||
name = db.Column(db.String(250))
|
||||
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_colour(cls, colour):
|
||||
_m = 'Colour_Temp.from_colour'
|
||||
temp = cls()
|
||||
temp.id_colour = colour.id_colour
|
||||
temp.code = colour.code
|
||||
temp.name = colour.name
|
||||
temp.active = colour.active
|
||||
# temp.created_on = colour.created_on
|
||||
return temp
|
||||
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.__class__.__name__}(
|
||||
{Colour.FLAG_COLOUR}: {self.id_colour}
|
||||
{self.FLAG_CODE}: {self.code}
|
||||
{self.FLAG_NAME}: {self.name}
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
)
|
||||
'''
|
||||
|
||||
class Parameters_Colour(Get_Many_Parameters_Base):
|
||||
get_all_colour: bool
|
||||
get_inactive_colour: bool
|
||||
ids_colour: str
|
||||
names_colour: 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_colour = True
|
||||
, get_inactive_colour = False
|
||||
, ids_colour = ''
|
||||
, names_colour = ''
|
||||
, 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_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', '')
|
||||
, 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_colour(cls, form):
|
||||
av.val_instance(form, 'form', 'Parameters_Colour.from_form_filters_colour', Filters_Colour)
|
||||
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_Colour.from_form_filters_colour")
|
||||
filters = cls.get_default()
|
||||
filters.get_all_colour = True
|
||||
filters.get_inactive_colour = not active_only
|
||||
filters.ids_colour = ''
|
||||
filters.names_colour = form.search.data if has_filter_search_text else ''
|
||||
return filters
|
||||
"""
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
'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_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
|
||||
}
|
||||
@@ -79,6 +79,16 @@ class Command(SQLAlchemy_ABC, Base):
|
||||
# command.created_on = query_row[7]
|
||||
command.command_category = Command_Category.from_db_dog_command_link(query_row) # this is done in datastore get many method using category dictionary
|
||||
return command
|
||||
|
||||
@classmethod
|
||||
def from_db_command_button_link(cls, query_row):
|
||||
_m = f'{cls.__qualname__}.from_db_command_button_link'
|
||||
command = cls()
|
||||
command.id_command = query_row[3]
|
||||
command.name = query_row[4]
|
||||
command.active = True
|
||||
command.command_category = Command_Category.from_db_command_button_link(query_row)
|
||||
return command
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
@@ -86,7 +96,7 @@ class Command(SQLAlchemy_ABC, Base):
|
||||
command = cls()
|
||||
if json is None: return command
|
||||
# Helper_App.console_log(f'{_m}\njson: {json}')
|
||||
command.id_command = -1
|
||||
command.id_command = json.get(Command.ATTR_ID_COMMAND, -1)
|
||||
command.id_command_category = json[Command_Category.ATTR_ID_COMMAND_CATEGORY]
|
||||
command.name = json[cls.FLAG_NAME]
|
||||
command.hand_signal_default_description = json[cls.FLAG_HAND_SIGNAL_DEFAULT_DESCRIPTION]
|
||||
|
||||
412
business_objects/dog/command_button_link.py
Normal file
412
business_objects/dog/command_button_link.py
Normal file
@@ -0,0 +1,412 @@
|
||||
"""
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ class Command_Category(SQLAlchemy_ABC, Base):
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
|
||||
id_command_category = db.Column(db.Integer, primary_key=True)
|
||||
code = db.Column(db.String(100))
|
||||
code = db.Column(db.String(250))
|
||||
name = db.Column(db.String(250))
|
||||
active = db.Column(db.Boolean)
|
||||
|
||||
@@ -57,6 +57,15 @@ class Command_Category(SQLAlchemy_ABC, Base):
|
||||
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_json(cls, json):
|
||||
@@ -65,8 +74,8 @@ class Command_Category(SQLAlchemy_ABC, Base):
|
||||
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.code = json[cls.FLAG_CODE]
|
||||
command_category.name = json[cls.FLAG_NAME]
|
||||
command_category.code = json.get(cls.FLAG_CODE, command_category.name.upper().replace(" ", "_"))
|
||||
command_category.active = json[cls.FLAG_ACTIVE]
|
||||
# Helper_App.console_log(f'Command_Category: {command_category}')
|
||||
return command_category
|
||||
@@ -99,7 +108,7 @@ class Command_Category_Temp(db.Model, Base):
|
||||
__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))
|
||||
# code = db.Column(db.String(250))
|
||||
name = db.Column(db.String(250))
|
||||
active = db.Column(db.Boolean)
|
||||
guid: str = db.Column(db.String(36))
|
||||
|
||||
@@ -27,7 +27,7 @@ class Understanding_Level(SQLAlchemy_ABC, Base):
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
|
||||
id_understanding_level = db.Column(db.Integer, primary_key=True)
|
||||
code = db.Column(db.String(100))
|
||||
code = db.Column(db.String(250))
|
||||
name = db.Column(db.String(250))
|
||||
active = db.Column(db.Boolean)
|
||||
|
||||
@@ -85,7 +85,7 @@ class Understanding_Level_Temp(db.Model, Base):
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_temp = db.Column(db.Integer, primary_key=True)
|
||||
id_understanding_level = db.Column(db.Integer)
|
||||
code = db.Column(db.String(100))
|
||||
code = db.Column(db.String(250))
|
||||
name = db.Column(db.String(250))
|
||||
active = db.Column(db.Boolean)
|
||||
guid: str = db.Column(db.String(36))
|
||||
@@ -74,7 +74,7 @@ class Dog(SQLAlchemy_ABC, Base):
|
||||
dog = cls()
|
||||
if json is None: return Dog
|
||||
# Helper_App.console_log(f'{_m}\njson: {json}')
|
||||
dog.id_dog = -1
|
||||
dog.id_dog = json.get(Dog.ATTR_ID_DOG, -1)
|
||||
dog.name = json[cls.FLAG_NAME]
|
||||
dog.appearance = json[cls.FLAG_APPEARANCE]
|
||||
dog.mass_kg = json[cls.FLAG_MASS_KG]
|
||||
|
||||
@@ -70,7 +70,7 @@ 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_link = -1
|
||||
dog_command_link.id_link = json.get(Dog_Command_Link.ATTR_ID_DOG_COMMAND_LINK, -1)
|
||||
dog_command_link.id_dog = json[Dog.ATTR_ID_DOG]
|
||||
dog_command_link.id_command = json[Command.ATTR_ID_COMMAND]
|
||||
dog_command_link.hand_signal_description = json[cls.FLAG_HAND_SIGNAL_DESCRIPTION]
|
||||
|
||||
240
business_objects/dog/image.py
Normal file
240
business_objects/dog/image.py
Normal file
@@ -0,0 +1,240 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Business Objects
|
||||
Feature: Image Business Object
|
||||
"""
|
||||
|
||||
# internal
|
||||
from business_objects.base import Base
|
||||
from business_objects.db_base import SQLAlchemy_ABC, Get_Many_Parameters_Base
|
||||
from business_objects.file_type import File_Type
|
||||
from business_objects.dog.dog import Dog
|
||||
import lib.argument_validation as av
|
||||
from extensions import db
|
||||
# from forms.dog.image import Filters_Image
|
||||
from helpers.helper_app import Helper_App
|
||||
# external
|
||||
from dataclasses import dataclass
|
||||
from typing import ClassVar
|
||||
|
||||
|
||||
class Image(SQLAlchemy_ABC, Base):
|
||||
ATTR_ID_IMAGE: ClassVar[str] = 'id_image'
|
||||
FLAG_IMAGE: ClassVar[str] = 'image'
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = ATTR_ID_IMAGE
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = Base.FLAG_NAME
|
||||
|
||||
__tablename__ = 'DOG_Image'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
|
||||
id_image = db.Column(db.Integer, primary_key=True)
|
||||
id_file_type = db.Column(db.Integer)
|
||||
id_dog = db.Column(db.Integer)
|
||||
path = db.Column(db.String(1024))
|
||||
name = db.Column(db.String(1024))
|
||||
active = db.Column(db.Boolean)
|
||||
created_on = db.Column(db.DateTime)
|
||||
|
||||
def __init__(self):
|
||||
self.id_image = 0
|
||||
self.is_new = False
|
||||
super().__init__()
|
||||
|
||||
"""
|
||||
@classmethod
|
||||
def from_db_image(cls, query_row):
|
||||
_m = f'{cls.__qualname__}.from_db_image'
|
||||
image = cls()
|
||||
image.id_image = query_row[0]
|
||||
image.code = query_row[3]
|
||||
image.name = query_row[4]
|
||||
image.active = av.input_bool(query_row[5], 'active', _m)
|
||||
# image.created_on = query_row[7]
|
||||
return image
|
||||
"""
|
||||
@classmethod
|
||||
def from_db_button_icon(cls, query_row):
|
||||
_m = f'{cls.__qualname__}.from_db_button_icon'
|
||||
image = cls()
|
||||
image.id_image = query_row[1]
|
||||
image.path = query_row[2]
|
||||
image.name = query_row[3]
|
||||
image.active = True
|
||||
return image
|
||||
@classmethod
|
||||
def from_db_command_button_link(cls, query_row):
|
||||
_m = f'{cls.__qualname__}.from_db_command_button_link'
|
||||
image = cls()
|
||||
image.id_image = query_row[11]
|
||||
image.path = query_row[12]
|
||||
image.name = query_row[13]
|
||||
image.active = True
|
||||
return image
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
_m = f'{cls.__qualname__}.from_json'
|
||||
image = cls()
|
||||
if json is None: return image
|
||||
# Helper_App.console_log(f'{_m}\njson: {json}')
|
||||
image.id_image = json.get(Image.ATTR_ID_IMAGE, -1)
|
||||
image.id_file_type = json[File_Type.FLAG_FILE_TYPE]
|
||||
image.id_dog = json[Dog.FLAG_DOG]
|
||||
image.path = json[cls.FLAG_PATH]
|
||||
image.name = json[cls.FLAG_NAME]
|
||||
image.active = json[cls.FLAG_ACTIVE]
|
||||
image.created_on = json.get(cls.FLAG_CREATED_ON, None)
|
||||
# Helper_App.console_log(f'Image: {image}')
|
||||
return image
|
||||
|
||||
def to_json(self):
|
||||
as_json = {
|
||||
**self.get_shared_json_attributes(self)
|
||||
, self.ATTR_ID_IMAGE: self.id_image
|
||||
, self.FLAG_CODE: self.code
|
||||
, self.FLAG_NAME: self.name
|
||||
, self.FLAG_ACTIVE: self.active
|
||||
, self.FLAG_CREATED_ON: self.created_on
|
||||
}
|
||||
# Helper_App.console_log(f'as_json: {as_json}')
|
||||
return as_json
|
||||
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.__class__.__name__}(
|
||||
{self.FLAG_IMAGE}: {self.id_image}
|
||||
{self.FLAG_CODE}: {self.code}
|
||||
{self.FLAG_NAME}: {self.name}
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
{self.FLAG_CREATED_ON}: {self.created_on}
|
||||
)
|
||||
'''
|
||||
|
||||
class Image_Temp(db.Model, Base):
|
||||
__tablename__ = 'DOG_Image_Temp'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_temp = db.Column(db.Integer, primary_key=True)
|
||||
id_image = db.Column(db.Integer)
|
||||
code = db.Column(db.String(250))
|
||||
name = db.Column(db.String(250))
|
||||
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_image(cls, image):
|
||||
_m = 'Image_Temp.from_image'
|
||||
temp = cls()
|
||||
temp.id_image = image.id_image
|
||||
temp.id_image = image.id_image
|
||||
temp.code = image.code
|
||||
temp.name = image.name
|
||||
temp.active = image.active
|
||||
# temp.created_on = image.created_on
|
||||
return temp
|
||||
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.__class__.__name__}(
|
||||
{Image.FLAG_IMAGE}: {self.id_image}
|
||||
{Image.FLAG_IMAGE}: {self.id_image}
|
||||
{self.FLAG_CODE}: {self.code}
|
||||
{self.FLAG_NAME}: {self.name}
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
)
|
||||
'''
|
||||
|
||||
class Parameters_Image(Get_Many_Parameters_Base):
|
||||
get_all_file_type: bool
|
||||
get_inactive_file_type: bool
|
||||
ids_file_type: str
|
||||
names_file_type: str
|
||||
get_all_dog: bool
|
||||
get_inactive_dog: bool
|
||||
ids_dog: str
|
||||
names_dog: str
|
||||
get_all_image: bool
|
||||
get_inactive_image: bool
|
||||
ids_image: str
|
||||
names_image: 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_file_type = True
|
||||
, get_inactive_file_type = False
|
||||
, ids_file_type = ''
|
||||
, names_file_type = ''
|
||||
, get_all_dog = True
|
||||
, get_inactive_dog = False
|
||||
, ids_dog = ''
|
||||
, names_dog = ''
|
||||
, get_all_image = True
|
||||
, get_inactive_image = False
|
||||
, ids_image = ''
|
||||
, names_image = ''
|
||||
, 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_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_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', '')
|
||||
, names_dog = json.get('a_names_dog', '')
|
||||
, 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', '')
|
||||
, 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_image(cls, form):
|
||||
av.val_instance(form, 'form', 'Parameters_Image.from_form_filters_image', Filters_Image)
|
||||
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_Image.from_form_filters_image")
|
||||
filters = cls.get_default()
|
||||
filters.get_all_image = True
|
||||
filters.get_inactive_image = not active_only
|
||||
filters.ids_image = ''
|
||||
filters.names_image = form.search.data if has_filter_search_text else ''
|
||||
return filters
|
||||
"""
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
'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_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
|
||||
, 'a_output_images': self.output_images
|
||||
}
|
||||
|
||||
|
||||
@@ -9,12 +9,10 @@ Feature: Location Business Object
|
||||
|
||||
# internal
|
||||
from business_objects.base import Base
|
||||
from business_objects.dog.location_category import Location_Category
|
||||
from business_objects.db_base import SQLAlchemy_ABC, Get_Many_Parameters_Base
|
||||
import lib.argument_validation as av
|
||||
from extensions import db
|
||||
from forms.dog.location import Filters_Location
|
||||
from forms.dog.location_category import Filters_Location_Category
|
||||
from helpers.helper_app import Helper_App
|
||||
# external
|
||||
from dataclasses import dataclass
|
||||
@@ -32,19 +30,16 @@ class Location(SQLAlchemy_ABC, Base):
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
|
||||
id_location = db.Column(db.Integer, primary_key=True)
|
||||
id_location_category = db.Column(db.Integer)
|
||||
id_location_parent = db.Column(db.Integer)
|
||||
code = db.Column(db.String(250))
|
||||
name = db.Column(db.String(250))
|
||||
hand_signal_default_description = db.Column(db.Text)
|
||||
can_have_button = db.Column(db.Boolean)
|
||||
notes = db.Column(db.Text)
|
||||
active = db.Column(db.Boolean)
|
||||
created_on = db.Column(db.DateTime)
|
||||
|
||||
def __init__(self):
|
||||
self.id_location = 0
|
||||
self.location_category = None
|
||||
self.location_parent = None
|
||||
self.is_new = False
|
||||
self.has_button = False
|
||||
super().__init__()
|
||||
|
||||
@classmethod
|
||||
@@ -52,31 +47,23 @@ class Location(SQLAlchemy_ABC, Base):
|
||||
_m = f'{cls.__qualname__}.from_db_location'
|
||||
location = cls()
|
||||
location.id_location = query_row[0]
|
||||
location.id_location_category = query_row[1]
|
||||
location.name = query_row[2]
|
||||
location.hand_signal_default_description = query_row[3]
|
||||
location.can_have_button = av.input_bool(query_row[4], 'can_have_button', _m)
|
||||
# location.has_button = av.input_bool(query_row[7], 'has_button', _m)
|
||||
location.notes = query_row[5]
|
||||
location.active = av.input_bool(query_row[6], 'active', _m)
|
||||
location.id_location_parent = query_row[1]
|
||||
location.code = query_row[3]
|
||||
location.name = query_row[4]
|
||||
location.active = av.input_bool(query_row[5], 'active', _m)
|
||||
# location.created_on = query_row[7]
|
||||
# location.location_category = Location_Category.from_db_location(query_row)
|
||||
location.location_parent = cls()
|
||||
location.location_parent.id_location = location.id_location_parent
|
||||
location.location_parent.name = query_row[2]
|
||||
return location
|
||||
|
||||
@classmethod
|
||||
def from_db_dog_location_link(cls, query_row):
|
||||
_m = f'{cls.__qualname__}.from_db_dog_location_link'
|
||||
def from_db_command_button_link(cls, query_row):
|
||||
_m = f'{cls.__qualname__}.from_db_command_button_link'
|
||||
location = cls()
|
||||
location.id_location = query_row[5]
|
||||
location.id_location_category = query_row[3]
|
||||
location.name = query_row[6]
|
||||
# location.hand_signal_default_description = query_row[2]
|
||||
location.can_have_button = av.input_bool(query_row[8], 'can_have_button', _m)
|
||||
# location.has_button = av.input_bool(query_row[7], 'has_button', _m)
|
||||
# location.notes = query_row[4]
|
||||
location.active = True # av.input_bool(True, 'active', _m)
|
||||
# location.created_on = query_row[7]
|
||||
location.location_category = Location_Category.from_db_dog_location_link(query_row) # this is done in datastore get many method using category dictionary
|
||||
location.id_location = query_row[14]
|
||||
location.name = query_row[15]
|
||||
location.active = True
|
||||
return location
|
||||
|
||||
@classmethod
|
||||
@@ -85,12 +72,10 @@ class Location(SQLAlchemy_ABC, Base):
|
||||
location = cls()
|
||||
if json is None: return location
|
||||
# Helper_App.console_log(f'{_m}\njson: {json}')
|
||||
location.id_location = -1
|
||||
location.id_location_category = json[Location_Category.ATTR_ID_LOCATION_CATEGORY]
|
||||
location.id_location = json.get(Location.ATTR_ID_LOCATION, -1)
|
||||
location.id_location_parent = json[Location.FLAG_LOCATION_PARENT]
|
||||
location.name = json[cls.FLAG_NAME]
|
||||
location.hand_signal_default_description = json[cls.FLAG_HAND_SIGNAL_DEFAULT_DESCRIPTION]
|
||||
location.can_have_button = json[cls.FLAG_CAN_HAVE_BUTTON]
|
||||
location.notes = json[cls.FLAG_NOTES]
|
||||
location.code = json.get(cls.FLAG_CODE, location.name.upper().replace(" ", "_"))
|
||||
location.active = json[cls.FLAG_ACTIVE]
|
||||
location.created_on = json.get(cls.FLAG_CREATED_ON, None)
|
||||
# Helper_App.console_log(f'Location: {location}')
|
||||
@@ -100,11 +85,9 @@ class Location(SQLAlchemy_ABC, Base):
|
||||
as_json = {
|
||||
**self.get_shared_json_attributes(self)
|
||||
, self.ATTR_ID_LOCATION: self.id_location
|
||||
, Location_Category.ATTR_ID_LOCATION_CATEGORY: self.id_location_category
|
||||
, Location.FLAG_LOCATION_PARENT: self.id_location_parent
|
||||
, self.FLAG_CODE: self.code
|
||||
, self.FLAG_NAME: self.name
|
||||
, self.FLAG_HAND_SIGNAL_DEFAULT_DESCRIPTION: self.hand_signal_default_description
|
||||
, self.FLAG_CAN_HAVE_BUTTON: self.can_have_button
|
||||
, self.FLAG_NOTES: self.notes
|
||||
, self.FLAG_ACTIVE: self.active
|
||||
, self.FLAG_CREATED_ON: self.created_on
|
||||
}
|
||||
@@ -115,11 +98,9 @@ class Location(SQLAlchemy_ABC, Base):
|
||||
return f'''
|
||||
{self.__class__.__name__}(
|
||||
{self.FLAG_LOCATION}: {self.id_location}
|
||||
{Location_Category.FLAG_LOCATION_CATEGORY}: {self.id_location_category}
|
||||
{Location.FLAG_LOCATION_PARENT}: {self.id_location_parent}
|
||||
{self.FLAG_CODE}: {self.code}
|
||||
{self.FLAG_NAME}: {self.name}
|
||||
{self.FLAG_HAND_SIGNAL_DEFAULT_DESCRIPTION}: {self.hand_signal_default_description}
|
||||
{self.FLAG_CAN_HAVE_BUTTON}: {self.can_have_button}
|
||||
{self.FLAG_NOTES}: {self.notes}
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
{self.FLAG_CREATED_ON}: {self.created_on}
|
||||
)
|
||||
@@ -130,13 +111,11 @@ class Location_Temp(db.Model, Base):
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_temp = db.Column(db.Integer, primary_key=True)
|
||||
id_location = db.Column(db.Integer)
|
||||
id_location_category = db.Column(db.Integer)
|
||||
id_location_parent = db.Column(db.Integer)
|
||||
code = db.Column(db.String(250))
|
||||
name = db.Column(db.String(250))
|
||||
hand_signal_default_description = db.Column(db.Text)
|
||||
can_have_button = db.Column(db.Boolean)
|
||||
notes = db.Column(db.Text)
|
||||
active = db.Column(db.Boolean)
|
||||
created_on = db.Column(db.DateTime)
|
||||
# created_on = db.Column(db.DateTime)
|
||||
guid: str = db.Column(db.String(36))
|
||||
|
||||
def __init__(self):
|
||||
@@ -147,68 +126,56 @@ class Location_Temp(db.Model, Base):
|
||||
_m = 'Location_Temp.from_location'
|
||||
temp = cls()
|
||||
temp.id_location = location.id_location
|
||||
temp.id_location_category = location.id_location_category
|
||||
temp.id_location_parent = location.id_location_parent
|
||||
temp.code = location.code
|
||||
temp.name = location.name
|
||||
temp.hand_signal_default_description = location.hand_signal_default_description
|
||||
temp.can_have_button = location.can_have_button
|
||||
temp.notes = location.notes
|
||||
temp.active = location.active
|
||||
temp.created_on = location.created_on
|
||||
# temp.created_on = location.created_on
|
||||
return temp
|
||||
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.__class__.__name__}(
|
||||
{Location.FLAG_LOCATION}: {self.id_location}
|
||||
{Location.FLAG_LOCATION_PARENT}: {self.id_location_parent}
|
||||
{self.FLAG_CODE}: {self.code}
|
||||
{self.FLAG_NAME}: {self.name}
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
)
|
||||
'''
|
||||
|
||||
class Parameters_Location(Get_Many_Parameters_Base):
|
||||
get_all_location_category: bool
|
||||
get_inactive_location_category: bool
|
||||
ids_location_category: str
|
||||
names_location_category: str
|
||||
get_all_location: bool
|
||||
get_inactive_location: bool
|
||||
ids_location: str
|
||||
names_location: str
|
||||
hand_signal_default_descriptions_location: str
|
||||
notes_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
|
||||
output_location_categories: bool
|
||||
output_locations: bool
|
||||
|
||||
@classmethod
|
||||
def get_default(cls):
|
||||
return cls(
|
||||
get_all_location_category = True
|
||||
, get_inactive_location_category = False
|
||||
, ids_location_category = ''
|
||||
, names_location_category = ''
|
||||
, get_all_location = True
|
||||
get_all_location = True
|
||||
, get_inactive_location = False
|
||||
, ids_location = ''
|
||||
, names_location = ''
|
||||
, hand_signal_default_descriptions_location = ''
|
||||
, notes_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
|
||||
, output_location_categories = True
|
||||
, output_locations = True
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
return cls(
|
||||
get_all_location_category = json.get('a_get_all_location_category', False)
|
||||
, get_inactive_location_category = json.get('a_get_inactive_location_category', False)
|
||||
, ids_location_category = json.get('a_ids_location_category', '')
|
||||
, names_location_category = json.get('a_names_location_category', '')
|
||||
, get_all_location = json.get('a_get_all_location', False)
|
||||
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', '')
|
||||
, hand_signal_default_descriptions_location = json.get('a_hand_signal_default_descriptions_location', '')
|
||||
, notes_location = json.get('a_notes_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)
|
||||
@@ -221,54 +188,24 @@ class Parameters_Location(Get_Many_Parameters_Base):
|
||||
def from_form_filters_location(cls, form):
|
||||
av.val_instance(form, 'form', 'Parameters_Location.from_form_filters_location', Filters_Location)
|
||||
has_filter_search_text = not (form.search.data == '' or form.search.data is None)
|
||||
has_filter_location_category = not (has_filter_search_text or form.id_location_category.data == '0' or form.id_location_category.data == '' or form.id_location_category.data is None)
|
||||
active_only = av.input_bool(form.active_only.data, "active", "Parameters_Location.from_form_filters_location")
|
||||
filters = cls.get_default()
|
||||
filters.get_all_location_category = not has_filter_location_category
|
||||
filters.get_inactive_location_category = not active_only
|
||||
filters.ids_location_category = form.id_location_category.data if has_filter_location_category else ''
|
||||
filters.names_location_category = form.search.data if has_filter_search_text else ''
|
||||
filters.get_all_location = True
|
||||
filters.get_inactive_location = not active_only
|
||||
filters.ids_location = ''
|
||||
filters.names_location = form.search.data if has_filter_search_text else ''
|
||||
return filters
|
||||
|
||||
@classmethod
|
||||
def from_form_filters_location_category(cls, form):
|
||||
av.val_instance(form, 'form', 'Parameters_Location.from_form_filters_location_category', Filters_Location_Category)
|
||||
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_Location.from_form_filters_location")
|
||||
filters = cls.get_default()
|
||||
filters.get_all_location_category = True
|
||||
filters.get_inactive_location_category = not active_only
|
||||
filters.ids_location_category = ''
|
||||
filters.names_location_category = form.search.data if has_filter_search_text else ''
|
||||
filters.get_all_location = False
|
||||
filters.get_inactive_location = False
|
||||
filters.ids_location = ''
|
||||
filters.names_location = ''
|
||||
filters.require_all_id_search_filters_met = False
|
||||
filters.output_locations = False
|
||||
return filters
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
'a_get_all_location_category': self.get_all_location_category
|
||||
, 'a_get_inactive_location_category': self.get_inactive_location_category
|
||||
, 'a_ids_location_category': self.ids_location_category
|
||||
, 'a_names_location_category': self.names_location_category
|
||||
, 'a_get_all_location': self.get_all_location
|
||||
'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_hand_signal_default_descriptions_location': self.hand_signal_default_descriptions_location
|
||||
, 'a_notes_location': self.notes_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
|
||||
, 'a_output_location_categories': self.output_location_categories
|
||||
, 'a_output_locations': self.output_locations
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ class Obedience_Level(SQLAlchemy_ABC, Base):
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
|
||||
id_obedience_level = db.Column(db.Integer, primary_key=True)
|
||||
code = db.Column(db.String(100))
|
||||
code = db.Column(db.String(250))
|
||||
name = db.Column(db.String(250))
|
||||
active = db.Column(db.Boolean)
|
||||
|
||||
@@ -53,7 +53,7 @@ class Obedience_Level(SQLAlchemy_ABC, Base):
|
||||
obedience_level = cls()
|
||||
if json is None: return Obedience_Level
|
||||
Helper_App.console_log(f'{_m}\njson: {json}')
|
||||
obedience_level.id_obedience_level = -1
|
||||
obedience_level.id_obedience_level = json.get(Obedience_Level.ATTR_ID_OBEDIENCE_LEVEL, -1)
|
||||
obedience_level.code = json[cls.FLAG_CODE]
|
||||
obedience_level.name = json[cls.FLAG_NAME]
|
||||
obedience_level.active = json[cls.FLAG_ACTIVE]
|
||||
@@ -88,7 +88,7 @@ class Obedience_Level_Temp(db.Model, Base):
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_temp = db.Column(db.Integer, primary_key=True)
|
||||
id_obedience_level = db.Column(db.Integer)
|
||||
code = db.Column(db.String(100))
|
||||
code = db.Column(db.String(250))
|
||||
name = db.Column(db.String(250))
|
||||
active = db.Column(db.Boolean)
|
||||
guid: str = db.Column(db.String(36))
|
||||
|
||||
116
business_objects/file_type.py
Normal file
116
business_objects/file_type.py
Normal file
@@ -0,0 +1,116 @@
|
||||
"""
|
||||
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 File_Type(SQLAlchemy_ABC, Base):
|
||||
ATTR_ID_FILE_TYPE: ClassVar[str] = 'id_file_type'
|
||||
FLAG_FILE_TYPE: ClassVar[str] = 'command-category'
|
||||
FLAG_IS_IMAGE: ClassVar[str] = 'is_image'
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = ATTR_ID_FILE_TYPE
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = Base.FLAG_NAME
|
||||
|
||||
__tablename__ = 'CORE_File_Type'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
|
||||
id_file_type = db.Column(db.Integer, primary_key=True)
|
||||
code = db.Column(db.String(250))
|
||||
name = db.Column(db.String(250))
|
||||
is_image = db.Column(db.Boolean)
|
||||
active = db.Column(db.Boolean)
|
||||
|
||||
def __init__(self):
|
||||
self.id_file_type = 0
|
||||
self.is_new = False
|
||||
super().__init__()
|
||||
|
||||
@classmethod
|
||||
def from_db_file_type(cls, query_row):
|
||||
_m = f'{cls.__qualname__}.from_db_command'
|
||||
category = cls()
|
||||
category.id_file_type = query_row[0]
|
||||
category.code = query_row[1]
|
||||
category.name = query_row[2]
|
||||
category.is_image = av.input_bool(query_row[3], 'is_image', _m)
|
||||
category.active = av.input_bool(query_row[4], 'active', _m)
|
||||
# command.created_on = query_row[7]
|
||||
return category
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
_m = 'File_Type.from_json'
|
||||
file_type = cls()
|
||||
if json is None: return File_Type
|
||||
# Helper_App.console_log(f'{_m}\njson: {json}')
|
||||
file_type.id_file_type = json.get(cls.ATTR_ID_FILE_TYPE, -1)
|
||||
file_type.name = json[cls.FLAG_NAME]
|
||||
file_type.code = json.get(cls.FLAG_CODE, file_type.name.upper().replace(" ", "_"))
|
||||
file_type.is_image = json[cls.FLAG_IS_IMAGE]
|
||||
file_type.active = json[cls.FLAG_ACTIVE]
|
||||
# Helper_App.console_log(f'File_Type: {file_type}')
|
||||
return file_type
|
||||
|
||||
|
||||
def to_json(self):
|
||||
as_json = {
|
||||
**self.get_shared_json_attributes(self)
|
||||
, self.ATTR_ID_FILE_TYPE: self.id_file_type
|
||||
, self.FLAG_CODE: self.code
|
||||
, self.FLAG_NAME: self.name
|
||||
, self.FLAG_IS_IMAGE: self.is_image
|
||||
, 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_FILE_TYPE}: {self.id_file_type}
|
||||
{self.FLAG_CODE}: {self.code}
|
||||
{self.FLAG_NAME}: {self.name}
|
||||
{self.FLAG_IS_IMAGE}: {self.is_image}
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
)
|
||||
'''
|
||||
|
||||
|
||||
class File_Type_Temp(db.Model, Base):
|
||||
__tablename__ = 'CORE_File_Type_Temp'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_temp = db.Column(db.Integer, primary_key=True)
|
||||
id_file_type = db.Column(db.Integer)
|
||||
# code = db.Column(db.String(250))
|
||||
name = db.Column(db.String(250))
|
||||
is_image = db.Column(db.Boolean)
|
||||
active = db.Column(db.Boolean)
|
||||
guid: str = db.Column(db.String(36))
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
@classmethod
|
||||
def from_file_type(cls, file_type):
|
||||
_m = 'File_Type_Temp.from_File_Type'
|
||||
temp = cls()
|
||||
temp.id_file_type = file_type.id_file_type
|
||||
# temp.code = file_type.code
|
||||
temp.name = file_type.name
|
||||
temp.is_image = file_type.is_image
|
||||
temp.active = file_type.active
|
||||
return temp
|
||||
Reference in New Issue
Block a user