162 lines
5.5 KiB
Python
162 lines
5.5 KiB
Python
import datetime, pytz
|
|
|
|
from typing import Dict, List, Optional, Set, Union
|
|
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
|
|
|
from app.db_sql import redis_lookup_id_random
|
|
from app.lib_general import log, logging
|
|
|
|
from app.models.common_field_schema import base_fields, default_num_bytes
|
|
from app.models.event_cfg_models import Event_Cfg_Base
|
|
from app.models.event_location_models import Event_Location_Base
|
|
|
|
|
|
# ### BEGIN ### API Event Device Models ### Event_Device_Base() ###
|
|
class Event_Device_Base(BaseModel):
|
|
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(locals())
|
|
|
|
id_random: Optional[str] = Field(
|
|
**base_fields['event_device_id_random'],
|
|
alias = 'event_device_id_random',
|
|
)
|
|
id: Optional[int] = Field(
|
|
alias = 'event_device_id'
|
|
)
|
|
|
|
account_id_random: Optional[str]
|
|
account_id: Optional[int]
|
|
|
|
event_id_random: Optional[str]
|
|
event_id: Optional[int]
|
|
|
|
event_location_id_random: Optional[str]
|
|
event_location_id: Optional[int]
|
|
|
|
code: Optional[str]
|
|
|
|
name: Optional[str]
|
|
description: Optional[str]
|
|
|
|
app_mode: Optional[str] # null, default, onsite, app
|
|
use_local_api: Optional[bool]
|
|
use_local_app: Optional[bool]
|
|
|
|
api_secret_key: Optional[str]
|
|
|
|
api_base_url: Optional[str]
|
|
app_server_base_url: Optional[str]
|
|
file_server_base_url: Optional[str]
|
|
|
|
api_base_url_bak: Optional[str] # Backup URL
|
|
app_server_base_url_bak: Optional[str] # Backup URL
|
|
file_server_base_url_bak: Optional[str] # Backup URL
|
|
|
|
trigger_open_filename: Optional[str] # The file hash filename
|
|
trigger_open_extension: Optional[str] # The file hash extension part
|
|
trigger_open_open_in_os: Optional[str] # Use open_in_os for win vs mac
|
|
|
|
trigger_open_file_id: Optional[str] # The file ID random; use along with filename, extension, and open_in_os
|
|
trigger_open_hash_file: Optional[str] # The file hash; use along with filename, extension, and open_in_os
|
|
trigger_open_file_path: Optional[str] # Use along with filename
|
|
|
|
trigger_open_session_id: Optional[str]
|
|
trigger_open_session_id: Optional[str]
|
|
|
|
trigger_recording_start: Optional[bool]
|
|
trigger_recording_stop: Optional[bool]
|
|
|
|
trigger_reset: Optional[bool]
|
|
|
|
trigger_show_admin: Optional[str]
|
|
trigger_show_hidden: Optional[str]
|
|
|
|
local_file_cache_path: Optional[str] # Path for hash file cache only
|
|
host_file_temp_path: Optional[str] # Path for copied and renamed temporary files from hash file cache directory
|
|
recording_path: Optional[str] # Path to save recordings
|
|
|
|
record_audio: Optional[bool] # Record
|
|
record_video: Optional[bool] # Record
|
|
|
|
check_event_loop_period: Optional[int]
|
|
check_event_device_loop_period: Optional[int]
|
|
check_event_location_loop_period: Optional[int]
|
|
check_event_session_loop_period: Optional[int]
|
|
|
|
alert: Optional[bool]
|
|
alert_msg: Optional[str]
|
|
|
|
info_hostname: Optional[str]
|
|
info_ip: Optional[str]
|
|
info_ip_list: Optional[str] # string list of IPs separated by ;
|
|
info_os: Optional[str]
|
|
|
|
enable: Optional[bool]
|
|
|
|
# hide: Optional[bool]
|
|
# priority: Optional[bool]
|
|
# sort: Optional[int]
|
|
# group: Optional[str]
|
|
|
|
event_notes: Optional[str]
|
|
notes: Optional[str]
|
|
|
|
created_on: Optional[datetime.datetime] = None
|
|
updated_on: Optional[datetime.datetime] = None
|
|
|
|
# Including convenience data
|
|
# This is only for convenience. Probably going to keep unless it causes a problem.
|
|
|
|
# Including JSON data
|
|
other_json: Optional[Union[str,Json]]
|
|
meta_json: Optional[Union[str,Json]]
|
|
|
|
# Including other related objects
|
|
event_cfg: Optional[Event_Cfg_Base]
|
|
event_location: Optional[Event_Location_Base]
|
|
|
|
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
|
|
|
#@validator('event_device_id_random', always=True)
|
|
# def event_device_id_random_copy(cls, v, values, **kwargs):
|
|
# log.setLevel(logging.WARNING)
|
|
# log.debug(locals())
|
|
|
|
# if values['id_random']:
|
|
# return values['id_random']
|
|
# return None
|
|
|
|
@validator('id', always=True)
|
|
def event_device_id_lookup(cls, v, values, **kwargs):
|
|
if isinstance(v, int) and v > 0: return v
|
|
elif id_random := values.get('id_random'):
|
|
return redis_lookup_id_random(record_id_random=id_random, table_name='event_device')
|
|
return None
|
|
|
|
@validator('account_id', always=True)
|
|
def account_id_lookup(cls, v, values, **kwargs):
|
|
if isinstance(v, int) and v > 0: return v
|
|
elif id_random := values.get('account_id_random'):
|
|
return redis_lookup_id_random(record_id_random=id_random, table_name='account')
|
|
return None
|
|
|
|
@validator('event_id', always=True)
|
|
def event_id_lookup(cls, v, values, **kwargs):
|
|
if isinstance(v, int) and v > 0: return v
|
|
elif id_random := values.get('event_id_random'):
|
|
return redis_lookup_id_random(record_id_random=id_random, table_name='event')
|
|
return None
|
|
|
|
@validator('event_location_id', always=True)
|
|
def event_location_id_lookup(cls, v, values, **kwargs):
|
|
if isinstance(v, int) and v > 0: return v
|
|
elif id_random := values.get('event_location_id_random'):
|
|
return redis_lookup_id_random(record_id_random=id_random, table_name='event_location')
|
|
return None
|
|
|
|
class Config:
|
|
underscore_attrs_are_private = True
|
|
allow_population_by_field_name = True
|
|
fields = base_fields
|
|
# ### END ### API Event Device Models ### Event_Device_Base() ###
|