Feat: Architecture redesign for Assessments, Commands, Modalities, Training Techniques, Reinforcement Schedules, Distractions, and Assessment Responses.
This commit is contained in:
207
business_objects/dog/deprecated/bribe.py
Normal file
207
business_objects/dog/deprecated/bribe.py
Normal file
@@ -0,0 +1,207 @@
|
||||
"""
|
||||
Project: PARTS Website
|
||||
Author: Edward Middleton-Smith
|
||||
Precision And Research Technology Systems Limited
|
||||
|
||||
Technology: Business Objects
|
||||
Feature: Bribe Business Object
|
||||
"""
|
||||
|
||||
# internal
|
||||
from business_objects.base import Base
|
||||
from business_objects.db_base import SQLAlchemy_ABC, Get_Many_Parameters_Base
|
||||
import lib.argument_validation as av
|
||||
from extensions import db
|
||||
from helpers.helper_app import Helper_App
|
||||
# external
|
||||
from dataclasses import dataclass
|
||||
from typing import ClassVar
|
||||
|
||||
|
||||
class Bribe(SQLAlchemy_ABC, Base):
|
||||
ATTR_ID_BRIBE: ClassVar[str] = 'id_bribe'
|
||||
FLAG_BRIBE: ClassVar[str] = 'bribe'
|
||||
NAME_ATTR_OPTION_VALUE: ClassVar[str] = ATTR_ID_BRIBE
|
||||
NAME_ATTR_OPTION_TEXT: ClassVar[str] = Base.FLAG_NAME
|
||||
|
||||
__tablename__ = 'DOG_Bribe'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
|
||||
id_bribe = db.Column(db.Integer, primary_key=True)
|
||||
code = db.Column(db.String(250))
|
||||
name = db.Column(db.String(250))
|
||||
active = db.Column(db.Boolean)
|
||||
|
||||
def __init__(self):
|
||||
self.id_bribe = 0
|
||||
self.is_new = False
|
||||
super().__init__()
|
||||
|
||||
@classmethod
|
||||
def from_db_bribe(cls, query_row):
|
||||
_m = f'{cls.__qualname__}.from_db_bribe'
|
||||
category = cls()
|
||||
category.id_bribe = query_row[0]
|
||||
category.code = query_row[1]
|
||||
category.name = query_row[2]
|
||||
category.active = av.input_bool(query_row[3], 'active', _m)
|
||||
# command.created_on = query_row[7]
|
||||
return category
|
||||
|
||||
@classmethod
|
||||
def from_db_distraction(cls, query_row):
|
||||
_m = f'{cls.__qualname__}.from_db_distraction'
|
||||
level = cls()
|
||||
level.id_bribe = query_row[2]
|
||||
level.name = query_row[3]
|
||||
level.active = True
|
||||
return level
|
||||
|
||||
@classmethod
|
||||
def from_db_assessment_command_link(cls, query_row):
|
||||
_m = f'{cls.__qualname__}.from_db_assessment_command_link'
|
||||
level = cls()
|
||||
level.id_bribe = query_row[9]
|
||||
level.name = query_row[10]
|
||||
level.active = True
|
||||
return level
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, json):
|
||||
_m = 'Bribe.from_json'
|
||||
bribe = cls()
|
||||
if json is None: return bribe
|
||||
bribe.id_bribe = json.get(cls.ATTR_ID_BRIBE, -1)
|
||||
bribe.name = json[cls.FLAG_NAME]
|
||||
bribe.code = json.get(cls.FLAG_CODE, bribe.name.upper().replace(" ", "_"))
|
||||
bribe.active = av.input_bool(json[cls.FLAG_ACTIVE], cls.FLAG_ACTIVE, _m)
|
||||
return bribe
|
||||
|
||||
|
||||
def to_json(self):
|
||||
as_json = {
|
||||
**self.get_shared_json_attributes(self)
|
||||
, self.ATTR_ID_BRIBE: self.id_bribe
|
||||
, self.FLAG_CODE: self.code
|
||||
, self.FLAG_NAME: self.name
|
||||
, self.FLAG_ACTIVE: self.active
|
||||
}
|
||||
return as_json
|
||||
|
||||
def __repr__(self):
|
||||
return f'''
|
||||
{self.__class__.__name__}(
|
||||
{self.FLAG_BRIBE}: {self.id_bribe}
|
||||
{self.FLAG_CODE}: {self.code}
|
||||
{self.FLAG_NAME}: {self.name}
|
||||
{self.FLAG_ACTIVE}: {self.active}
|
||||
)
|
||||
'''
|
||||
|
||||
|
||||
class Bribe_Temp(db.Model, Base):
|
||||
__tablename__ = 'DOG_Bribe_Temp'
|
||||
__table_args__ = { 'extend_existing': True }
|
||||
id_temp = db.Column(db.Integer, primary_key=True)
|
||||
id_bribe = db.Column(db.Integer)
|
||||
code = db.Column(db.String(250))
|
||||
name = db.Column(db.String(250))
|
||||
active = db.Column(db.Boolean)
|
||||
guid: str = db.Column(db.String(36))
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
@classmethod
|
||||
def from_bribe(cls, bribe):
|
||||
_m = 'Bribe_Temp.from_Bribe'
|
||||
temp = cls()
|
||||
temp.id_bribe = bribe.id_bribe
|
||||
temp.code = bribe.code
|
||||
temp.name = bribe.name
|
||||
temp.active = bribe.active
|
||||
return temp
|
||||
|
||||
|
||||
class Parameters_Bribe(Get_Many_Parameters_Base):
|
||||
get_all_bribe: bool
|
||||
get_inactive_bribe: bool
|
||||
ids_bribe: str
|
||||
names_bribe: 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_bribe = True
|
||||
, get_inactive_bribe = False
|
||||
, ids_bribe = ''
|
||||
, names_bribe = ''
|
||||
, 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_bribe = json.get('a_get_all_bribe', False)
|
||||
, get_inactive_bribe = json.get('a_get_inactive_bribe', False)
|
||||
, ids_bribe = json.get('a_ids_bribe', '')
|
||||
, names_bribe = json.get('a_names_bribe', '')
|
||||
, 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_bribe(cls, form):
|
||||
av.val_instance(form, 'form', 'Parameters_Bribe.from_form_filters_bribe', Filters_Bribe)
|
||||
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_Bribe.from_form_filters_bribe")
|
||||
filters = cls.get_default()
|
||||
filters.get_all_bribe = True
|
||||
filters.get_inactive_bribe = not active_only
|
||||
filters.ids_bribe = ''
|
||||
filters.names_bribe = form.search.data if has_filter_search_text else ''
|
||||
filters.notes_bribe = form.search.data if has_filter_search_text else ''
|
||||
return filters
|
||||
"""
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
'a_get_all_bribe': self.get_all_bribe
|
||||
, 'a_get_inactive_bribe': self.get_inactive_bribe
|
||||
, 'a_ids_bribe': self.ids_bribe
|
||||
, 'a_names_bribe': self.names_bribe
|
||||
, '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
|
||||
}
|
||||
Reference in New Issue
Block a user