656 lines
37 KiB
Python
656 lines
37 KiB
Python
"""
|
|
Project: PARTS Website
|
|
Author: Edward Middleton-Smith
|
|
Precision And Research Technology Systems Limited
|
|
|
|
Technology: Business Objects
|
|
Feature: Distraction 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.assessment import Assessment
|
|
from business_objects.dog.command import Command
|
|
# from business_objects.dog.command_category import Command_Category
|
|
from business_objects.dog.distraction_intensity_level import Distraction_Intensity_Level
|
|
from business_objects.dog.distraction_type import Distraction_Type
|
|
from business_objects.dog.dog import Dog
|
|
from extensions import db
|
|
from forms.dog.assessment import Filters_Assessment
|
|
# from forms.dog.distraction import Filters_Distraction
|
|
from helpers.helper_app import Helper_App
|
|
import lib.argument_validation as av
|
|
# external
|
|
from dataclasses import dataclass
|
|
from typing import ClassVar, Optional
|
|
|
|
|
|
class Distraction(SQLAlchemy_ABC, Base):
|
|
ATTR_ID_DISTRACTION: ClassVar[str] = 'id_distraction'
|
|
FLAG_DISTRACTION: ClassVar[str] = Assessment.FLAG_DISTRACTION
|
|
FLAG_DISTRACTION_INTENSITY_LEVEL_EMOTIONAL: ClassVar[str] = f'{Distraction_Intensity_Level.FLAG_DISTRACTION_INTENSITY_LEVEL}-emotional'
|
|
FLAG_DISTRACTION_INTENSITY_LEVEL_SCENT: ClassVar[str] = f'{Distraction_Intensity_Level.FLAG_DISTRACTION_INTENSITY_LEVEL}-scent'
|
|
FLAG_DISTRACTION_INTENSITY_LEVEL_SIGHT: ClassVar[str] = f'{Distraction_Intensity_Level.FLAG_DISTRACTION_INTENSITY_LEVEL}-sight'
|
|
FLAG_DISTRACTION_INTENSITY_LEVEL_SOUND: ClassVar[str] = f'{Distraction_Intensity_Level.FLAG_DISTRACTION_INTENSITY_LEVEL}-sound'
|
|
FLAG_DISTRACTION_INTENSITY_LEVEL_TOUCH: ClassVar[str] = f'{Distraction_Intensity_Level.FLAG_DISTRACTION_INTENSITY_LEVEL}-touch'
|
|
FLAG_PROXIMITY_METRES: ClassVar[str] = 'proximity-metres'
|
|
NAME_ATTR_OPTION_VALUE: ClassVar[str] = ATTR_ID_DISTRACTION
|
|
NAME_ATTR_OPTION_TEXT: ClassVar[str] = ATTR_ID_DISTRACTION
|
|
|
|
__tablename__ = 'DOG_Distraction'
|
|
__table_args__ = { 'extend_existing': True }
|
|
|
|
id_distraction = db.Column(db.Integer, primary_key=True)
|
|
id_assessment = db.Column(db.Integer)
|
|
id_distraction_type = db.Column(db.Integer)
|
|
id_intensity_level_emotional = db.Column(db.Integer)
|
|
id_intensity_level_scent = db.Column(db.Integer)
|
|
id_intensity_level_sight = db.Column(db.Integer)
|
|
id_intensity_level_sound = db.Column(db.Integer)
|
|
id_intensity_level_touch = db.Column(db.Integer)
|
|
quantity = db.Column(db.Integer)
|
|
proximity_metres = db.Column(db.Float)
|
|
notes = db.Column(db.Text)
|
|
active = db.Column(db.Boolean)
|
|
created_on = db.Column(db.DateTime)
|
|
|
|
def __init__(self):
|
|
self.id_distraction = 0
|
|
self.is_new = False
|
|
self.assessment = None
|
|
self.distraction_type = None
|
|
self.intensity_level_emotional = None
|
|
self.intensity_level_scent = None
|
|
self.intensity_level_sight = None
|
|
self.intensity_level_sound = None
|
|
self.intensity_level_touch = None
|
|
super().__init__()
|
|
|
|
@classmethod
|
|
def from_db_distraction(cls, query_row):
|
|
_m = 'Distraction.from_db_distraction'
|
|
distraction = cls()
|
|
distraction.id_distraction = query_row[0]
|
|
distraction.id_assessment = query_row[1]
|
|
distraction.id_distraction_type = query_row[2]
|
|
#distraction.id_command_category = query_row[3]
|
|
distraction.id_intensity_level_emotional = query_row[4]
|
|
distraction.id_intensity_level_scent = query_row[6]
|
|
distraction.id_intensity_level_sight = query_row[8]
|
|
distraction.id_intensity_level_sound = query_row[10]
|
|
distraction.id_intensity_level_touch = query_row[12]
|
|
distraction.quantity = query_row[14]
|
|
distraction.proximity_metres = query_row[15]
|
|
distraction.notes = query_row[16]
|
|
distraction.active = av.input_bool(query_row[17], 'active', _m)
|
|
# distraction.created_on = query_row[7]
|
|
distraction.assessment = Assessment.from_db_distraction(query_row)
|
|
distraction.distraction_type = Distraction_Type.from_db_distraction(query_row)
|
|
distraction.intensity_level_emotional = Distraction_Intensity_Level.from_db_distraction_emotional(query_row)
|
|
distraction.intensity_level_scent = Distraction_Intensity_Level.from_db_distraction_scent(query_row)
|
|
distraction.intensity_level_sight = Distraction_Intensity_Level.from_db_distraction_sight(query_row)
|
|
distraction.intensity_level_sound = Distraction_Intensity_Level.from_db_distraction_sound(query_row)
|
|
distraction.intensity_level_touch = Distraction_Intensity_Level.from_db_distraction_touch(query_row)
|
|
return distraction
|
|
|
|
@classmethod
|
|
def from_json(cls, json):
|
|
_m = 'Distraction.from_json'
|
|
distraction = cls()
|
|
if json is None: return distraction
|
|
# Helper_App.console_log(f'{_m}\njson: {json}')
|
|
distraction.id_distraction = json.get(cls.ATTR_ID_DISTRACTION, -1)
|
|
distraction.id_assessment = json[Assessment.ATTR_ID_ASSESSMENT]
|
|
distraction.id_distraction_type = json[Distraction_Type.ATTR_ID_DISTRACTION_TYPE]
|
|
distraction.id_intensity_level_emotional = json[cls.FLAG_DISTRACTION_INTENSITY_LEVEL_EMOTIONAL]
|
|
distraction.id_intensity_level_scent = json[cls.FLAG_DISTRACTION_INTENSITY_LEVEL_SCENT]
|
|
distraction.id_intensity_level_sight = json[cls.FLAG_DISTRACTION_INTENSITY_LEVEL_SIGHT]
|
|
distraction.id_intensity_level_sound = json[cls.FLAG_DISTRACTION_INTENSITY_LEVEL_SOUND]
|
|
distraction.id_intensity_level_touch = json[cls.FLAG_DISTRACTION_INTENSITY_LEVEL_TOUCH]
|
|
distraction.quantity = json[cls.FLAG_QUANTITY]
|
|
distraction.proximity_metres = json[cls.FLAG_PROXIMITY_METRES]
|
|
distraction.notes = json[cls.FLAG_NOTES]
|
|
distraction.active = json[cls.FLAG_ACTIVE]
|
|
distraction.created_on = json.get(cls.FLAG_CREATED_ON, None)
|
|
# distraction.id_command_category = json[Command_Category.FLAG_COMMAND_CATEGORY]
|
|
# Helper_App.console_log(f'Dog Command Link: {distraction}')
|
|
return distraction
|
|
|
|
def to_json(self):
|
|
as_json = {
|
|
**self.get_shared_json_attributes(self)
|
|
, self.ATTR_ID_DISTRACTION: self.id_distraction
|
|
, Assessment.ATTR_ID_ASSESSMENT: { Assessment.ATTR_ID_ASSESSMENT: None } if self.assessment is None else self.assessment.to_json()
|
|
, Distraction_Type.ATTR_ID_DISTRACTION_TYPE: { Distraction_Type.ATTR_ID_DISTRACTION_TYPE: None } if self.distraction_type is None else self.distraction_type.to_json()
|
|
, self.FLAG_DISTRACTION_INTENSITY_LEVEL_EMOTIONAL: { self.FLAG_DISTRACTION_INTENSITY_LEVEL_EMOTIONAL: None } if self.intensity_level_emotional is None else self.intensity_level_emotional.to_json()
|
|
, self.FLAG_DISTRACTION_INTENSITY_LEVEL_SCENT: { self.FLAG_DISTRACTION_INTENSITY_LEVEL_SCENT: None } if self.intensity_level_scent is None else self.intensity_level_scent.to_json()
|
|
, self.FLAG_DISTRACTION_INTENSITY_LEVEL_SIGHT: { self.FLAG_DISTRACTION_INTENSITY_LEVEL_SIGHT: None } if self.intensity_level_sight is None else self.intensity_level_sight.to_json()
|
|
, self.FLAG_DISTRACTION_INTENSITY_LEVEL_SOUND: { self.FLAG_DISTRACTION_INTENSITY_LEVEL_SOUND: None } if self.intensity_level_sound is None else self.intensity_level_sound.to_json()
|
|
, self.FLAG_DISTRACTION_INTENSITY_LEVEL_TOUCH: { self.FLAG_DISTRACTION_INTENSITY_LEVEL_TOUCH: None } if self.intensity_level_touch is None else self.intensity_level_touch.to_json()
|
|
, self.FLAG_QUANTITY: self.quantity
|
|
, self.FLAG_PROXIMITY_METRES: self.proximity_metres
|
|
, self.FLAG_NOTES: self.notes
|
|
, 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_DISTRACTION}: {self.id_distraction}
|
|
{Assessment.ATTR_ID_ASSESSMENT}: {self.id_assessment}
|
|
{Distraction_Type.ATTR_ID_DISTRACTION_TYPE}: {self.id_distraction_type}
|
|
{self.FLAG_DISTRACTION_INTENSITY_LEVEL_EMOTIONAL}: {self.intensity_level_emotional}
|
|
{self.FLAG_DISTRACTION_INTENSITY_LEVEL_SCENT}: {self.intensity_level_scent}
|
|
{self.FLAG_DISTRACTION_INTENSITY_LEVEL_SIGHT}: {self.intensity_level_sight}
|
|
{self.FLAG_DISTRACTION_INTENSITY_LEVEL_SOUND}: {self.intensity_level_sound}
|
|
{self.FLAG_DISTRACTION_INTENSITY_LEVEL_TOUCH}: {self.intensity_level_touch}
|
|
{self.FLAG_QUANTITY}: {self.quantity}
|
|
{self.FLAG_PROXIMITY_METRES}: {self.proximity_metres}
|
|
{self.FLAG_NOTES}: {self.notes}
|
|
{self.FLAG_ACTIVE}: {self.active}
|
|
{self.FLAG_CREATED_ON}: {self.created_on}
|
|
)
|
|
'''
|
|
# {Command_Category.FLAG_COMMAND_CATEGORY}: {self.id_command_category}
|
|
|
|
class Distraction_Temp(db.Model, Base):
|
|
__tablename__ = 'DOG_Distraction_Temp'
|
|
__table_args__ = { 'extend_existing': True }
|
|
id_temp = db.Column(db.Integer, primary_key=True)
|
|
id_distraction = db.Column(db.Integer)
|
|
id_assessment = db.Column(db.Integer)
|
|
id_distraction_type = db.Column(db.Integer)
|
|
id_intensity_level_emotional = db.Column(db.Integer)
|
|
id_intensity_level_scent = db.Column(db.Integer)
|
|
id_intensity_level_sight = db.Column(db.Integer)
|
|
id_intensity_level_sound = db.Column(db.Integer)
|
|
id_intensity_level_touch = db.Column(db.Integer)
|
|
quantity = db.Column(db.Integer)
|
|
proximity_metres = db.Column(db.Float)
|
|
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_distraction(cls, distraction):
|
|
_m = 'Distraction_Temp.from_distraction'
|
|
temp = cls()
|
|
temp.id_distraction = distraction.id_distraction
|
|
temp.id_assessment = distraction.id_assessment
|
|
temp.id_distraction_type = distraction.id_distraction_type
|
|
temp.id_intensity_level_emotional = distraction.id_intensity_level_emotional
|
|
temp.id_intensity_level_scent = distraction.id_intensity_level_scent
|
|
temp.id_intensity_level_sight = distraction.id_intensity_level_sight
|
|
temp.id_intensity_level_sound = distraction.id_intensity_level_sound
|
|
temp.id_intensity_level_touch = distraction.id_intensity_level_touch
|
|
temp.quantity = distraction.quantity
|
|
temp.proximity_metres = distraction.proximity_metres
|
|
temp.notes = distraction.notes
|
|
temp.active = distraction.active
|
|
# temp.created_on = distraction.created_on
|
|
return temp
|
|
|
|
|
|
class Parameters_Distraction(Get_Many_Parameters_Base):
|
|
get_all_distraction: bool
|
|
get_inactive_distraction: bool
|
|
ids_distraction: str
|
|
notes_distraction: str
|
|
min_quantity_distraction: Optional[int]
|
|
max_quantity_distraction: Optional[int]
|
|
min_proximity_metres_distraction: Optional[float]
|
|
max_proximity_metres_distraction: Optional[float]
|
|
|
|
get_all_distraction_type: bool
|
|
get_inactive_distraction_type: bool
|
|
ids_distraction_type: str
|
|
names_distraction_type: str
|
|
|
|
get_all_distraction_intensity_level_emotional: bool
|
|
get_inactive_distraction_intensity_level_emotional: bool
|
|
ids_distraction_intensity_level_emotional: str
|
|
names_distraction_intensity_level_emotional: str
|
|
|
|
get_all_distraction_intensity_level_scent: bool
|
|
get_inactive_distraction_intensity_level_scent: bool
|
|
ids_distraction_intensity_level_scent: str
|
|
names_distraction_intensity_level_scent: str
|
|
|
|
get_all_distraction_intensity_level_sight: bool
|
|
get_inactive_distraction_intensity_level_sight: bool
|
|
ids_distraction_intensity_level_sight: str
|
|
names_distraction_intensity_level_sight: str
|
|
|
|
get_all_distraction_intensity_level_sound: bool
|
|
get_inactive_distraction_intensity_level_sound: bool
|
|
ids_distraction_intensity_level_sound: str
|
|
names_distraction_intensity_level_sound: str
|
|
|
|
get_all_distraction_intensity_level_touch: bool
|
|
get_inactive_distraction_intensity_level_touch: bool
|
|
ids_distraction_intensity_level_touch: str
|
|
names_distraction_intensity_level_touch: str
|
|
|
|
get_all_assessment: bool
|
|
get_inactive_assessment: bool
|
|
ids_assessment: str
|
|
notes_assessment: str
|
|
min_temperature_assessment: Optional[float]
|
|
max_temperature_assessment: Optional[float]
|
|
get_all_weather: bool
|
|
get_inactive_weather: bool
|
|
ids_weather: str
|
|
names_weather: str
|
|
get_all_lighting_level: bool
|
|
get_inactive_lighting_level: bool
|
|
ids_lighting_level: str
|
|
names_lighting_level: str
|
|
get_all_location: bool
|
|
get_inactive_location: bool
|
|
ids_location: str
|
|
names_location: str
|
|
get_all_user_handler: bool
|
|
get_inactive_user_handler: bool
|
|
ids_user_handler: str
|
|
#auth0_ids_user_handler: str
|
|
names_user_handler: str
|
|
emails_user_handler: 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_distraction = True
|
|
, get_inactive_distraction = False
|
|
, ids_distraction = ''
|
|
, notes_distraction = ''
|
|
, min_quantity_distraction = None
|
|
, max_quantity_distraction = None
|
|
, min_proximity_metres_distraction = None
|
|
, max_proximity_metres_distraction = None
|
|
|
|
, get_all_distraction_type = True
|
|
, get_inactive_distraction_type = False
|
|
, ids_distraction_type = ''
|
|
, names_distraction_type = ''
|
|
|
|
, get_all_distraction_intensity_level_emotional = True
|
|
, get_inactive_distraction_intensity_level_emotional = False
|
|
, ids_distraction_intensity_level_emotional = ''
|
|
, names_distraction_intensity_level_emotional = ''
|
|
|
|
, get_all_distraction_intensity_level_scent = True
|
|
, get_inactive_distraction_intensity_level_scent = False
|
|
, ids_distraction_intensity_level_scent = ''
|
|
, names_distraction_intensity_level_scent = ''
|
|
|
|
, get_all_distraction_intensity_level_sight = True
|
|
, get_inactive_distraction_intensity_level_sight = False
|
|
, ids_distraction_intensity_level_sight = ''
|
|
, names_distraction_intensity_level_sight = ''
|
|
|
|
, get_all_distraction_intensity_level_sound = True
|
|
, get_inactive_distraction_intensity_level_sound = False
|
|
, ids_distraction_intensity_level_sound = ''
|
|
, names_distraction_intensity_level_sound = ''
|
|
|
|
, get_all_distraction_intensity_level_touch = True
|
|
, get_inactive_distraction_intensity_level_touch = False
|
|
, ids_distraction_intensity_level_touch = ''
|
|
, names_distraction_intensity_level_touch = ''
|
|
|
|
, get_all_assessment = True
|
|
, get_inactive_assessment = False
|
|
, ids_assessment = ''
|
|
, notes_assessment = ''
|
|
, min_temperature_assessment = None
|
|
, max_temperature_assessment = None
|
|
, get_all_weather = True
|
|
, get_inactive_weather = False
|
|
, ids_weather = ''
|
|
, names_weather = ''
|
|
, get_all_lighting_level = True
|
|
, get_inactive_lighting_level = False
|
|
, ids_lighting_level = ''
|
|
, names_lighting_level = ''
|
|
, get_all_location = True
|
|
, get_inactive_location = False
|
|
, ids_location = ''
|
|
, names_location = ''
|
|
, get_all_user_handler = True
|
|
, get_inactive_user_handler = False
|
|
, ids_user_handler = ''
|
|
# , auth0_ids_user_handler = ''
|
|
, names_user_handler = ''
|
|
, emails_user_handler = ''
|
|
|
|
, 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_distraction = json.get('a_get_all_distraction', False)
|
|
, get_inactive_distraction = json.get('a_get_inactive_distraction', False)
|
|
, ids_distraction = json.get('a_ids_distraction', '')
|
|
, notes_distraction = json.get('a_notes_distraction', '')
|
|
, min_quantity_distraction = json.get('a_min_quantity_distraction', None)
|
|
, max_quantity_distraction = json.get('a_max_quantity_distraction', None)
|
|
, min_proximity_metres_distraction = json.get('a_min_proximity_metres_distraction', None)
|
|
, max_proximity_metres_distraction = json.get('a_max_proximity_metres_distraction', None)
|
|
|
|
, get_all_distraction_type = json.get('a_get_all_distraction_type', False)
|
|
, get_inactive_distraction_type = json.get('a_get_inactive_distraction_type', False)
|
|
, ids_distraction_type = json.get('a_ids_distraction_type', '')
|
|
, names_distraction_type = json.get('a_names_distraction_type', '')
|
|
|
|
, get_all_distraction_intensity_level_emotional = json.get('a_get_all_distraction_intensity_level_emotional', False)
|
|
, get_inactive_distraction_intensity_level_emotional = json.get('a_get_inactive_distraction_intensity_level_emotional', False)
|
|
, ids_distraction_intensity_level_emotional = json.get('a_ids_distraction_intensity_level_emotional', '')
|
|
, names_distraction_intensity_level_emotional = json.get('a_names_distraction_intensity_level_emotional', '')
|
|
|
|
, get_all_distraction_intensity_level_scent = json.get('a_get_all_distraction_intensity_level_scent', False)
|
|
, get_inactive_distraction_intensity_level_scent = json.get('a_get_inactive_distraction_intensity_level_scent', False)
|
|
, ids_distraction_intensity_level_scent = json.get('a_ids_distraction_intensity_level_scent', '')
|
|
, names_distraction_intensity_level_scent = json.get('a_names_distraction_intensity_level_scent', '')
|
|
|
|
, get_all_distraction_intensity_level_sight = json.get('a_get_all_distraction_intensity_level_sight', False)
|
|
, get_inactive_distraction_intensity_level_sight = json.get('a_get_inactive_distraction_intensity_level_sight', False)
|
|
, ids_distraction_intensity_level_sight = json.get('a_ids_distraction_intensity_level_sight', '')
|
|
, names_distraction_intensity_level_sight = json.get('a_names_distraction_intensity_level_sight', '')
|
|
|
|
, get_all_distraction_intensity_level_sound = json.get('a_get_all_distraction_intensity_level_sound', False)
|
|
, get_inactive_distraction_intensity_level_sound = json.get('a_get_inactive_distraction_intensity_level_sound', False)
|
|
, ids_distraction_intensity_level_sound = json.get('a_ids_distraction_intensity_level_sound', '')
|
|
, names_distraction_intensity_level_sound = json.get('a_names_distraction_intensity_level_sound', '')
|
|
|
|
, get_all_distraction_intensity_level_touch = json.get('a_get_all_distraction_intensity_level_touch', False)
|
|
, get_inactive_distraction_intensity_level_touch = json.get('a_get_inactive_distraction_intensity_level_touch', False)
|
|
, ids_distraction_intensity_level_touch = json.get('a_ids_distraction_intensity_level_touch', '')
|
|
, names_distraction_intensity_level_touch = json.get('a_names_distraction_intensity_level_touch', '')
|
|
|
|
, get_all_assessment = json.get('a_get_all_assessment', False)
|
|
, get_inactive_assessment = json.get('a_get_inactive_assessment', False)
|
|
, ids_assessment = json.get('a_ids_assessment', '')
|
|
, notes_assessment = json.get('a_notes_assessment', '')
|
|
, min_temperature_assessment = json.get('a_min_temperature_assessment', None)
|
|
, max_temperature_assessment = json.get('a_max_temperature_assessment', None)
|
|
, get_all_weather = json.get('a_get_all_weather', False)
|
|
, get_inactive_weather = json.get('a_get_inactive_weather', False)
|
|
, ids_weather = json.get('a_ids_weather', '')
|
|
, names_weather = json.get('a_names_weather', '')
|
|
, get_all_lighting_level = json.get('a_get_all_lighting_level', False)
|
|
, get_inactive_lighting_level = json.get('a_get_inactive_lighting_level', False)
|
|
, ids_lighting_level = json.get('a_ids_lighting_level', '')
|
|
, names_lighting_level = json.get('a_names_lighting_level', '')
|
|
, 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', '')
|
|
, get_all_user_handler = json.get('a_get_all_user_handler', False)
|
|
, get_inactive_user_handler = json.get('a_get_inactive_user_handler', False)
|
|
, ids_user_handler = json.get('a_ids_user_handler', '')
|
|
# , auth0_ids_user_handler = json.get('a_ids_user_handler', '')
|
|
, names_user_handler = json.get('a_names_user_handler', '')
|
|
, emails_user_handler = json.get('a_emails_user_handler', '')
|
|
|
|
, 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_distraction(cls, form):
|
|
_m = f'{cls.__qualname__}.from_form_filters_distraction'
|
|
Helper_App.console_log(_m)
|
|
Helper_App.console_log(f'Filters: {form}')
|
|
av.val_instance(form, 'form', _m, Filters_Distraction)
|
|
has_filter_search_text = not (form.search.data == '' or form.search.data is None)
|
|
has_filter_distraction_type = not (form.id_distraction_type.data == '0' or form.id_distraction_type.data == '' or form.id_distraction_type.data is None)
|
|
has_filter_intensity_level_emotional = not (form.id_intensity_level_emotional.data == '0' or form.id_intensity_level_emotional.data == '' or form.id_intensity_level_emotional.data is None)
|
|
has_filter_intensity_level_scent = not (form.id_intensity_level_scent.data == '0' or form.id_intensity_level_scent.data == '' or form.id_intensity_level_scent.data is None)
|
|
has_filter_intensity_level_sight = not (form.id_intensity_level_sight.data == '0' or form.id_intensity_level_sight.data == '' or form.id_intensity_level_sight.data is None)
|
|
has_filter_intensity_level_sound = not (form.id_intensity_level_sound.data == '0' or form.id_intensity_level_sound.data == '' or form.id_intensity_level_sound.data is None)
|
|
has_filter_intensity_level_touch = not (form.id_intensity_level_touch.data == '0' or form.id_intensity_level_touch.data == '' or form.id_intensity_level_touch.data is None)
|
|
|
|
has_filter_assessment = not (form.id_assessment.data == '0' or form.id_assessment.data == '' or form.id_assessment.data is None)
|
|
has_filter_weather = not (form.id_weather.data == '0' or form.id_weather.data == '' or form.id_weather.data is None)
|
|
has_filter_lighting_level = not (form.id_lighting_level.data == '0' or form.id_lighting_level.data == '' or form.id_lighting_level.data is None)
|
|
has_filter_location = not (form.id_location.data == '0' or form.id_location.data == '' or form.id_location.data is None)
|
|
has_filter_user_handler = not (form.id_user_handler.data == '0' or form.id_user_handler.data == '' or form.id_user_handler.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_distraction_type: {has_filter_distraction_type}
|
|
has_filter_intensity_level_emotional: {has_filter_intensity_level_emotional}
|
|
has_filter_intensity_level_scent: {has_filter_intensity_level_scent}
|
|
has_filter_intensity_level_sight: {has_filter_intensity_level_sight}
|
|
has_filter_intensity_level_sound: {has_filter_intensity_level_sound}
|
|
has_filter_intensity_level_touch: {has_filter_intensity_level_touch}
|
|
has_filter_assessment: {has_filter_assessment}
|
|
has_filter_weather: {has_filter_weather}
|
|
has_filter_lighting_level: {has_filter_lighting_level}
|
|
has_filter_location: {has_filter_location}
|
|
has_filter_user_handler: {has_filter_user_handler}
|
|
active_only: {active_only}
|
|
''')
|
|
filters = cls.get_default()
|
|
filters.get_all_distraction = True
|
|
filters.get_inactive_distraction = not active_only
|
|
filters.ids_distraction = ''
|
|
filters.notes_distraction = form.search.data if has_filter_search_text else ''
|
|
|
|
filters.get_all_distraction_type = True
|
|
filters.get_inactive_distraction_type = not active_only
|
|
filters.ids_distraction_type = form.id_distraction_type.data if has_filter_distraction_type else ''
|
|
filters.names_distraction_type = form.search.data if has_filter_search_text else ''
|
|
|
|
filters.get_all_distraction_intensity_level_emotional = True
|
|
filters.get_inactive_distraction_intensity_level_emotional = not active_only
|
|
filters.ids_distraction_intensity_level_emotional = form.id_intensity_level_emotional.data if has_filter_intensity_level_emotional else ''
|
|
filters.names_distraction_intensity_level_emotional = form.search.data if has_filter_search_text else ''
|
|
|
|
filters.get_all_distraction_intensity_level_scent = True
|
|
filters.get_inactive_distraction_intensity_level_scent = not active_only
|
|
filters.ids_distraction_intensity_level_scent = form.id_intensity_level_scent.data if has_filter_intensity_level_scent else ''
|
|
filters.names_distraction_intensity_level_scent = form.search.data if has_filter_search_text else ''
|
|
|
|
filters.get_all_distraction_intensity_level_sight = True
|
|
filters.get_inactive_distraction_intensity_level_sight = not active_only
|
|
filters.ids_distraction_intensity_level_sight = form.id_intensity_level_sight.data if has_filter_intensity_level_sight else ''
|
|
filters.names_distraction_intensity_level_sight = form.search.data if has_filter_search_text else ''
|
|
|
|
filters.get_all_distraction_intensity_level_sound = True
|
|
filters.get_inactive_distraction_intensity_level_sound = not active_only
|
|
filters.ids_distraction_intensity_level_sound = form.id_intensity_level_sound.data if has_filter_intensity_level_sound else ''
|
|
filters.names_distraction_intensity_level_sound = form.search.data if has_filter_search_text else ''
|
|
|
|
filters.get_all_distraction_intensity_level_touch = True
|
|
filters.get_inactive_distraction_intensity_level_touch = not active_only
|
|
filters.ids_distraction_intensity_level_touch = form.id_intensity_level_touch.data if has_filter_intensity_level_touch else ''
|
|
filters.names_distraction_intensity_level_touch = form.search.data if has_filter_search_text else ''
|
|
|
|
filters.get_all_assessment = True
|
|
filters.get_inactive_assessment = not active_only
|
|
filters.ids_assessment = form.id_assessment.data if has_filter_assessment else ''
|
|
filters.get_all_weather = not has_filter_weather
|
|
filters.get_inactive_weather = not active_only
|
|
filters.ids_weather = form.id_weather.data if has_filter_weather else ''
|
|
filters.names_weather = form.search.data if has_filter_search_text else ''
|
|
filters.get_all_lighting_level = not has_filter_lighting_level
|
|
filters.get_inactive_lighting_level = not active_only
|
|
filters.ids_lighting_level = form.id_lighting_level.data if has_filter_lighting_level else ''
|
|
filters.names_lighting_level = 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 ''
|
|
filters.get_all_user_handler = not has_filter_user_handler
|
|
filters.get_inactive_user_handler = not active_only
|
|
filters.ids_user_handler = form.id_user_handler.data if has_filter_user_handler else ''
|
|
# filters.auth0_ids_user_handler = form.id_user_handler.data if has_filter_user_handler else ''
|
|
filters.names_user_handler = form.search.data if has_filter_search_text else ''
|
|
filters.emails_user_handler = form.search.data if has_filter_search_text else ''
|
|
|
|
return filters
|
|
"""
|
|
|
|
@classmethod
|
|
def from_form_filters_assessment(cls, form):
|
|
_m = f'{cls.__qualname__}.from_form_filters_assessment'
|
|
Helper_App.console_log(_m)
|
|
Helper_App.console_log(f'Filters: {form}')
|
|
av.val_instance(form, 'form', _m, Filters_Assessment)
|
|
has_filter_search_text = not (form.search.data == '' or form.search.data is None)
|
|
has_filter_distraction_type = False
|
|
has_filter_intensity_level_emotional = False
|
|
has_filter_intensity_level_scent = False
|
|
has_filter_intensity_level_sight = False
|
|
has_filter_intensity_level_sound = False
|
|
has_filter_intensity_level_touch = False
|
|
|
|
has_filter_assessment = not (form.id_assessment.data == '0' or form.id_assessment.data == '' or form.id_assessment.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_distraction_type: {has_filter_distraction_type}
|
|
has_filter_intensity_level_emotional: {has_filter_intensity_level_emotional}
|
|
has_filter_intensity_level_scent: {has_filter_intensity_level_scent}
|
|
has_filter_intensity_level_sight: {has_filter_intensity_level_sight}
|
|
has_filter_intensity_level_sound: {has_filter_intensity_level_sound}
|
|
has_filter_intensity_level_touch: {has_filter_intensity_level_touch}
|
|
has_filter_assessment: {has_filter_assessment}
|
|
active_only: {active_only}
|
|
''')
|
|
filters = cls.get_default()
|
|
filters.get_all_distraction = True
|
|
filters.get_inactive_distraction = not active_only
|
|
filters.ids_distraction = ''
|
|
filters.notes_distraction = form.search.data if has_filter_search_text else ''
|
|
|
|
filters.get_all_distraction_type = True
|
|
filters.get_inactive_distraction_type = not active_only
|
|
filters.ids_distraction_type = ''
|
|
filters.names_distraction_type = form.search.data if has_filter_search_text else ''
|
|
|
|
filters.get_all_distraction_intensity_level_emotional = True
|
|
filters.get_inactive_distraction_intensity_level_emotional = not active_only
|
|
filters.ids_distraction_intensity_level_emotional = ''
|
|
filters.names_distraction_intensity_level_emotional = form.search.data if has_filter_search_text else ''
|
|
|
|
filters.get_all_distraction_intensity_level_scent = True
|
|
filters.get_inactive_distraction_intensity_level_scent = not active_only
|
|
filters.ids_distraction_intensity_level_scent = ''
|
|
filters.names_distraction_intensity_level_scent = form.search.data if has_filter_search_text else ''
|
|
|
|
filters.get_all_distraction_intensity_level_sight = True
|
|
filters.get_inactive_distraction_intensity_level_sight = not active_only
|
|
filters.ids_distraction_intensity_level_sight = ''
|
|
filters.names_distraction_intensity_level_sight = form.search.data if has_filter_search_text else ''
|
|
|
|
filters.get_all_distraction_intensity_level_sound = True
|
|
filters.get_inactive_distraction_intensity_level_sound = not active_only
|
|
filters.ids_distraction_intensity_level_sound = ''
|
|
filters.names_distraction_intensity_level_sound = form.search.data if has_filter_search_text else ''
|
|
|
|
filters.get_all_distraction_intensity_level_touch = True
|
|
filters.get_inactive_distraction_intensity_level_touch = not active_only
|
|
filters.ids_distraction_intensity_level_touch = ''
|
|
filters.names_distraction_intensity_level_touch = form.search.data if has_filter_search_text else ''
|
|
|
|
filters.get_all_assessment = True
|
|
filters.get_inactive_assessment = not active_only
|
|
filters.ids_assessment = form.id_assessment.data if has_filter_assessment else ''
|
|
|
|
return filters
|
|
|
|
def to_json(self):
|
|
return {
|
|
'a_get_all_distraction': self.get_all_distraction
|
|
, 'a_get_inactive_distraction': self.get_inactive_distraction
|
|
, 'a_ids_distraction': self.ids_distraction
|
|
, 'a_notes_distraction': self.notes_distraction
|
|
, 'a_min_quantity_distraction': self.min_quantity_distraction
|
|
, 'a_max_quantity_distraction': self.max_quantity_distraction
|
|
, 'a_min_proximity_metres_distraction': self.min_proximity_metres_distraction
|
|
, 'a_max_proximity_metres_distraction': self.max_proximity_metres_distraction
|
|
|
|
, 'a_get_all_distraction_type': self.get_all_distraction_type
|
|
, 'a_get_inactive_distraction_type': self.get_inactive_distraction_type
|
|
, 'a_ids_distraction_type': self.ids_distraction_type
|
|
, 'a_names_distraction_type': self.names_distraction_type
|
|
|
|
, 'a_get_all_distraction_intensity_level_emotional': self.get_all_distraction_intensity_level_emotional
|
|
, 'a_get_inactive_distraction_intensity_level_emotional': self.get_inactive_distraction_intensity_level_emotional
|
|
, 'a_ids_distraction_intensity_level_emotional': self.ids_distraction_intensity_level_emotional
|
|
, 'a_names_distraction_intensity_level_emotional': self.names_distraction_intensity_level_emotional
|
|
|
|
, 'a_get_all_distraction_intensity_level_scent': self.get_all_distraction_intensity_level_scent
|
|
, 'a_get_inactive_distraction_intensity_level_scent': self.get_inactive_distraction_intensity_level_scent
|
|
, 'a_ids_distraction_intensity_level_scent': self.ids_distraction_intensity_level_scent
|
|
, 'a_names_distraction_intensity_level_scent': self.names_distraction_intensity_level_scent
|
|
|
|
, 'a_get_all_distraction_intensity_level_sight': self.get_all_distraction_intensity_level_sight
|
|
, 'a_get_inactive_distraction_intensity_level_sight': self.get_inactive_distraction_intensity_level_sight
|
|
, 'a_ids_distraction_intensity_level_sight': self.ids_distraction_intensity_level_sight
|
|
, 'a_names_distraction_intensity_level_sight': self.names_distraction_intensity_level_sight
|
|
|
|
, 'a_get_all_distraction_intensity_level_sound': self.get_all_distraction_intensity_level_sound
|
|
, 'a_get_inactive_distraction_intensity_level_sound': self.get_inactive_distraction_intensity_level_sound
|
|
, 'a_ids_distraction_intensity_level_sound': self.ids_distraction_intensity_level_sound
|
|
, 'a_names_distraction_intensity_level_sound': self.names_distraction_intensity_level_sound
|
|
|
|
, 'a_get_all_distraction_intensity_level_touch': self.get_all_distraction_intensity_level_touch
|
|
, 'a_get_inactive_distraction_intensity_level_touch': self.get_inactive_distraction_intensity_level_touch
|
|
, 'a_ids_distraction_intensity_level_touch': self.ids_distraction_intensity_level_touch
|
|
, 'a_names_distraction_intensity_level_touch': self.names_distraction_intensity_level_touch
|
|
|
|
, 'a_get_all_assessment': self.get_all_assessment
|
|
, 'a_get_inactive_assessment': self.get_inactive_assessment
|
|
, 'a_ids_assessment': self.ids_assessment
|
|
, 'a_notes_assessment': self.notes_assessment
|
|
, 'a_min_temperature_assessment': self.min_temperature_assessment
|
|
, 'a_max_temperature_assessment': self.max_temperature_assessment
|
|
, 'get_all_weather': self.get_all_weather
|
|
, 'get_inactive_weather': self.get_inactive_weather
|
|
, 'ids_weather': self.ids_weather
|
|
, 'names_weather': self.names_weather
|
|
, 'get_all_lighting_level': self.get_all_lighting_level
|
|
, 'get_inactive_lighting_level': self.get_inactive_lighting_level
|
|
, 'ids_lighting_level': self.ids_lighting_level
|
|
, 'names_lighting_level': self.names_lighting_level
|
|
, 'get_all_location': self.get_all_location
|
|
, 'get_inactive_location': self.get_inactive_location
|
|
, 'ids_location': self.ids_location
|
|
, 'names_location': self.names_location
|
|
, 'get_all_user_handler': self.get_all_user_handler
|
|
, 'get_inactive_user_handler': self.get_inactive_user_handler
|
|
, 'ids_user_handler': self.ids_user_handler
|
|
#, 'auth0_ids_user_handler': self.ids_user_handler
|
|
, 'names_user_handler': self.names_user_handler
|
|
, 'emails_user_handler': self.emails_user_handler
|
|
|
|
, '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
|
|
}
|