Working on event person, registration, badge, session, presentation, and presenter create and update. _v3 things
This commit is contained in:
@@ -14,6 +14,7 @@ from app.methods.organization_methods import create_update_organization_obj, loa
|
||||
# from app.methods.user_methods import create_user_obj # , load_user_obj, update_user_obj
|
||||
|
||||
from app.models.common_field_schema import default_num_bytes
|
||||
from app.models.contact_models import Contact_Base
|
||||
from app.models.person_models import Person_Base
|
||||
|
||||
|
||||
@@ -372,6 +373,7 @@ def get_account_id_w_person_id(
|
||||
|
||||
# ### 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.
|
||||
# Updated 2021-08-25
|
||||
# Reviewed and updated 2021-08-24
|
||||
# Reviewed and updated 2021-08-21
|
||||
# Reviewed and updated 2021-08-10
|
||||
@@ -388,8 +390,19 @@ def create_person_obj_v3(
|
||||
if account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'): pass
|
||||
else: return False
|
||||
|
||||
log.debug(type(person_obj_new))
|
||||
if isinstance(person_obj_new, dict):
|
||||
try:
|
||||
person_obj_new = Person_Base(**person_obj_new)
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(person_obj_new)
|
||||
except ValidationError as e:
|
||||
log.error(e.json())
|
||||
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)
|
||||
person_obj_data['account_id'] = account_id
|
||||
|
||||
if person_obj_in_result := sql_insert(data=person_obj_data, table_name='person', rm_id_random=True, id_random_length=8): pass
|
||||
else:
|
||||
@@ -414,7 +427,7 @@ def create_person_obj_v3(
|
||||
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
|
||||
# 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,
|
||||
@@ -446,6 +459,9 @@ def create_person_obj_v3(
|
||||
contact_obj_unknown.for_id = person_id
|
||||
|
||||
if create_contact_obj_result := create_contact_obj(
|
||||
account_id = account_id,
|
||||
for_type = 'person',
|
||||
for_id = person_id,
|
||||
contact_obj_new = contact_obj_unknown,
|
||||
create_sub_obj = create_sub_obj,
|
||||
fail_any = fail_any,
|
||||
@@ -547,8 +563,9 @@ def create_person_obj_v3(
|
||||
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(
|
||||
# from app.methods.user_methods import update_user_obj_v3
|
||||
from app.methods.user_methods import update_user_obj
|
||||
if update_user_obj_result := update_user_obj(
|
||||
user_id = user_id,
|
||||
user_obj_up = user_obj_unknown,
|
||||
# create_sub_obj = create_sub_obj,
|
||||
@@ -572,13 +589,10 @@ def create_person_obj_v3(
|
||||
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(
|
||||
# from app.methods.user_methods import create_user_obj_v3
|
||||
from app.methods.user_methods import create_user_obj
|
||||
if create_user_obj_result := create_user_obj(
|
||||
account_id = account_id,
|
||||
user_obj_new = user_obj_unknown,
|
||||
# create_sub_obj = create_sub_obj,
|
||||
# fail_any = fail_any,
|
||||
@@ -646,14 +660,16 @@ def create_person_obj_v3(
|
||||
|
||||
|
||||
# ### BEGIN ### API Person Methods ### update_person_obj_v3() ###
|
||||
# Updated 2021-08-25
|
||||
# Updated 2021-08-24
|
||||
def update_person_obj_v3(
|
||||
person_id: int|str,
|
||||
person_obj_exist: Person_Base,
|
||||
create_sub_obj: bool = False,
|
||||
fail_any: bool = False, # Fail if any thing goes wrong for sub objects
|
||||
return_dict: bool = False,
|
||||
) -> bool:
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if person_id := redis_lookup_id_random(record_id_random=person_id, table_name='person'): pass
|
||||
@@ -661,6 +677,18 @@ def update_person_obj_v3(
|
||||
|
||||
account_id = get_account_id_w_person_id(person_id=person_id)
|
||||
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(type(person_obj_exist))
|
||||
log.debug(person_obj_exist)
|
||||
if isinstance(person_obj_exist, dict):
|
||||
try:
|
||||
person_obj_exist = Person_Base(**person_obj_exist)
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(person_obj_exist)
|
||||
except ValidationError as e:
|
||||
log.error(e.json())
|
||||
return False
|
||||
|
||||
# Can't update the person_id alias if the .id was never set.
|
||||
# person_obj_exist.person_id = person_id
|
||||
if not person_obj_exist.id:
|
||||
@@ -683,15 +711,28 @@ def update_person_obj_v3(
|
||||
return_dict['organization_id'] = None
|
||||
return_dict['user_id'] = None
|
||||
|
||||
if person_obj_exist.contact and isinstance(person_obj_exist.contact, dict):
|
||||
if person_obj_exist.contact:
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
contact_obj_unknown = person_obj_exist.contact
|
||||
log.debug(contact_obj_unknown)
|
||||
if contact_id := contact_obj_unknown.get('contact_id_random', None):
|
||||
from app.methods.contact_methods import update_contact_obj_v3
|
||||
if update_contact_obj_result := update_contact_obj_v3(
|
||||
if isinstance(person_obj_exist.contact, dict):
|
||||
contact_id = contact_obj_unknown.get('contact_id_random', None)
|
||||
# try:
|
||||
# contact_obj_new = Contact_Base(**contact_obj_new)
|
||||
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
# log.debug(contact_obj_new)
|
||||
# except ValidationError as e:
|
||||
# log.error(e.json())
|
||||
# return False
|
||||
else:
|
||||
contact_id = contact_obj_unknown.id
|
||||
|
||||
# if contact_id := contact_obj_unknown.get('contact_id_random', None):
|
||||
if contact_id:
|
||||
# from app.methods.contact_methods import update_contact_obj_v3
|
||||
if update_contact_obj_result := update_contact_obj(
|
||||
contact_id = contact_id,
|
||||
contact_obj_exist = contact_obj_unknown,
|
||||
contact_obj_up = contact_obj_unknown,
|
||||
create_sub_obj = create_sub_obj,
|
||||
fail_any = fail_any,
|
||||
):
|
||||
@@ -713,9 +754,11 @@ def update_person_obj_v3(
|
||||
if fail_any: return False
|
||||
else:
|
||||
log.info(f'No Contact ID found.')
|
||||
from app.methods.contact_methods import create_contact_obj
|
||||
# from app.methods.contact_methods import create_contact_obj_v3
|
||||
if create_contact_obj_result := create_contact_obj(
|
||||
person_id = person_id,
|
||||
account_id = account_id,
|
||||
for_type = 'person',
|
||||
for_id = person_id,
|
||||
contact_obj_new = contact_obj_unknown,
|
||||
create_sub_obj = create_sub_obj,
|
||||
fail_any = fail_any,
|
||||
@@ -799,9 +842,10 @@ def update_person_obj_v3(
|
||||
log.debug(user_obj_unknown)
|
||||
if user_id := user_obj_unknown.get('user_id_random', None):
|
||||
# from app.methods.user_methods import update_user_obj_v3
|
||||
from app.methods.user_methods import update_user_obj
|
||||
if update_user_obj_result := update_user_obj(
|
||||
user_id = user_id,
|
||||
user_obj_exist = user_obj_unknown,
|
||||
user_obj_up = user_obj_unknown,
|
||||
create_sub_obj = create_sub_obj,
|
||||
fail_any = fail_any,
|
||||
):
|
||||
@@ -824,6 +868,7 @@ def update_person_obj_v3(
|
||||
else:
|
||||
log.info(f'No User ID found.')
|
||||
# from app.methods.user_methods import create_user_obj_v3
|
||||
from app.methods.user_methods import create_user_obj
|
||||
if create_user_obj_result := create_user_obj(
|
||||
account_id = account_id,
|
||||
user_obj_new = user_obj_unknown,
|
||||
|
||||
Reference in New Issue
Block a user