344 lines
13 KiB
Python
344 lines
13 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.core_object_models import Core_Std_Obj_Base
|
|
# from app.models.event_models import Event_Base
|
|
from app.models.event_cfg_models import Event_Cfg_Base
|
|
# from app.models.event_person_models import Event_Person_Base
|
|
# from app.models.event_presentation_models import Event_Presentation_Base
|
|
#from app.models.event_presenter_models import Event_Presenter_Base # This creates an import loop
|
|
# from app.models.event_session_models import Event_Session_Base
|
|
|
|
|
|
# ### BEGIN ### API Event Abstract Models ### Event_Abstract_Base() ###
|
|
# Update 2023-03-20
|
|
class Event_Abstract_Base(BaseModel):
|
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(locals())
|
|
|
|
id_random: Optional[str] = Field(
|
|
# **base_fields['event_abstract_id_random'],
|
|
alias = 'event_abstract_id_random',
|
|
)
|
|
id: Optional[int] = Field(
|
|
alias = 'event_abstract_id'
|
|
)
|
|
|
|
event_id_random: Optional[str]
|
|
event_id: Optional[int]
|
|
|
|
event_person_id_random: Optional[str] # This is the primary person/submitter
|
|
event_person_id: Optional[int]
|
|
|
|
event_presentation_id_random: Optional[str]
|
|
event_presentation_id: Optional[int]
|
|
|
|
event_presenter_id_random: Optional[str]
|
|
event_presenter_id: Optional[int]
|
|
|
|
event_session_id_random: Optional[str]
|
|
event_session_id: Optional[int]
|
|
|
|
# event_track_id_random: Optional[str]
|
|
# event_track_id: Optional[int]
|
|
|
|
# poc_event_person_id_random: Optional[str] # Maybe change this to primary_event_person?
|
|
# poc_event_person_id: Optional[int] # Maybe change this to primary_event_person?
|
|
|
|
external_id: Optional[str]
|
|
code: Optional[str]
|
|
|
|
grant_id_random: Optional[str]
|
|
grant_id: Optional[int]
|
|
|
|
grant_code: Optional[str]
|
|
# grant_type_code: Optional[str]
|
|
# grant_json: Optional[Union[Json, None]]
|
|
|
|
name: Optional[str]
|
|
description: Optional[str]
|
|
abstract: Optional[str]
|
|
|
|
passcode: Optional[str] # = '7777777'
|
|
|
|
data_json: Optional[Json]
|
|
|
|
enable: Optional[bool]
|
|
hide: Optional[bool]
|
|
priority: Optional[bool]
|
|
sort: Optional[int]
|
|
group: 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.
|
|
event_session_code: Optional[str]
|
|
event_session_name: Optional[str]
|
|
|
|
# Including other related objects
|
|
# event: Optional[Event_Base]
|
|
event_file_list: Optional[list] # Optional[Event_File_Base]
|
|
# event_person: Optional[Event_Person_Base]
|
|
event_person: Optional[dict]
|
|
# event_presentation: Optional[Event_Presentation_Base]
|
|
#event_presenter: Optional[Event_Presenter_Base] # This creates an import loop
|
|
event_presenter_list: Optional[list] # Optional[Event_Presenter_Base]
|
|
# event_session: Optional[Event_Session_Base]
|
|
# event_track: Optional[Event_Track_Base]
|
|
# poc_event_person: Optional[Event_Person_Base] # Maybe change this to primary_event_person?
|
|
# poc_person: Optional[Person_Base] # Maybe change this to primary_person?
|
|
|
|
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
|
|
|
@validator('id', always=True)
|
|
def event_abstract_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_abstract')
|
|
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_person_id', always=True)
|
|
def event_person_id_lookup(cls, v, values, **kwargs):
|
|
if isinstance(v, int) and v > 0: return v
|
|
elif id_random := values.get('event_person_id_random'):
|
|
return redis_lookup_id_random(record_id_random=id_random, table_name='event_person')
|
|
return None
|
|
|
|
@validator('event_presentation_id', always=True)
|
|
def event_presentation_id_lookup(cls, v, values, **kwargs):
|
|
if isinstance(v, int) and v > 0: return v
|
|
elif id_random := values.get('event_presentation_id_random'):
|
|
return redis_lookup_id_random(record_id_random=id_random, table_name='event_presentation')
|
|
return None
|
|
|
|
@validator('event_presenter_id', always=True)
|
|
def event_presenter_id_lookup(cls, v, values, **kwargs):
|
|
if isinstance(v, int) and v > 0: return v
|
|
elif id_random := values.get('event_presenter_id_random'):
|
|
return redis_lookup_id_random(record_id_random=id_random, table_name='event_presenter')
|
|
return None
|
|
|
|
@validator('event_session_id', always=True)
|
|
def event_session_id_lookup(cls, v, values, **kwargs):
|
|
if isinstance(v, int) and v > 0: return v
|
|
elif id_random := values.get('event_session_id_random'):
|
|
return redis_lookup_id_random(record_id_random=id_random, table_name='event_session')
|
|
return None
|
|
|
|
@validator('grant_id', always=True)
|
|
def grant_id_lookup(cls, v, values, **kwargs):
|
|
if isinstance(v, int) and v > 0: return v
|
|
elif id_random := values.get('grant_id_random'):
|
|
return redis_lookup_id_random(record_id_random=id_random, table_name='grant')
|
|
return None
|
|
|
|
# @validator('poc_event_person_id', always=True)
|
|
# def poc_event_person_id_lookup(cls, v, values, **kwargs):
|
|
# log.setLevel(logging.WARNING)
|
|
# log.debug(locals())
|
|
|
|
# if values['poc_event_person_id_random']:
|
|
# return redis_lookup_id_random(record_id_random=values['poc_event_person_id_random'], table_name='poc_event_person')
|
|
# return None
|
|
|
|
class Config:
|
|
underscore_attrs_are_private = True
|
|
allow_population_by_field_name = True
|
|
fields = base_fields
|
|
# ### END ### API Event Abstract Models ### Event_Abstract_Base() ###
|
|
|
|
|
|
|
|
|
|
|
|
# ### BEGIN ### API Event Abstract Models ### Event_Abstract_Base() ###
|
|
# Update 2023-03-22
|
|
class Event_Abstract_Base_New(Core_Std_Obj_Base):
|
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(locals())
|
|
|
|
id_random: Optional[str] = Field(
|
|
alias = 'event_abstract_id_random',
|
|
)
|
|
|
|
event_id_random: Optional[str]
|
|
event_id: Optional[int]
|
|
|
|
event_person_id: Optional[int]
|
|
|
|
event_session_id: Optional[int]
|
|
|
|
event_person_id_random: Optional[str]
|
|
|
|
event_presentation_id_random: Optional[str]
|
|
|
|
event_presenter_id_random: Optional[str]
|
|
|
|
event_session_id_random: Optional[str]
|
|
|
|
# event_track_id_random: Optional[str]
|
|
|
|
# poc_event_person_id_random: Optional[str] # Maybe change this to primary_event_person?
|
|
|
|
code: Optional[str]
|
|
|
|
external_id: Optional[str]
|
|
|
|
# type_code: Optional[str]
|
|
|
|
description: Optional[str]
|
|
abstract: Optional[str] # Actual abstract text
|
|
|
|
passcode: Optional[str]
|
|
|
|
grant_id_random: Optional[str]
|
|
grant_id: Optional[int]
|
|
|
|
grant_code: Optional[str]
|
|
grant_type_code: Optional[str]
|
|
grant_json: Optional[Union[Json, None]]
|
|
|
|
category_code: Optional[str]
|
|
# category2_code: Optional[str]
|
|
|
|
topics_json: Optional[Union[Json, None]]
|
|
|
|
submitter_json: Optional[Union[Json, None]]
|
|
coauthors_json: Optional[Union[Json, None]]
|
|
|
|
@validator('event_person_id', always=True)
|
|
def event_person_id_lookup(cls, v, values, **kwargs):
|
|
if isinstance(v, int) and v > 0: return v
|
|
elif id_random := values.get('event_person_id_random'):
|
|
return redis_lookup_id_random(record_id_random=id_random, table_name='event_person')
|
|
return None
|
|
|
|
# @validator('event_session_id', always=True)
|
|
# def event_session_id_lookup(cls, v, values, **kwargs):
|
|
# if isinstance(v, int) and v > 0: return v
|
|
# elif id_random := values.get('event_session_id_random'):
|
|
# return redis_lookup_id_random(record_id_random=id_random, table_name='event_session')
|
|
# return None
|
|
|
|
class Config:
|
|
underscore_attrs_are_private = True
|
|
allow_population_by_field_name = True
|
|
fields = base_fields
|
|
# ### END ### API Event Abstract Models ### Event_Abstract_Base() ###
|
|
|
|
|
|
# ### BEGIN ### API Event Abstract Models ### Event_Abstract_In() ###
|
|
# Update 2023-03-22
|
|
class Event_Abstract_In(Event_Abstract_Base_New):
|
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(locals())
|
|
|
|
id: Optional[int] = Field(
|
|
alias = 'event_abstract_id'
|
|
)
|
|
|
|
event_id: Optional[int]
|
|
|
|
event_person_id: Optional[int]
|
|
|
|
# event_session_id: Optional[int]
|
|
|
|
# grant_json: Optional[Union[str, None]]
|
|
|
|
|
|
@validator('id', always=True)
|
|
def event_abstract_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_abstract')
|
|
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_person_id', always=True)
|
|
def event_person_id_lookup(cls, v, values, **kwargs):
|
|
if isinstance(v, int) and v > 0: return v
|
|
elif id_random := values.get('event_person_id_random'):
|
|
return redis_lookup_id_random(record_id_random=id_random, table_name='event_person')
|
|
return None
|
|
|
|
# @validator('event_presentation_id', always=True)
|
|
# def event_presentation_id_lookup(cls, v, values, **kwargs):
|
|
# if isinstance(v, int) and v > 0: return v
|
|
# elif id_random := values.get('event_presentation_id_random'):
|
|
# return redis_lookup_id_random(record_id_random=id_random, table_name='event_presentation')
|
|
# return None
|
|
|
|
# @validator('event_presenter_id', always=True)
|
|
# def event_presenter_id_lookup(cls, v, values, **kwargs):
|
|
# if isinstance(v, int) and v > 0: return v
|
|
# elif id_random := values.get('event_presenter_id_random'):
|
|
# return redis_lookup_id_random(record_id_random=id_random, table_name='event_presenter')
|
|
# return None
|
|
|
|
# @validator('event_session_id', always=True)
|
|
# def event_session_id_lookup(cls, v, values, **kwargs):
|
|
# if isinstance(v, int) and v > 0: return v
|
|
# elif id_random := values.get('event_session_id_random'):
|
|
# return redis_lookup_id_random(record_id_random=id_random, table_name='event_session')
|
|
# return None
|
|
|
|
@validator('grant_id', always=True)
|
|
def grant_id_lookup(cls, v, values, **kwargs):
|
|
if isinstance(v, int) and v > 0: return v
|
|
elif id_random := values.get('grant_id_random'):
|
|
return redis_lookup_id_random(record_id_random=id_random, table_name='grant')
|
|
return None
|
|
# ### END ### API Event Abstract Models ### Event_Abstract_In() ###
|
|
|
|
|
|
# ### BEGIN ### API Event Abstract Models ### Event_Abstract_Ext() ###
|
|
# Update 2023-09-22
|
|
class Event_Abstract_Ext(Event_Abstract_Base_New):
|
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(locals())
|
|
|
|
# Including convenience data
|
|
# This is only for convenience. Probably going to keep unless it causes a problem.
|
|
event_session_code: Optional[str]
|
|
event_session_name: Optional[str]
|
|
|
|
# Including other related objects
|
|
# event: Optional[Event_Base]
|
|
event_cfg: Optional[Event_Cfg_Base]
|
|
event_file_list: Optional[list] # Optional[Event_File_Base]
|
|
# from app.models.event_person_models import Event_Person_Base
|
|
# event_person: Optional[Event_Person_Base]
|
|
event_person: Optional[dict]
|
|
# event_presentation: Optional[Event_Presentation_Base]
|
|
#event_presenter: Optional[Event_Presenter_Base] # This creates an import loop
|
|
# event_presenter_list: Optional[list] # Optional[Event_Presenter_Base]
|
|
# event_session: Optional[Event_Session_Base]
|
|
# event_track: Optional[Event_Track_Base]
|
|
# poc_event_person: Optional[Event_Person_Base] # Maybe change this to primary_event_person?
|
|
# poc_person: Optional[Person_Base] # Maybe change this to primary_person?
|
|
# ### END ### API Event Abstract Models ### Event_Abstract_Ext() ###
|