Working on event person, registration, badge, session, presentation, and presenter create and update. _v3 things
This commit is contained in:
@@ -117,8 +117,13 @@ def get_contact_rec_list(
|
||||
|
||||
# ### BEGIN ### API Contact Methods ### create_contact_obj() ###
|
||||
# NOTE: This will create a contact and then also create a linked address if contact_obj.address data is passed.
|
||||
# Reviewed and updated 2021-08-10
|
||||
def create_contact_obj(contact_obj_new:Contact_Base):
|
||||
# NOTE: In the future it should be required that account_id, for_type, and for_id should be passed separately. account_id might not be required *if* it can be looked up based on for_type and for_id.
|
||||
# Reviewed and updated 2021-08-24
|
||||
def create_contact_obj(
|
||||
contact_obj_new: Contact_Base,
|
||||
create_sub_obj: bool = False,
|
||||
fail_any: bool = False, # Fail if any thing goes wrong for sub objects
|
||||
) -> int|bool:
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
@@ -167,6 +172,7 @@ def update_contact_obj(
|
||||
contact_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
|
||||
contact_obj_up: Contact_Base,
|
||||
create_missing_obj: bool = False,
|
||||
fail_any: bool = False, # Fail if any thing goes wrong for sub objects
|
||||
) -> bool:
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
@@ -189,9 +195,9 @@ def update_contact_obj(
|
||||
log.debug(address_id)
|
||||
log.debug(address_obj_up)
|
||||
if address_obj_up_result := update_address_obj(
|
||||
address_id=address_id,
|
||||
address_obj_up=address_obj_up,
|
||||
create_missing_obj=create_missing_obj,
|
||||
address_id = address_id,
|
||||
address_obj_up = address_obj_up,
|
||||
create_missing_obj = create_missing_obj,
|
||||
):
|
||||
log.debug(address_obj_up_result)
|
||||
else:
|
||||
|
||||
@@ -11,7 +11,7 @@ from app.methods.address_methods import load_address_obj
|
||||
from app.methods.contact_methods import load_contact_obj
|
||||
from app.methods.event_cfg_methods import load_event_cfg_obj
|
||||
from app.methods.event_session_methods import load_event_session_obj
|
||||
from app.methods.person_methods import create_person_obj, load_person_obj, update_person_obj
|
||||
from app.methods.person_methods import create_person_obj_v3, load_person_obj, update_person_obj
|
||||
from app.methods.user_methods import create_user_obj, load_user_obj, update_user_obj
|
||||
|
||||
from app.models.event_models import Event_Base
|
||||
@@ -500,6 +500,37 @@ def load_event_obj_list(
|
||||
# ### END ### API Event Methods ### load_event_obj_list() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Event Methods ### get_account_id_w_event_id() ###
|
||||
# Updated 2021-08-24
|
||||
def get_account_id_w_event_id(
|
||||
event_id: int|str,
|
||||
) -> bool|int|None:
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if event_id := redis_lookup_id_random(record_id_random=event_id, table_name='event'): pass
|
||||
else: return False
|
||||
|
||||
data = {}
|
||||
data['event_id'] = event_id
|
||||
|
||||
sql = f"""
|
||||
SELECT `event`.id AS 'event_id', `event`.id_random AS 'event_id_random', `event`.account_id AS account_id
|
||||
FROM `event` AS `event`
|
||||
WHERE `event`.id = :event_id
|
||||
LIMIT 1;
|
||||
"""
|
||||
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
if event_data_result := sql_select(data=data, sql=sql):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(event_data_result)
|
||||
if account_id := event_data_result.get('account_id', None): return account_id
|
||||
else: return False
|
||||
else: return None
|
||||
# ### END ### API Event Methods ### get_account_id_w_event_person_id() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Event Methods ### update_event_obj() ###
|
||||
def update_event_obj(
|
||||
event_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
|
||||
@@ -512,6 +543,8 @@ def update_event_obj(
|
||||
if event_id := redis_lookup_id_random(record_id_random=event_id, table_name='event'): pass
|
||||
else: return False
|
||||
|
||||
account_id = get_account_id_w_event_id(event_id=event_id)
|
||||
|
||||
event_obj_up.id = event_id
|
||||
|
||||
log.debug(event_obj_up)
|
||||
@@ -537,7 +570,7 @@ def update_event_obj(
|
||||
# NOTE: This will blindly create a new person even if there was one associated but the event.poc_person_id was not found.
|
||||
poc_person_obj_in = event_obj_up.poc_person
|
||||
log.debug(poc_person_obj_in)
|
||||
if poc_person_obj_in_result := create_person_obj(person_obj_new=poc_person_obj_in):
|
||||
if poc_person_obj_in_result := create_person_obj_v3(person_obj_new=poc_person_obj_in):
|
||||
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(poc_person_obj_in_result)
|
||||
event_obj_up.poc_person_id = poc_person_obj_in_result
|
||||
|
||||
@@ -16,7 +16,7 @@ from app.methods.event_badge_methods import load_event_badge_obj
|
||||
# from app.methods.event_registration_methods import create_event_registration_obj, load_event_registration_obj, update_event_registration_obj_v3
|
||||
# from app.methods.event_session_methods import load_event_session_obj
|
||||
# from app.methods.event_track_methods import load_event_track_obj
|
||||
from app.methods.person_methods import create_person_obj, load_person_obj, update_person_obj
|
||||
from app.methods.person_methods import create_person_obj_v3, load_person_obj, update_person_obj
|
||||
from app.methods.user_methods import create_user_obj, load_user_obj, update_user_obj
|
||||
|
||||
from app.models.event_person_models import Event_Person_New_Base, Event_Person_Base
|
||||
@@ -184,11 +184,73 @@ def get_event_person_rec_list(
|
||||
# ### END ### API Event Person Methods ### get_event_person_rec_list() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Event Person Methods ### get_account_id_w_event_person_id() ###
|
||||
# Updated 2021-08-24
|
||||
def get_account_id_w_event_person_id(
|
||||
event_person_id: int|str,
|
||||
) -> bool|int|None:
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if event_person_id := redis_lookup_id_random(record_id_random=event_person_id, table_name='event_person'): pass
|
||||
else: return False
|
||||
|
||||
data = {}
|
||||
data['event_person_id'] = event_person_id
|
||||
|
||||
sql = f"""
|
||||
SELECT `event_person`.id AS 'event_person_id', `event_person`.id_random AS 'event_person_id_random', `event_person`.account_id AS account_id
|
||||
FROM `event_person` AS `event_person`
|
||||
WHERE `event_person`.id = :event_person_id
|
||||
LIMIT 1;
|
||||
"""
|
||||
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
if event_person_data_result := sql_select(data=data, sql=sql):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(event_person_data_result)
|
||||
if account_id := event_person_data_result.get('account_id', None): return account_id
|
||||
else: return False
|
||||
else: return None
|
||||
# ### END ### API Event Person Methods ### get_account_id_w_event_person_id() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Event Person Methods ### get_event_id_w_event_person_id() ###
|
||||
# Updated 2021-08-24
|
||||
def get_event_id_w_event_person_id(
|
||||
event_person_id: int|str,
|
||||
) -> bool|int|None:
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if event_person_id := redis_lookup_id_random(record_id_random=event_person_id, table_name='event_person'): pass
|
||||
else: return False
|
||||
|
||||
data = {}
|
||||
data['event_person_id'] = event_person_id
|
||||
|
||||
sql = f"""
|
||||
SELECT `event_person`.id AS 'event_person_id', `event_person`.id_random AS 'event_person_id_random', `event_person`.event_id AS event_id
|
||||
FROM `event_person` AS `event_person`
|
||||
WHERE `event_person`.id = :event_person_id
|
||||
LIMIT 1;
|
||||
"""
|
||||
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
if event_person_data_result := sql_select(data=data, sql=sql):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(event_person_data_result)
|
||||
if event_id := event_person_data_result.get('event_id', None): return event_id
|
||||
else: return False
|
||||
else: return None
|
||||
# ### END ### API Event Person Methods ### get_event_id_w_event_person_id() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Event Person Methods ### create_event_person_obj() ###
|
||||
# NOTE: This will create an event_person. This event_person should include at least a person_id.
|
||||
# NOTE: Is it a good idea to create and or update a person and or user here??? The create_event_person_obj() below does do that.
|
||||
# NOTE NOTE NOTE NOTE: I don't like the idea of creating or updating person and or user here. It just does not seem right... Security risk? Complexity?
|
||||
# Reviewed and updated 2021-08-10
|
||||
# Updated 2021-08-24
|
||||
def create_event_person_obj(
|
||||
event_id: int|str,
|
||||
event_person_obj_new: Event_Person_Base,
|
||||
@@ -218,6 +280,7 @@ def create_event_person_obj(
|
||||
return_dict['event_registration_id'] = None
|
||||
|
||||
if event_person_obj_new.event_badge and isinstance(event_person_obj_new.event_badge, dict):
|
||||
log.info(f'Event Badge was found. Create a new Event Badge and link it to the new Event Person or update existing Event Badge. Event Person ID: {event_person_id}')
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
event_badge_obj_unknown = event_person_obj_new.event_badge
|
||||
log.debug(event_badge_obj_unknown)
|
||||
@@ -274,6 +337,7 @@ def create_event_person_obj(
|
||||
pass
|
||||
|
||||
if event_person_obj_new.event_registration and isinstance(event_person_obj_new.event_registration, dict):
|
||||
log.info(f'Event Registration was found. Create a new Event Registration and link it to the new Event Person or update existing Event Registration. Event Person ID: {event_person_id}')
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
event_registration_obj_unknown = event_person_obj_new.event_registration
|
||||
log.debug(event_registration_obj_unknown)
|
||||
@@ -341,13 +405,13 @@ def create_event_person_obj(
|
||||
if event_person_obj_new.event_session and event_person_obj_new.poc_event_session_id: pass # POC for event session; could be more than one
|
||||
if event_person_obj_new.event_registration and event_person_obj_new.poc_event_registration_id: pass # Primary registrant for registration; only one
|
||||
|
||||
log.info(f'The event person has been created. Event Person ID: {event_person_id}')
|
||||
log.info(f'The Event Person has been created. Event Person ID: {event_person_id}')
|
||||
return event_person_id
|
||||
# ### END ### API Event Person Methods ### create_event_person_obj() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Event Person Methods ### update_event_person_obj_v3() ###
|
||||
# Updated 2021-08-21
|
||||
# Updated 2021-08-24
|
||||
def update_event_person_obj_v3(
|
||||
event_person_id: int|str,
|
||||
event_person_obj_exist: Event_Person_Base,
|
||||
@@ -489,15 +553,13 @@ def update_event_person_obj_v3(
|
||||
log.info('Event Registration not found or not in a dict.')
|
||||
pass
|
||||
|
||||
log.info(f'The event person has been updated. Event Person ID: {event_person_id}')
|
||||
log.info(f'The Event Person has been updated. Event Person ID: {event_person_id}')
|
||||
return True
|
||||
# ### END ### API Event Person Methods ### update_event_person_obj_v3() ###
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# ### BEGIN ### API Event Person Methods ### update_event_person_obj() ###
|
||||
# NOTE: This will update an event_person. This also tries to create or update a person or user if that data is passed.
|
||||
# NOTE: Is it a good idea to create and or update a person and or user here???
|
||||
@@ -515,6 +577,8 @@ def update_event_person_obj(
|
||||
if event_person_id := redis_lookup_id_random(record_id_random=event_person_id, table_name='event_person'): pass
|
||||
else: return False
|
||||
|
||||
account_id = get_account_id_w_event_person_id(event_person_id)
|
||||
|
||||
event_person_obj_up.id = event_person_id
|
||||
|
||||
log.debug(event_person_obj_up)
|
||||
@@ -540,7 +604,7 @@ def update_event_person_obj(
|
||||
# NOTE: This will blindly create a new person even if there was one associated but the event_person.person_id was not found.
|
||||
person_obj_in = event_person_obj_up.person
|
||||
log.debug(person_obj_in)
|
||||
if person_obj_in_result := create_person_obj(person_obj_new=person_obj_in):
|
||||
if person_obj_in_result := create_person_obj_v3(account_id=account_id, person_obj_new=person_obj_in):
|
||||
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(person_obj_in_result)
|
||||
event_person_obj_up.person_id = person_obj_in_result
|
||||
|
||||
@@ -146,7 +146,7 @@ def load_event_presentation_obj(
|
||||
# Updated 2021-08-23
|
||||
def get_event_id_w_event_session_id(
|
||||
event_session_id: int|str,
|
||||
) -> bool|None:
|
||||
) -> bool|int|None:
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
@@ -259,7 +259,7 @@ def create_event_presentation_obj(
|
||||
log.info('Event Presenter List not found')
|
||||
pass
|
||||
|
||||
log.info(f'The event presentation has been created. Event Presentation ID: {event_presentation_id}')
|
||||
log.info(f'The Event Presentation has been created. Event Presentation ID: {event_presentation_id}')
|
||||
return event_presentation_id
|
||||
# ### END ### API Event Presentation Methods ### create_event_presentation_obj() ###
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ def load_event_presenter_obj(
|
||||
# Updated 2021-08-23
|
||||
def get_event_session_id_w_event_presentation_id(
|
||||
event_presentation_id: int|str,
|
||||
) -> bool|None:
|
||||
) -> bool|int|None:
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
@@ -206,7 +206,7 @@ def create_event_presenter_obj(
|
||||
return_dict = {}
|
||||
return_dict['event_presenter_id'] = None
|
||||
|
||||
log.info(f'The event presenter has been created. Event Presenter ID: {event_presenter_id}')
|
||||
log.info(f'The Event Presenter has been created. Event Presenter ID: {event_presenter_id}')
|
||||
return event_presenter_id
|
||||
# ### END ### API Event Presenter Methods ### create_event_presenter_obj() ###
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ def load_event_registration_obj(
|
||||
# Updated 2021-08-23
|
||||
def get_event_id_w_event_person_id(
|
||||
event_person_id: int|str,
|
||||
) -> bool|None:
|
||||
) -> bool|int|None:
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
|
||||
@@ -232,6 +232,7 @@ def create_event_session_obj(
|
||||
return_dict['event_presentation_list'] = []
|
||||
|
||||
if event_session_obj_new.event_presentation_list and isinstance(event_session_obj_new.event_presentation_list, list):
|
||||
log.info(f'Event Presentation List was found. Loop through and create a new Event Presentation for each and link them to the new Event Session. Event Session ID: {event_session_id}')
|
||||
for event_presentation_obj_new in event_session_obj_new.event_presentation_list:
|
||||
# NOTE: This does not account for an edge case where the presentation already exists. Possibly as part of another session.
|
||||
if create_event_presentation_obj_result := create_event_presentation_obj(
|
||||
@@ -258,7 +259,7 @@ def create_event_session_obj(
|
||||
log.info('Event Presentation List not found')
|
||||
pass
|
||||
|
||||
log.info(f'The event session has been created. Event Session ID: {event_session_id}')
|
||||
log.info(f'The Event Session has been created. Event Session ID: {event_session_id}')
|
||||
return event_session_id
|
||||
# ### END ### API Event Session Methods ### create_event_session_obj() ###
|
||||
|
||||
|
||||
@@ -339,11 +339,13 @@ def get_person_rec_w_external_id(
|
||||
# ### END ### API Person Methods ### get_person_rec_w_external_id() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Person Methods ### create_person_obj() ###
|
||||
# ### BEGIN ### API Person Methods ### create_person_obj_v3() ###
|
||||
# NOTE: This will create a person and then also create a linked contact if person_obj.contact data is passed. The create_contact_obj will create a contact and then also create a linked address if person_obj.contact.address data is passed.
|
||||
# Reviewed and updated 2021-08-24
|
||||
# Reviewed and updated 2021-08-21
|
||||
# Reviewed and updated 2021-08-10
|
||||
def create_person_obj(
|
||||
def create_person_obj_v3(
|
||||
account_id: int|str,
|
||||
person_obj_new: Person_Base,
|
||||
create_sub_obj: bool = False,
|
||||
fail_any: bool = True, # Fail if any thing goes wrong for sub objects
|
||||
@@ -352,6 +354,9 @@ def create_person_obj(
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'): pass
|
||||
else: return False
|
||||
|
||||
person_obj_data = person_obj_new.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'contact', 'organization', 'user', 'created_on', 'updated_on'})
|
||||
log.debug(person_obj_data)
|
||||
|
||||
@@ -370,30 +375,199 @@ def create_person_obj(
|
||||
return_dict['contact']['address_id'] = None
|
||||
return_dict['user_id'] = None
|
||||
|
||||
if person_obj_new.contact:
|
||||
log.info(f'Contact data was found. Create a new contact and link it to the new person. Person ID: {person_id}')
|
||||
contact_obj_new = person_obj_new.contact
|
||||
contact_obj_new.for_type = 'person'
|
||||
contact_obj_new.for_id = person_id
|
||||
create_contact_obj_result = create_contact_obj(contact_obj_new=contact_obj_new)
|
||||
if isinstance(create_contact_obj_result, int):
|
||||
contact_id = create_contact_obj_result
|
||||
log.info(f'Contact created. Contact ID: {contact_id}')
|
||||
else:
|
||||
log.warning(f'Contact not created. Person ID: {person_id}')
|
||||
log.debug(create_contact_obj_result)
|
||||
contact_id = None
|
||||
if fail_any: return False
|
||||
if person_obj_new.contact and isinstance(person_obj_new.contact, dict):
|
||||
log.info(f'Contact was found. Create a new Contact and link it to the new Person or update existing Contact. Person ID: {person_id}')
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
contact_obj_unknown = person_obj_new.contact
|
||||
log.debug(contact_obj_unknown)
|
||||
if contact_id := contact_obj_unknown.get('contact_id_random', None):
|
||||
log.warning('Contact ID found. This is not expected, but should be ok.')
|
||||
from app.methods.contact_methods import update_contact_obj_v3
|
||||
if update_contact_obj_result := update_contact_obj(
|
||||
contact_id = contact_id,
|
||||
contact_obj_up = contact_obj_unknown,
|
||||
create_missing_obj = create_sub_obj,
|
||||
fail_any = fail_any,
|
||||
):
|
||||
contact_id = update_contact_obj_result
|
||||
log.info(f'Contact updated. Contact ID: {contact_id}')
|
||||
else:
|
||||
log.warning(f'Contact not updated. Person ID: {person_id}')
|
||||
log.debug(update_contact_obj_result)
|
||||
contact_id = None
|
||||
if fail_any: return False
|
||||
|
||||
if isinstance(update_contact_obj_result, int):
|
||||
contact_id = update_contact_obj_result
|
||||
log.info(f'Contact updated. Contact ID: {contact_id}')
|
||||
else:
|
||||
log.warning(f'Contact not updated. Person ID: {person_id}')
|
||||
log.debug(update_contact_obj_result)
|
||||
contact_id = None
|
||||
if fail_any: return False
|
||||
else:
|
||||
log.info(f'No Contact ID found.')
|
||||
# from app.methods.contact_methods import create_contact_obj
|
||||
|
||||
contact_obj_unknown = person_obj_new.contact
|
||||
contact_obj_unknown.for_type = 'person'
|
||||
contact_obj_unknown.for_id = person_id
|
||||
|
||||
if create_contact_obj_result := create_contact_obj(
|
||||
contact_obj_new = contact_obj_unknown,
|
||||
create_sub_obj = create_sub_obj,
|
||||
fail_any = fail_any,
|
||||
):
|
||||
if isinstance(create_contact_obj_result, int):
|
||||
contact_id = create_contact_obj_result
|
||||
log.info(f'Contact created. Contact ID: {contact_id}')
|
||||
else:
|
||||
log.warning(f'Contact not created. Person ID: {person_id}')
|
||||
log.debug(create_contact_obj_result)
|
||||
contact_id = None
|
||||
if fail_any: return False
|
||||
else:
|
||||
log.warning(f'Contact not created. Person ID: {person_id}')
|
||||
log.debug(create_contact_obj_result)
|
||||
contact_id = None
|
||||
if fail_any: return False
|
||||
return_dict['contact_id'] = contact_id
|
||||
else:
|
||||
log.info('Contact not found or not in a dict.')
|
||||
pass
|
||||
|
||||
# NOTE: This is the older pre v3 version
|
||||
# if person_obj_new.contact:
|
||||
# log.info(f'Contact was found. Create a new Contact and link it to the new Person or update existing Contact. Person ID: {person_id}')
|
||||
# contact_obj_new = person_obj_new.contact
|
||||
# contact_obj_new.for_type = 'person'
|
||||
# contact_obj_new.for_id = person_id
|
||||
# create_contact_obj_result = create_contact_obj(contact_obj_new=contact_obj_new)
|
||||
# if isinstance(create_contact_obj_result, int):
|
||||
# contact_id = create_contact_obj_result
|
||||
# log.info(f'Contact created. Contact ID: {contact_id}')
|
||||
# else:
|
||||
# log.warning(f'Contact not created. Person ID: {person_id}')
|
||||
# log.debug(create_contact_obj_result)
|
||||
# contact_id = None
|
||||
# if fail_any: return False
|
||||
|
||||
if person_obj_new.organization and isinstance(person_obj_new.organization, dict):
|
||||
log.info(f'Organization was found. Create a new Organization and link it to the new Person or update existing Organization. Person ID: {person_id}')
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
organization_obj_unknown = person_obj_new.organization
|
||||
log.debug(organization_obj_unknown)
|
||||
if organization_id := organization_obj_unknown.get('organization_id_random', None):
|
||||
log.warning('Organization ID found. This is not expected, but should be ok.')
|
||||
# from app.methods.organization_methods import update_organization_obj_v3
|
||||
if update_organization_obj_result := update_organization_obj(
|
||||
organization_id = organization_id,
|
||||
organization_obj_up = organization_obj_unknown,
|
||||
create_missing_obj = create_sub_obj,
|
||||
fail_any = fail_any,
|
||||
):
|
||||
organization_id = update_organization_obj_result
|
||||
log.info(f'Organization updated. Organization ID: {organization_id}')
|
||||
else:
|
||||
log.warning(f'Organization not updated. Person ID: {person_id}')
|
||||
log.debug(update_organization_obj_result)
|
||||
organization_id = None
|
||||
if fail_any: return False
|
||||
|
||||
if isinstance(update_organization_obj_result, int):
|
||||
organization_id = update_organization_obj_result
|
||||
log.info(f'Organization updated. Organization ID: {organization_id}')
|
||||
else:
|
||||
log.warning(f'Organization not updated. Person ID: {person_id}')
|
||||
log.debug(update_organization_obj_result)
|
||||
organization_id = None
|
||||
if fail_any: return False
|
||||
else:
|
||||
log.info(f'No Organization ID found.')
|
||||
# from app.methods.organization_methods import create_organization_obj_v3
|
||||
if create_organization_obj_result := create_organization_obj(
|
||||
organization_obj_new = organization_obj_unknown,
|
||||
create_sub_obj = create_sub_obj,
|
||||
fail_any = fail_any,
|
||||
):
|
||||
if isinstance(create_organization_obj_result, int):
|
||||
organization_id = create_organization_obj_result
|
||||
log.info(f'Organization created. Organization ID: {organization_id}')
|
||||
else:
|
||||
log.warning(f'Organization not created. Person ID: {person_id}')
|
||||
log.debug(create_organization_obj_result)
|
||||
organization_id = None
|
||||
if fail_any: return False
|
||||
else:
|
||||
log.warning(f'Organization not created. Person ID: {person_id}')
|
||||
log.debug(create_organization_obj_result)
|
||||
organization_id = None
|
||||
if fail_any: return False
|
||||
return_dict['organization_id'] = organization_id
|
||||
else:
|
||||
log.info('Organization not found or not in a dict.')
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
if person_obj_new.user and isinstance(person_obj_new.user, dict):
|
||||
log.info(f'User was found. Create a new User and link it to the new Person or update existing User. Person ID: {person_id}')
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
user_obj_unknown = person_obj_new.user
|
||||
log.debug(user_obj_unknown)
|
||||
if user_id := user_obj_unknown.get('user_id_random', None):
|
||||
log.warning('User ID found. This is not expected, but should be ok.')
|
||||
from app.methods.user_methods import update_user_obj_v3
|
||||
if update_user_obj_result := update_user_obj_v3(
|
||||
user_id = user_id,
|
||||
user_obj_up = user_obj_unknown,
|
||||
# create_missing_obj = create_sub_obj,
|
||||
# fail_any = fail_any,
|
||||
):
|
||||
user_id = update_user_obj_result
|
||||
log.info(f'User updated. User ID: {user_id}')
|
||||
else:
|
||||
log.warning(f'User not updated. Person ID: {person_id}')
|
||||
log.debug(update_user_obj_result)
|
||||
user_id = None
|
||||
if fail_any: return False
|
||||
|
||||
if isinstance(update_user_obj_result, int):
|
||||
user_id = update_user_obj_result
|
||||
log.info(f'User updated. User ID: {user_id}')
|
||||
else:
|
||||
log.warning(f'User not updated. Person ID: {person_id}')
|
||||
log.debug(update_user_obj_result)
|
||||
user_id = None
|
||||
if fail_any: return False
|
||||
else:
|
||||
log.info(f'No User ID found.')
|
||||
from app.methods.user_methods import create_user_obj_v3
|
||||
|
||||
user_obj_unknown = person_obj_new.user
|
||||
user_obj_unknown.for_type = 'person'
|
||||
user_obj_unknown.for_id = person_id
|
||||
|
||||
if create_user_obj_result := create_user_obj_v3(
|
||||
user_obj_new = user_obj_unknown,
|
||||
# create_sub_obj = create_sub_obj,
|
||||
# fail_any = fail_any,
|
||||
):
|
||||
if isinstance(create_user_obj_result, int):
|
||||
user_id = create_user_obj_result
|
||||
log.info(f'User created. User ID: {user_id}')
|
||||
else:
|
||||
log.warning(f'User not created. Person ID: {person_id}')
|
||||
log.debug(create_user_obj_result)
|
||||
user_id = None
|
||||
if fail_any: return False
|
||||
else:
|
||||
log.warning(f'User not created. Person ID: {person_id}')
|
||||
log.debug(create_user_obj_result)
|
||||
user_id = None
|
||||
if fail_any: return False
|
||||
|
||||
if person_obj_new.user:
|
||||
log.info(f'User data was found. Create a new user and link it to the new person. Person ID: {person_id}')
|
||||
from app.methods.user_methods import create_user_obj
|
||||
user_obj_new = person_obj_new.user
|
||||
user_obj_new.person_id = person_id
|
||||
create_user_obj_result = create_user_obj(user_obj_new=user_obj_new)
|
||||
if isinstance(create_user_obj_result, int):
|
||||
log.info(f'User created. User ID: {user_id} Update person {person_id} with new user ID.')
|
||||
user_id = create_user_obj_result
|
||||
# Need to update the person with the new user_id
|
||||
person_obj_up = {}
|
||||
person_obj_up['id'] = person_id
|
||||
@@ -404,15 +578,42 @@ def create_person_obj(
|
||||
log.warning(f'Person not updated with user ID. Person ID: {person_id} User ID: {user_id}')
|
||||
if fail_any: return False
|
||||
log.debug(person_obj_up_result)
|
||||
else:
|
||||
log.warning(f'User not created. Person ID: {person_id}')
|
||||
log.debug(create_user_obj_result)
|
||||
user_id = None
|
||||
if fail_any: return False
|
||||
|
||||
return_dict['user_id'] = user_id
|
||||
else:
|
||||
log.info('User not found or not in a dict.')
|
||||
pass
|
||||
|
||||
|
||||
# NOTE: This is the older pre v3 version
|
||||
# if person_obj_new.user:
|
||||
# log.info(f'User data was found. Create a new user and link it to the new person. Person ID: {person_id}')
|
||||
# from app.methods.user_methods import create_user_obj
|
||||
# user_obj_new = person_obj_new.user
|
||||
# user_obj_new.person_id = person_id
|
||||
# create_user_obj_result = create_user_obj(user_obj_new=user_obj_new)
|
||||
# if isinstance(create_user_obj_result, int):
|
||||
# log.info(f'User created. User ID: {user_id} Update person {person_id} with new user ID.')
|
||||
# user_id = create_user_obj_result
|
||||
# # Need to update the person with the new user_id
|
||||
# person_obj_up = {}
|
||||
# person_obj_up['id'] = person_id
|
||||
# person_obj_up['user_id'] = user_id
|
||||
# if person_obj_up_result := sql_update(data=person_obj_up, table_name='person'):
|
||||
# log.info(f'Person updated with user ID. Person ID: {person_id} User ID: {user_id}')
|
||||
# else:
|
||||
# log.warning(f'Person not updated with user ID. Person ID: {person_id} User ID: {user_id}')
|
||||
# if fail_any: return False
|
||||
# log.debug(person_obj_up_result)
|
||||
# else:
|
||||
# log.warning(f'User not created. Person ID: {person_id}')
|
||||
# log.debug(create_user_obj_result)
|
||||
# user_id = None
|
||||
# if fail_any: return False
|
||||
|
||||
log.debug(f'Returning the new person_id: {person_id}')
|
||||
return person_id
|
||||
# ### END ### API Person Methods ### create_person_obj() ###
|
||||
# ### END ### API Person Methods ### create_person_obj_v3() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Person Methods ### update_person_obj() ###
|
||||
|
||||
@@ -11,7 +11,7 @@ from app.methods.contact_methods import load_contact_obj, update_contact_obj
|
||||
# from app.methods.event_methods import get_event_rec_list
|
||||
from app.methods.order_methods import load_order_obj, get_order_rec_list
|
||||
from app.methods.organization_methods import load_organization_obj, update_organization_obj
|
||||
from app.methods.person_methods import load_person_obj, update_person_obj
|
||||
from app.methods.person_methods import create_person_obj_v3, load_person_obj, update_person_obj
|
||||
from app.methods.post_methods import get_post_rec_list, load_post_obj
|
||||
from app.methods.user_role_methods import get_user_role_rec_list, load_user_role_obj
|
||||
|
||||
@@ -367,7 +367,7 @@ def update_user_obj(
|
||||
# # NOTE: This will blindly create a new person even if there was one associated but the user.person_id was not found.
|
||||
# person_obj_in = user_obj_up.person
|
||||
# log.debug(person_obj_in)
|
||||
# if person_obj_in_result := create_person_obj(person_obj_new=person_obj_in):
|
||||
# if person_obj_in_result := create_person_obj_v3(person_obj_new=person_obj_in):
|
||||
# # log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
# log.debug(person_obj_in_result)
|
||||
# person_obj_up.person_id = person_obj_in_result
|
||||
|
||||
@@ -5,12 +5,12 @@ from typing import Dict, List, Optional, Set, Union
|
||||
|
||||
from app.lib_general import log, logging
|
||||
from app.config import settings
|
||||
from app.db_sql import sql_insert, sql_update, sql_insert_or_update, sql_select, sql_delete, redis_lookup_id_random
|
||||
from app.db_sql import sql_insert, sql_update, sql_insert_or_update, sql_select, sql_delete, get_id_random, redis_lookup_id_random
|
||||
|
||||
from app.routers.api_crud import delete_obj_template, get_obj_template, get_obj_li_template, patch_obj_template, post_obj_template
|
||||
|
||||
from app.methods.event_person_methods import create_event_person_obj, get_event_person_rec_list, load_event_person_obj, update_event_person_obj
|
||||
from app.methods.person_methods import create_person_obj, load_person_obj, update_person_obj
|
||||
from app.methods.event_person_methods import create_event_person_obj, get_event_person_rec_list, load_event_person_obj, update_event_person_obj, update_event_person_obj_v3
|
||||
from app.methods.person_methods import create_person_obj_v3, load_person_obj, update_person_obj
|
||||
from app.methods.user_methods import create_user_obj, load_user_obj, update_user_obj
|
||||
# from app.methods.user_load_methods import load_user_obj
|
||||
|
||||
@@ -24,6 +24,96 @@ from app.models.user_models import User_New_Base, User_Base
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
# ### BEGIN ### API Event Person ### post_event_person_obj_new_v3() ###
|
||||
# Updated 2021-08-24
|
||||
@router.post('/new_v3', response_model=Resp_Body_Base)
|
||||
async def post_event_person_obj_new_v3(
|
||||
event_person_obj: Event_Person_Base,
|
||||
create_sub_obj: bool = False,
|
||||
fail_any: bool = True, # Fail if any thing goes wrong for sub objects
|
||||
x_account_id: str = Header(...),
|
||||
return_obj: bool = True,
|
||||
by_alias: bool = True,
|
||||
exclude_unset: bool = True,
|
||||
response: Response = Response,
|
||||
):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
# There should probably be a check for the event ID before calling the create function?
|
||||
if create_event_person_obj_result := create_event_person_obj(
|
||||
event_id = event_person_obj.event_id,
|
||||
event_person_obj_new = event_person_obj,
|
||||
create_sub_obj = create_sub_obj,
|
||||
fail_any = fail_any
|
||||
): pass
|
||||
else: return mk_resp(data=False, status_code=400, response=response, status_message='The event person was not created. Check the field names and data types.')
|
||||
|
||||
if isinstance(create_event_person_obj_result, int):
|
||||
event_person_id = create_event_person_obj_result
|
||||
if return_obj:
|
||||
if load_event_person_obj_result := load_event_person_obj(event_person_id=event_person_id):
|
||||
data = load_event_person_obj_result
|
||||
else:
|
||||
data = False
|
||||
else:
|
||||
event_person_id = create_event_person_obj_result
|
||||
event_person_id_random = get_id_random(record_id=event_person_id, table_name='event_person')
|
||||
data = {}
|
||||
data['event_person_id'] = event_person_id
|
||||
data['event_person_id_random'] = event_person_id_random
|
||||
return mk_resp(data=data, response=response, status_message='The event person was created.')
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400, response=response, status_message='The result from trying to create an event person was unexpected.')
|
||||
# ### BEGIN ### API Event Person ### post_event_person_obj_new_v3() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Event Person ### patch_event_person_obj_exist_v3() ###
|
||||
# Updated 2021-08-24
|
||||
@router.patch('/{event_person_id}/exist_v3', response_model=Resp_Body_Base)
|
||||
async def patch_event_person_obj_exist_v3(
|
||||
event_person_obj: Event_Person_Base,
|
||||
event_person_id: str = Query(..., min_length=11, max_length=22),
|
||||
create_sub_obj: bool = False,
|
||||
fail_any: bool = True, # Fail if any thing goes wrong for sub objects
|
||||
x_account_id: Optional[str] = Header(..., ),
|
||||
return_obj: Optional[bool] = True,
|
||||
by_alias: Optional[bool] = True,
|
||||
exclude_unset: Optional[bool] = True,
|
||||
exclude_none: Optional[bool] = True,
|
||||
response: Response = Response,
|
||||
):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if event_person_id := redis_lookup_id_random(record_id_random=event_person_id, table_name='event_person'): pass
|
||||
else: return mk_resp(data=None, status_code=404)
|
||||
|
||||
if update_event_person_obj_result := update_event_person_obj_v3(
|
||||
event_person_id = event_person_id,
|
||||
event_person_obj_exist = event_person_obj,
|
||||
create_sub_obj = create_sub_obj,
|
||||
fail_any = fail_any,
|
||||
): pass
|
||||
else: return mk_resp(data=False, status_code=400, response=response, status_message='The event person was not created. Check the field names and data types.')
|
||||
|
||||
if update_event_person_obj_result:
|
||||
if return_obj:
|
||||
if load_event_person_obj_result := load_event_person_obj(event_person_id=event_person_id):
|
||||
data = load_event_person_obj_result
|
||||
else:
|
||||
data = False
|
||||
else:
|
||||
event_person_id_random = get_id_random(record_id=event_person_id, table_name='event_person')
|
||||
data = {}
|
||||
data['event_person_id'] = event_person_id
|
||||
data['event_person_id_random'] = event_person_id_random
|
||||
return mk_resp(data=data, response=response, status_message='The event person was created.')
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400, response=response, status_message='The result from trying to create an event person was unexpected.')
|
||||
# ### END ### API Event Person ### patch_event_person_obj_exist_v3() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Event Person Route ### post_event_person_new() ###
|
||||
# Initialize/create a new event person
|
||||
# Create a person record (with a contact record and an address for the contact record)
|
||||
@@ -97,7 +187,7 @@ async def post_event_person_new(
|
||||
|
||||
return mk_resp(data=False, status_code=401, response=response) # TESTING TESTING TESTING
|
||||
|
||||
create_person_obj_result = create_person_obj(person_obj_new=person_obj_new)
|
||||
create_person_obj_result = create_person_obj_v3(account_id=account_id_random, person_obj_new=person_obj_new)
|
||||
if isinstance(create_person_obj_result, int):
|
||||
person_id = create_person_obj_result
|
||||
person_obj = load_person_obj(
|
||||
|
||||
@@ -42,10 +42,10 @@ async def post_event_session_obj(
|
||||
return result
|
||||
|
||||
|
||||
# ### BEGIN ### API Event Session ### post_event_session_obj_new() ###
|
||||
# ### BEGIN ### API Event Session ### post_event_session_obj_new_v3() ###
|
||||
# Updated 2021-08-21 (all new)
|
||||
@router.post('/new', response_model=Resp_Body_Base)
|
||||
async def post_event_session_obj_new(
|
||||
@router.post('/new_v3', response_model=Resp_Body_Base)
|
||||
async def post_event_session_obj_new_v3(
|
||||
event_session_obj: Event_Session_Base,
|
||||
create_sub_obj: bool = False,
|
||||
fail_any: bool = True, # Fail if any thing goes wrong for sub objects
|
||||
@@ -61,9 +61,9 @@ async def post_event_session_obj_new(
|
||||
# There should probably be a check for the event ID before calling the create function?
|
||||
if create_event_session_obj_result := create_event_session_obj(
|
||||
event_id = event_session_obj.event_id,
|
||||
event_session_obj_new=event_session_obj,
|
||||
create_sub_obj=create_sub_obj,
|
||||
fail_any=fail_any
|
||||
event_session_obj_new = event_session_obj,
|
||||
create_sub_obj = create_sub_obj,
|
||||
fail_any = fail_any
|
||||
): pass
|
||||
else: return mk_resp(data=False, status_code=400, response=response, status_message='The event session was not created. Check the field names and data types.')
|
||||
|
||||
@@ -83,12 +83,13 @@ async def post_event_session_obj_new(
|
||||
return mk_resp(data=data, response=response, status_message='The event session was created.')
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400, response=response, status_message='The result from trying to create an event session was unexpected.')
|
||||
# ### BEGIN ### API Event Session ### post_event_session_obj_new() ###
|
||||
# ### BEGIN ### API Event Session ### post_event_session_obj_new_v3() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Event Session ### patch_event_session_obj_v3() ###
|
||||
@router.patch('/{event_session_id}/v3', response_model=Resp_Body_Base)
|
||||
async def patch_event_session_obj_v3(
|
||||
# ### BEGIN ### API Event Session ### patch_event_session_obj_exist_v3() ###
|
||||
# Updated 2021-08-24
|
||||
@router.patch('/{event_session_id}/exist_v3', response_model=Resp_Body_Base)
|
||||
async def patch_event_session_obj_exist_v3(
|
||||
event_session_obj: Event_Session_Base,
|
||||
event_session_id: str = Query(..., min_length=11, max_length=22),
|
||||
create_sub_obj: bool = False,
|
||||
@@ -128,7 +129,7 @@ async def patch_event_session_obj_v3(
|
||||
return mk_resp(data=data, response=response, status_message='The event session was created.')
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400, response=response, status_message='The result from trying to create an event session was unexpected.')
|
||||
# ### END ### API Event Session ### patch_event_session_obj_v3() ###
|
||||
# ### END ### API Event Session ### patch_event_session_obj_exist_v3() ###
|
||||
|
||||
|
||||
@router.patch('/{obj_id}', response_model=Resp_Body_Base)
|
||||
|
||||
@@ -5,13 +5,13 @@ from typing import Dict, List, Optional, Set, Union
|
||||
|
||||
from app.lib_general import log, logging
|
||||
from app.config import settings
|
||||
from app.db_sql import sql_insert, sql_update, sql_insert_or_update, sql_select, sql_delete, redis_lookup_id_random
|
||||
from app.db_sql import sql_insert, sql_update, sql_insert_or_update, sql_select, sql_delete, get_id_random, redis_lookup_id_random
|
||||
|
||||
from app.routers.api_crud import delete_obj_template, get_obj_template, get_obj_li_template, patch_obj_template, post_obj_template
|
||||
|
||||
# from app.methods.membership_person_methods import load_membership_person_obj
|
||||
from app.methods.order_methods import get_order_rec_list, load_order_obj
|
||||
from app.methods.person_methods import create_update_person_obj, get_person_rec_list, get_person_rec_w_external_id, load_person_obj, update_person_obj
|
||||
from app.methods.person_methods import create_person_obj_v3, create_update_person_obj, get_person_rec_list, get_person_rec_w_external_id, load_person_obj, update_person_obj
|
||||
|
||||
from app.models.person_models import Person_Base
|
||||
from app.models.response_models import Resp_Body_Base, mk_resp
|
||||
@@ -72,6 +72,52 @@ async def patch_person_obj(
|
||||
return result
|
||||
|
||||
|
||||
# ### BEGIN ### API Person ### post_person_obj_new_v3() ###
|
||||
# Updated 2021-08-24
|
||||
@router.post('/new_v3', response_model=Resp_Body_Base)
|
||||
async def post_person_obj_new_v3(
|
||||
person_obj: Person_Base,
|
||||
create_sub_obj: bool = False,
|
||||
fail_any: bool = True, # Fail if any thing goes wrong for sub objects
|
||||
x_account_id: str = Header(...),
|
||||
return_obj: bool = True,
|
||||
by_alias: bool = True,
|
||||
exclude_unset: bool = True,
|
||||
response: Response = Response,
|
||||
):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
# There should probably be a check for the account ID before calling the create function?
|
||||
if create_person_obj_result := create_person_obj_v3(
|
||||
account_id = person_obj.account_id,
|
||||
person_obj_new = person_obj,
|
||||
create_sub_obj = create_sub_obj,
|
||||
fail_any = fail_any
|
||||
): pass
|
||||
else: return mk_resp(data=False, status_code=400, response=response, status_message='The person was not created. Check the field names and data types.')
|
||||
|
||||
if isinstance(create_person_obj_result, int):
|
||||
person_id = create_person_obj_result
|
||||
if return_obj:
|
||||
if load_person_obj_result := load_person_obj(person_id=person_id):
|
||||
data = load_person_obj_result
|
||||
else:
|
||||
data = False
|
||||
else:
|
||||
person_id = create_person_obj_result
|
||||
person_id_random = get_id_random(record_id=person_id, table_name='person')
|
||||
data = {}
|
||||
data['person_id'] = person_id
|
||||
data['person_id_random'] = person_id_random
|
||||
return mk_resp(data=data, response=response, status_message='The person was created.')
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400, response=response, status_message='The result from trying to create an person was unexpected.')
|
||||
# ### BEGIN ### API Person ### post_person_obj_new_v3() ###
|
||||
|
||||
|
||||
|
||||
|
||||
# ### BEGIN ### API Person ### post_person_json() ###
|
||||
# Updated 2021-06-25
|
||||
@router.post('/person/json', response_model=Resp_Body_Base)
|
||||
|
||||
Reference in New Issue
Block a user