""" 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 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 = av.input_bool(json[cls.FLAG_ACTIVE], cls.FLAG_ACTIVE, _m) button_shape.created_on = json.get(cls.FLAG_CREATED_ON, None) 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 } 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 get_all_user: bool get_inactive_user: bool ids_user: str names_user: str emails_user: 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, id_user_session): return cls( get_all_button_shape = True , get_inactive_button_shape = False , ids_button_shape = '' , names_button_shape = '' , notes_button_shape = '' , get_all_user = False , get_inactive_user = False , ids_user = str(id_user_session) , names_user = '' , emails_user = '' , 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', '') , get_all_user = json.get('a_get_all_user', False) , get_inactive_user = json.get('a_get_inactive_user', False) , ids_user = json.get('a_ids_user', '') , names_user = json.get('a_names_user', '') , emails_user = json.get('a_emails_user', '') , 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_get_all_user': self.get_all_user , 'a_get_inactive_user': self.get_inactive_user , 'a_ids_user': self.ids_user , 'a_names_user': self.names_user , 'a_emails_user': self.emails_user , '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 }