Work on session proposals and related event person profile.

This commit is contained in:
Scott Idem
2021-09-07 18:49:21 -04:00
parent edd7beb4d7
commit 84aecddc7c
6 changed files with 458 additions and 3 deletions

View File

@@ -11,6 +11,7 @@ from app.lib_general import log, logging
from app.methods.event_badge_methods import load_event_badge_obj
# from app.methods.event_exhibit_methods import load_event_exhibit_obj
# from app.methods.event_file_methods import load_event_file_obj
from app.methods.event_person_profile_methods import load_event_person_profile_obj
# from app.methods.event_presentation_methods import load_event_presentation_obj
# from app.methods.event_presenter_methods import load_event_presenter_obj
# from app.methods.event_registration_methods import create_event_registration_obj, load_event_registration_obj, update_event_registration_obj_v3
@@ -37,6 +38,7 @@ def load_event_person_obj(
inc_event_exhibit_list: bool = False,
inc_event_file_list: bool = False,
#inc_event_person_detail: bool = False, # Should this be done differently?
inc_event_person_profile: bool = False,
inc_event_presentation_list: bool = False,
inc_event_presenter_list: bool = False,
inc_event_registration: bool = False,
@@ -65,6 +67,7 @@ def load_event_person_obj(
log.error(e.json())
return False
event_person_profile_id = event_person_rec.get('event_person_profile_id', None)
person_id = event_person_rec.get('person_id', None)
user_id = event_person_rec.get('user_id', None)
@@ -90,7 +93,20 @@ def load_event_person_obj(
if inc_event_exhibit_list: pass
if inc_event_file_list: pass
#if inc_event_person_detail: pass
# Updated 2021-09-07
if inc_event_person_profile:
log.info('Need to include event person profile data...')
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
if event_person_profile_obj := load_event_person_profile_obj(
event_person_profile_id = event_person_profile_id
):
log.debug(event_person_profile_obj)
event_person_obj.event_person_profile = event_person_profile_obj.dict(by_alias=True, exclude_unset=True)
else:
log.warning('A event_person_profile object was not returned.')
event_person_obj.event_person_profile = None
if inc_event_presentation_list: pass
if inc_event_presenter_list: pass
if inc_event_registration: pass

View File

@@ -0,0 +1,223 @@
from __future__ import annotations
import datetime
from typing import Dict, List, Optional, Set, Union
from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, validator
from app.db_sql import get_account_id_w_for_type_id, redis_lookup_id_random, sql_insert, sql_select, sql_update
from app.lib_general import log, logging
from app.methods.address_methods import create_address_obj, create_update_address_obj, create_update_address_obj_v4, update_address_obj
from app.models.common_field_schema import default_num_bytes
from app.models.event_person_profile_models import Event_Person_Profile_Base
# ### BEGIN ### API Event Person Profile Methods ### load_event_person_profile_obj() ###
def load_event_person_profile_obj(
event_person_profile_id: int|str,
limit: int = 1000,
by_alias: bool = True,
exclude_unset: bool = True,
model_as_dict: bool = False,
enabled: str = 'enabled', # enabled, disabled, all
inc_address: bool = False,
inc_contact: bool = False,
) -> Event_Person_Profile_Base|dict|bool:
# log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
if event_person_profile_id := redis_lookup_id_random(record_id_random=event_person_profile_id, table_name='event_person_profile'): pass
else: return False
if event_person_profile_rec := sql_select(table_name='v_event_person_profile', record_id=event_person_profile_id): pass
else: return False
try:
event_person_profile_obj = Event_Person_Profile_Base(**event_person_profile_rec)
log.debug(event_person_profile_obj)
except ValidationError as e:
log.error(e.json())
return False
if inc_contact:
log.info('Need to include contact data...')
contact_id = event_person_profile_rec.get('contact_id', None)
log.debug(contact_id)
from app.methods.contact_methods import load_contact_obj
if contact_result := load_contact_obj(
contact_id = contact_id,
by_alias = by_alias,
exclude_unset = exclude_unset,
model_as_dict = model_as_dict,
):
event_person_profile_obj.contact = contact_result
else: event_person_profile_obj.contact = None
if model_as_dict:
return event_person_profile_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset) # pylint: disable=no-member
else:
return event_person_profile_obj
# ### END ### API Event Person Profile Methods ### load_event_person_profile_obj() ###
# ### BEGIN ### API Event Person Profile Methods ### get_event_person_id_w_event_person_profile_id() ###
# Updated 2021-09-07
def get_event_person_id_w_event_person_profile_id(
event_person_profile_id: int|str,
) -> bool|int|None:
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
if event_person_profile_id := redis_lookup_id_random(record_id_random=event_person_profile_id, table_name='event_person_profile'): pass
else: return False
data = {}
data['event_person_profile_id'] = event_person_profile_id
sql = f"""
SELECT `event_person_profile`.id AS 'event_person_profile_id', `event_person_profile`.id_random AS 'event_person_profile_id_random', `event_person_profile`.account_id AS account_id
FROM `event_person_profile` AS `event_person_profile`
WHERE `event_person_profile`.id = :event_person_profile_id
LIMIT 1;
"""
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
if event_person_profile_data_result := sql_select(data=data, sql=sql):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(event_person_profile_data_result)
if account_id := event_person_profile_data_result.get('account_id', None): return account_id
else: return False
else: return None
# ### END ### API Event Person Profile Methods ### get_event_person_id_w_event_person_profile_id() ###
# ### BEGIN ### API Event Person Profile Methods ### create_update_event_person_profile_obj_v4() ###
# NOTE: This will create or update a event_person_profile.
# Rewrite and updated 2021-09-07
def create_update_event_person_profile_obj_v4(
event_person_profile_dict_obj: Event_Person_Profile|dict,
event_person_profile_id: int|str = None,
account_id: int|str = None,
event_id: int|str = None,
event_person_id: int|str = None,
create_sub_obj: bool = False,
fail_any: bool = False, # Fail if any thing goes wrong for sub objects
return_outline: bool = False,
) -> int|bool:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
log.info('Checking requirements...')
if account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'): pass
else:
log.error('Missing or invalid Account ID passed. Not required. Ignoring for now.')
log.info(f'Account ID: {account_id}')
if event_person_profile_id:
log.info(f'Event Person Profile ID passed. Update existing Event Person Profile. Event Person Profile ID: {event_person_profile_id}')
if event_person_profile_id := redis_lookup_id_random(record_id_random=event_person_profile_id, table_name='event_person_profile'): pass
else:
log.error('Event Person Profile ID passed but is invalid. Failed requirement.')
return False
else:
log.info('No Event Person Profile ID passed. Create new Event Person Profile. Required: Event Person ID')
if event_person_id := redis_lookup_id_random(record_id_random=event_person_id, table_name='event_person'): pass
else:
log.error('Missing or invalid Event Person ID passed. Failed requirement.')
log.info(f'Event Person ID: {event_person_id}')
return False
log.debug(type(event_person_profile_dict_obj))
if isinstance(event_person_profile_dict_obj, dict):
event_person_profile_dict = event_person_profile_dict_obj
if event_person_profile_id:
event_person_profile_dict['event_person_profile_id'] = event_person_profile_id
try:
event_person_profile_obj = Event_Person_Profile(**event_person_profile_dict)
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(event_person_profile_obj)
except ValidationError as e:
log.error(e.json())
return False
else:
event_person_profile_obj = event_person_profile_dict_obj
if event_person_profile_id:
# NOTE: Can't update the ID alias if it was never set.
event_person_profile_obj.id = event_person_profile_id
event_person_profile_dict = event_person_profile_obj.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'account_id', 'account_id_random', 'contact', 'event_cfg', 'event_id', 'event_id_random', 'organization', 'created_on', 'updated_on'})
if event_person_profile_id:
if event_person_profile_dict_up_result := sql_update(data=event_person_profile_dict, table_name='event_person_profile', rm_id_random=True): pass
else:
log.warning(f'Event Person Profile not updated. Event Person Profile ID: {event_person_profile_id}')
log.debug(event_person_profile_dict_up_result)
return False
log.debug(event_person_profile_dict_up_result)
else:
if event_person_profile_dict_in_result := sql_insert(data=event_person_profile_dict, table_name='event_person_profile', rm_id_random=True, id_random_length=8): pass
else:
log.warning(f'Event Person Profile not created.')
log.debug(event_person_profile_dict_in_result)
return False
log.debug(event_person_profile_dict_in_result)
event_person_profile_id = event_person_profile_dict_in_result
# NOTE: This is really only needed if a new contact is being created
if not account_id:
log.info('Attempting to get Account ID from related object.')
if account_id := event_person_profile_obj.account_id: pass
elif account_id := event_person_profile_obj.account_id_random: pass
elif event_person_id: pass
elif event_person_id := event_person_profile_obj.event_person_id: pass
elif event_person_id := event_person_profile_obj.event_person_id_random: pass
if event_person_id:
if account_id := get_account_id_w_for_type_id(for_type='event_person', for_id=event_person_id): pass
else:
log.error('Unable to get Account ID from related object.')
False
event_person_profile_outline = {}
event_person_profile_outline['event_person_profile_id'] = event_person_profile_id
# NOTE: Use object model version because of better type checking and validations
if event_person_profile_obj.contact:
event_person_profile_outline['contact_id'] = None
contact_obj = event_person_profile_obj.contact
if contact_id := event_person_profile_obj.contact_id: pass
elif contact_id := contact_obj.id: pass
else: contact_id = None
contact_obj.id
contact_obj.for_type = 'event_person_profile'
contact_obj.for_id = event_person_profile_id
create_update_contact_obj_result = create_update_contact_obj_v4(
contact_dict_obj = contact_obj,
contact_id = contact_id,
account_id = account_id,
for_type = 'event_person_profile',
for_id = event_person_profile_id,
fail_any = fail_any,
return_outline = return_outline,
)
if isinstance(create_update_contact_obj_result, int):
contact_id = create_update_contact_obj_result
elif create_update_contact_obj_result == True: pass
else:
log.warning(f'Create or Update failed while trying create_update_contact_obj_v4(): {create_update_contact_obj_result}')
contact_id = None
event_person_profile_outline['contact_id'] = contact_id
if return_outline:
log.debug(f'Returning the Event Person Profile Outline: {event_person_profile_outline}')
return event_person_profile_outline
else:
log.debug(f'Returning the Event Person Profile ID: {event_person_profile_id}')
return event_person_profile_id
# ### END ### API Event Person Profile Methods ### create_update_event_person_profile_obj_v4() ###

View File

@@ -40,6 +40,7 @@ base_fields['event_device_id_random'] = xxx_id_random_field_schema
base_fields['event_location_id_random'] = xxx_id_random_field_schema
base_fields['event_person_id_random'] = xxx_id_random_field_schema
base_fields['event_person_detail_id_random'] = xxx_id_random_field_schema
base_fields['event_person_profile_id_random'] = xxx_id_random_field_schema
base_fields['event_presentation_id_random'] = xxx_id_random_field_schema
base_fields['event_presenter_id_random'] = xxx_id_random_field_schema
base_fields['event_registration_id_random'] = xxx_id_random_field_schema

View File

@@ -10,7 +10,7 @@ from app.lib_general import log, logging
from app.models.common_field_schema import base_fields, default_num_bytes
# from app.models.event_models import Event_Base # Causes an import loop
from app.models.event_badge_models import Event_Badge_Base
# from app.models.event_person_detail_models import Event_Person_Detail_Base
from app.models.event_person_profile_models import Event_Person_Profile_Base
from app.models.event_registration_models import Event_Registration_Base
from app.models.person_models import Person_Base
from app.models.user_models import User_Base, User_Out_Base
@@ -43,6 +43,9 @@ class Event_Person_Base(BaseModel):
event_badge_vip_id_random: Optional[str] # Additional VIP badge
event_badge_vip_id: Optional[int]
event_person_profile_id_random: Optional[str]
event_person_profile_id: Optional[int]
event_registration_id_random: Optional[str]
event_registration_id: Optional[int]
@@ -70,6 +73,7 @@ class Event_Person_Base(BaseModel):
event_file_list: Optional[list] # Use event_person_detail table. An event_person record can be linked to one or more files
event_location_list: Optional[list] # Use event_person_detail table. An event_person record can be linked to one or more locations (but unlikely?)
#event_person_detail_list: Optional[list] # list of Event_Person_Detail
event_person_profile: Optional[Event_Person_Profile_Base]
event_presentation_list: Optional[list] # Use event_person_detail table. An event_person record can be linked to one or more presentations
event_presenter_list: Optional[list] # Use event_person_detail table. An event_person record can be linked to one or more presenters (part of multiple presentations)
event_registration: Optional[Event_Registration_Base]
@@ -144,6 +148,15 @@ class Event_Person_Base(BaseModel):
return redis_lookup_id_random(record_id_random=values['event_badge_vip_id_random'], table_name='event_badge')
return None
@validator('event_person_profile_id', always=True)
def event_person_profile_id_lookup(cls, v, values, **kwargs):
log.setLevel(logging.WARNING)
log.debug(locals())
if values['event_person_profile_id_random']:
return redis_lookup_id_random(record_id_random=values['event_person_profile_id_random'], table_name='event_person_profile')
return None
@validator('event_registration_id', always=True)
def event_registration_id_lookup(cls, v, values, **kwargs):
log.setLevel(logging.WARNING)

View File

@@ -0,0 +1,193 @@
from __future__ import annotations
import datetime, hashlib, logging, os, pytz, redis, secrets
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.contact_models import Contact_Base
from app.models.event_cfg_models import Event_Cfg_Base
from app.models.organization_models import Organization_Base
class Event_Person_Profile_Base(BaseModel):
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
id_random: Optional[str] = Field(
**base_fields['event_person_profile_id_random'],
alias = 'event_person_profile_id_random',
default_factory = lambda:secrets.token_urlsafe(default_num_bytes),
)
id: Optional[int] = Field(
alias = 'event_person_profile_id'
)
account_id_random: Optional[str]
account_id: Optional[int]
contact_id_random: Optional[str]
contact_id: Optional[int]
event_id_random: Optional[str] # Only in view
event_id: Optional[int] # Only in view
event_person_id_random: Optional[str] # Only in view
event_person_id: Optional[int] # Only in view
organization_id_random: Optional[str]
organization_id: Optional[int]
pronoun: Optional[str]
informal_name: Optional[str]
given_name: Optional[str]
family_name: Optional[str]
full_name: Optional[str]
display_name: Optional[str] # Actual name shown in "public" areas. Maybe overridden by event_badge or event_presenter.
title: Optional[str]
affiliation: Optional[str]
degrees: Optional[str]
credentials: Optional[str]
tagline: Optional[str]
biography: Optional[str]
email: Optional[str]
website_url: Optional[str]
thumbnail_hosted_file_id: Optional[int]
thumbnail_hosted_file_id_random: Optional[str]
thumbnail_path: Optional[str]
thumbnail_bg_color: Optional[str]
# photo_path: Optional[str]
# photo_bg_color: Optional[str]
picture_hosted_file_id: Optional[int]
picture_hosted_file_id_random: Optional[str]
picture_path: Optional[str]
picture_bg_color: Optional[str]
about_hosted_file_id: Optional[int]
about_hosted_file_id_random: Optional[str]
about_path: Optional[str]
email_allowed: Optional[bool]
email_marketing: Optional[bool]
email_updates: Optional[bool]
show_online: Optional[bool]
show_printed: Optional[bool]
enable: 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 JSON data
extended_json: Optional[Json]
# Including other related objects
contact: Optional[Contact_Base]
event_cfg: Optional[Event_Cfg_Base] = Field(
alias = 'cfg',
)
organization: Optional[Organization_Base]
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
#@validator('event_person_profile_id_random', always=True)
def event_person_profile_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_person_profile_id_lookup(cls, v, values, **kwargs):
log.setLevel(logging.WARNING)
log.debug(locals())
if values['id_random']:
log.debug(values['id_random'])
return redis_lookup_id_random(record_id_random=values['id_random'], table_name='event_person_profile')
return None
@validator('account_id', always=True)
def account_id_lookup(cls, v, values, **kwargs):
log.setLevel(logging.WARNING)
log.debug(locals())
if values['account_id_random']:
return redis_lookup_id_random(record_id_random=values['account_id_random'], table_name='account')
return None
@validator('contact_id', always=True)
def contact_id_lookup(cls, v, values, **kwargs):
log.setLevel(logging.WARNING)
log.debug(locals())
if values['contact_id_random']:
return redis_lookup_id_random(record_id_random=values['contact_id_random'], table_name='contact')
return None
@validator('organization_id', always=True)
def organization_id_lookup(cls, v, values, **kwargs):
log.setLevel(logging.WARNING)
log.debug(locals())
if values['organization_id_random']:
return redis_lookup_id_random(record_id_random=values['organization_id_random'], table_name='organization')
return None
@validator('thumbnail_hosted_file_id', always=True)
def thumbnail_hosted_file_id_lookup(cls, v, values, **kwargs):
log.setLevel(logging.WARNING)
log.debug(locals())
if values.get('thumbnail_hosted_file_id_random', None):
return redis_lookup_id_random(record_id_random=values['thumbnail_hosted_file_id_random'], table_name='thumbnail_hosted_file')
return None
@validator('picture_hosted_file_id', always=True)
def picture_hosted_file_id_lookup(cls, v, values, **kwargs):
log.setLevel(logging.WARNING)
log.debug(locals())
if values.get('picture_hosted_file_id_random', None):
return redis_lookup_id_random(record_id_random=values['picture_hosted_file_id_random'], table_name='picture_hosted_file')
return None
@validator('about_hosted_file_id', always=True)
def about_hosted_file_id_lookup(cls, v, values, **kwargs):
log.setLevel(logging.WARNING)
log.debug(locals())
if values.get('about_hosted_file_id_random', None):
return redis_lookup_id_random(record_id_random=values['about_hosted_file_id_random'], table_name='about_hosted_file')
return None
class Config:
underscore_attrs_are_private = True
allow_population_by_field_name = True
fields = base_fields
class Event_Person_Profile_Base_Up(Event_Person_Profile_Base):
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
# Including JSON data
extended_json: Optional[str]

View File

@@ -33,6 +33,7 @@ async def post_event_person_obj_new_v4(
fail_any: bool = True, # Fail if any thing goes wrong for sub objects
inc_event_badge: bool = False,
inc_event_person_profile: bool = False,
inc_person: bool = False,
inc_user: bool = False,
@@ -64,6 +65,7 @@ async def post_event_person_obj_new_v4(
if load_event_person_obj_result := load_event_person_obj(
event_person_id = event_person_id,
inc_event_badge = inc_event_badge,
inc_event_person_profile = inc_event_person_profile,
inc_person = inc_person,
inc_user = inc_user,
):
@@ -92,6 +94,7 @@ async def patch_event_person_obj_exist_v4(
fail_any: bool = True, # Fail if any thing goes wrong for sub objects
inc_event_badge: bool = False,
inc_event_person_profile: bool = False,
inc_person: bool = False,
inc_user: bool = False,
@@ -124,6 +127,7 @@ async def patch_event_person_obj_exist_v4(
if load_event_person_obj_result := load_event_person_obj(
event_person_id = event_person_id,
inc_event_badge = inc_event_badge,
inc_event_person_profile = inc_event_person_profile,
inc_person = inc_person,
inc_user = inc_user,
):
@@ -154,6 +158,7 @@ async def post_event_person_new(
inc_event: bool = False, # Not ready yet. Placeholder.
inc_event_badge: bool = False, # Not ready yet. Placeholder.
inc_event_person_detail: bool = False, # Not ready yet. Placeholder.
inc_event_person_profile: bool = False,
inc_event_registration: bool = False, # Not ready yet. Placeholder.
inc_person: bool = False,
inc_user: bool = False,
@@ -374,7 +379,7 @@ async def patch_event_person_json(
# Working well as of 2021-06-04. Using as a template for other routes.
@router.get('/event/person/{event_person_id}', response_model=Resp_Body_Base)
async def get_event_person_obj(
event_person_id: str = Query(..., min_length=1, max_length=22),
event_person_id: str = Query(..., min_length=11, max_length=22),
enabled: str = 'enabled', # For now this covers any included objects or object lists
limit: int = 500, # For now this covers any included objects or object lists
inc_address: bool = False, # Under contact
@@ -386,6 +391,7 @@ async def get_event_person_obj(
inc_event_file_list: bool = False,
#inc_event_location_list: bool = False,
#inc_event_person_list: bool = False,
inc_event_person_profile: bool = False,
inc_event_presentation_list: bool = False,
#inc_event_presenter_list: bool = False,
inc_event_registration: bool = False,
@@ -417,6 +423,7 @@ async def get_event_person_obj(
inc_event_file_list = inc_event_file_list,
#inc_event_location = inc_event_location,
#inc_event_person_list = inc_event_person_list,
inc_event_person_profile = inc_event_person_profile,
inc_event_presentation_list = inc_event_presentation_list,
#inc_event_presenter_list = inc_event_presenter_list,
inc_event_registration = inc_event_registration,
@@ -444,6 +451,7 @@ async def get_event_registration_event_person_obj_li(
inc_address: bool = False,
inc_contact: bool = False,
inc_event_badge: bool = False,
inc_event_person_profile: bool = False,
inc_person: bool = False,
# inc_user: bool = False,
x_account_id: str = Header(...),
@@ -472,6 +480,7 @@ async def get_event_registration_event_person_obj_li(
exclude_unset = exclude_unset,
# model_as_dict = model_as_dict,
enabled = enabled,
inc_event_person_profile = inc_event_person_profile,
inc_person = inc_person,
# inc_user = inc_user,
):