Code clean up and standardize

This commit is contained in:
Scott Idem
2021-08-25 10:58:39 -04:00
parent 7859d1d2b2
commit 1369874dc2
32 changed files with 479 additions and 195 deletions

View File

@@ -129,7 +129,7 @@ def create_address_obj(address_obj_new:Address_Base):
def update_address_obj( def update_address_obj(
address_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value. address_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
address_obj_up: Address_Base, address_obj_up: Address_Base,
create_missing_obj: bool = False, create_sub_obj: bool = False,
) -> bool: ) -> bool:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())

View File

@@ -171,7 +171,7 @@ def create_contact_obj(
def update_contact_obj( 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_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
contact_obj_up: Contact_Base, contact_obj_up: Contact_Base,
create_missing_obj: bool = False, create_sub_obj: bool = False,
fail_any: bool = False, # Fail if any thing goes wrong for sub objects fail_any: bool = False, # Fail if any thing goes wrong for sub objects
) -> bool: ) -> bool:
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
@@ -197,7 +197,7 @@ def update_contact_obj(
if address_obj_up_result := update_address_obj( if address_obj_up_result := update_address_obj(
address_id = address_id, address_id = address_id,
address_obj_up = address_obj_up, address_obj_up = address_obj_up,
create_missing_obj = create_missing_obj, create_sub_obj = create_sub_obj,
): ):
log.debug(address_obj_up_result) log.debug(address_obj_up_result)
else: else:

View File

@@ -535,7 +535,7 @@ def get_account_id_w_event_id(
def 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. event_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
event_obj_up: Event_Base, event_obj_up: Event_Base,
create_missing_obj: bool = False, create_sub_obj: bool = False,
) -> bool: ) -> bool:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())
@@ -558,9 +558,9 @@ def update_event_obj(
log.debug(poc_person_id) log.debug(poc_person_id)
log.debug(poc_person_obj_up) log.debug(poc_person_obj_up)
if poc_person_obj_up_result := update_person_obj( if poc_person_obj_up_result := update_person_obj(
poc_person_id=poc_person_id, poc_person_id = poc_person_id,
poc_person_obj_up=poc_person_obj_up, poc_person_obj_up = poc_person_obj_up,
create_missing_obj=create_missing_obj, create_sub_obj = create_sub_obj,
): ):
log.debug(poc_person_obj_up_result) log.debug(poc_person_obj_up_result)
else: else:
@@ -586,9 +586,9 @@ def update_event_obj(
log.debug(user_id) log.debug(user_id)
log.debug(user_obj_up) log.debug(user_obj_up)
if user_obj_up_result := update_user_obj( if user_obj_up_result := update_user_obj(
user_id=user_id, user_id = user_id,
user_obj_up=user_obj_up, user_obj_up = user_obj_up,
create_missing_obj=create_missing_obj, create_sub_obj = create_sub_obj,
): ):
log.debug(user_obj_up_result) log.debug(user_obj_up_result)
else: else:

View File

@@ -569,7 +569,7 @@ def update_event_person_obj_v3(
def update_event_person_obj( def update_event_person_obj(
event_person_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value. event_person_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
event_person_obj_up: Event_Person_Base, event_person_obj_up: Event_Person_Base,
create_missing_obj: bool = False, create_sub_obj: bool = False,
) -> bool: ) -> bool:
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())
@@ -594,7 +594,7 @@ def update_event_person_obj(
if person_obj_up_result := update_person_obj( if person_obj_up_result := update_person_obj(
person_id=person_id, person_id=person_id,
person_obj_up=person_obj_up, person_obj_up=person_obj_up,
create_missing_obj=create_missing_obj, create_sub_obj=create_sub_obj,
): ):
log.debug(person_obj_up_result) log.debug(person_obj_up_result)
else: else:
@@ -620,9 +620,9 @@ def update_event_person_obj(
log.debug(user_id) log.debug(user_id)
log.debug(user_obj_up) log.debug(user_obj_up)
if user_obj_up_result := update_user_obj( if user_obj_up_result := update_user_obj(
user_id=user_id, user_id = user_id,
user_obj_up=user_obj_up, user_obj_up = user_obj_up,
create_missing_obj=create_missing_obj, create_sub_obj = create_sub_obj,
): ):
log.debug(user_obj_up_result) log.debug(user_obj_up_result)
else: else:

View File

@@ -371,7 +371,7 @@ def update_event_presentation_obj_v3(
def update_event_presentation_obj( def update_event_presentation_obj(
event_presentation_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value. event_presentation_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
event_presentation_obj_up: Event_Presentation_Base, event_presentation_obj_up: Event_Presentation_Base,
create_missing_obj: bool = False, create_sub_obj: bool = False,
) -> bool: ) -> bool:
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())
@@ -395,7 +395,7 @@ def update_event_presentation_obj(
# if event_session_obj_up_result := update_event_session_obj( # if event_session_obj_up_result := update_event_session_obj(
# event_session_id=event_session_id, # event_session_id=event_session_id,
# event_session_obj_up=event_session_obj_up, # event_session_obj_up=event_session_obj_up,
# create_missing_obj=create_missing_obj, # create_sub_obj=create_sub_obj,
# ): # ):
# log.debug(event_session_obj_up_result) # log.debug(event_session_obj_up_result)
# else: # else:

View File

@@ -264,7 +264,7 @@ def update_event_presenter_obj_v3(
def update_event_presenter_obj( def update_event_presenter_obj(
event_presenter_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value. event_presenter_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
event_presenter_obj_up: Event_Presenter_Base, event_presenter_obj_up: Event_Presenter_Base,
create_missing_obj: bool = False, create_sub_obj: bool = False,
) -> bool: ) -> bool:
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())
@@ -288,7 +288,7 @@ def update_event_presenter_obj(
if event_person_obj_up_result := update_event_person_obj( if event_person_obj_up_result := update_event_person_obj(
event_person_id=event_person_id, event_person_id=event_person_id,
event_person_obj_up=event_person_obj_up, event_person_obj_up=event_person_obj_up,
create_missing_obj=create_missing_obj, create_sub_obj=create_sub_obj,
): ):
log.debug(event_person_obj_up_result) log.debug(event_person_obj_up_result)
else: else:
@@ -316,7 +316,7 @@ def update_event_presenter_obj(
# if event_presentation_obj_up_result := update_event_presentation_obj( # if event_presentation_obj_up_result := update_event_presentation_obj(
# event_presentation_id=event_presentation_id, # event_presentation_id=event_presentation_id,
# event_presentation_obj_up=event_presentation_obj_up, # event_presentation_obj_up=event_presentation_obj_up,
# create_missing_obj=create_missing_obj, # create_sub_obj=create_sub_obj,
# ): # ):
# log.debug(event_presentation_obj_up_result) # log.debug(event_presentation_obj_up_result)
# else: # else:
@@ -344,7 +344,7 @@ def update_event_presenter_obj(
# if event_session_obj_up_result := update_event_session_obj( # if event_session_obj_up_result := update_event_session_obj(
# event_session_id=event_session_id, # event_session_id=event_session_id,
# event_session_obj_up=event_session_obj_up, # event_session_obj_up=event_session_obj_up,
# create_missing_obj=create_missing_obj, # create_sub_obj=create_sub_obj,
# ): # ):
# log.debug(event_session_obj_up_result) # log.debug(event_session_obj_up_result)
# else: # else:

View File

@@ -361,7 +361,7 @@ def update_event_session_obj_v3(
def update_event_session_obj( def update_event_session_obj(
event_session_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value. event_session_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
event_session_obj_up: Event_Session_Base, event_session_obj_up: Event_Session_Base,
create_missing_obj: bool = False, create_sub_obj: bool = False,
) -> bool: ) -> bool:
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())
@@ -385,7 +385,7 @@ def update_event_session_obj(
if poc_event_person_obj_up_result := update_event_person_obj( if poc_event_person_obj_up_result := update_event_person_obj(
event_person_id=poc_event_person_id, event_person_id=poc_event_person_id,
event_person_obj_up=poc_event_person_obj_up, event_person_obj_up=poc_event_person_obj_up,
create_missing_obj=create_missing_obj, create_sub_obj=create_sub_obj,
): ):
log.debug(poc_event_person_obj_up_result) log.debug(poc_event_person_obj_up_result)
else: else:
@@ -413,7 +413,7 @@ def update_event_session_obj(
if event_presentation_obj_up_result := update_event_presentation_obj( if event_presentation_obj_up_result := update_event_presentation_obj(
event_presentation_id=event_presentation_id, event_presentation_id=event_presentation_id,
event_presentation_obj_up=event_presentation_obj_up, event_presentation_obj_up=event_presentation_obj_up,
create_missing_obj=create_missing_obj, create_sub_obj=create_sub_obj,
): ):
log.debug(event_presentation_obj_up_result) log.debug(event_presentation_obj_up_result)
else: else:

View File

@@ -72,7 +72,7 @@ def load_journal_entry_obj(
def update_journal_entry_obj( def update_journal_entry_obj(
journal_entry_id: int|str, # This allows for updating of the id_random value. journal_entry_id: int|str, # This allows for updating of the id_random value.
journal_entry_obj_up: Journal_Entry_Base, journal_entry_obj_up: Journal_Entry_Base,
create_missing_obj: bool = False, create_sub_obj: bool = False,
) -> bool: ) -> bool:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())

View File

@@ -104,7 +104,7 @@ def load_journal_obj(
def update_journal_obj( def update_journal_obj(
journal_id: int|str, # This allows for updating of the id_random value. journal_id: int|str, # This allows for updating of the id_random value.
journal_obj_up: Journal_Base, journal_obj_up: Journal_Base,
create_missing_obj: bool = False, create_sub_obj: bool = False,
) -> bool: ) -> bool:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())

View File

@@ -263,7 +263,7 @@ def create_membership_group_obj(membership_group_obj_new:Membership_Group_Base)
def update_membership_group_obj( def update_membership_group_obj(
membership_group_id: int|str, # This allows for updating of the id_random value. membership_group_id: int|str, # This allows for updating of the id_random value.
membership_group_obj_up: Membership_Group_Base, membership_group_obj_up: Membership_Group_Base,
create_missing_obj: bool = False, create_sub_obj: bool = False,
) -> bool: ) -> bool:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())

View File

@@ -165,7 +165,7 @@ def create_membership_group_person_obj(membership_group_person_obj_new:Membershi
def update_membership_group_person_obj( def update_membership_group_person_obj(
membership_group_person_id: int|str, # This allows for updating of the id_random value. membership_group_person_id: int|str, # This allows for updating of the id_random value.
membership_group_person_obj_up: Membership_Group_Person_Base, membership_group_person_obj_up: Membership_Group_Person_Base,
create_missing_obj: bool = False, create_sub_obj: bool = False,
) -> bool: ) -> bool:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())

View File

@@ -212,7 +212,7 @@ def create_membership_type_person_obj(membership_type_person_obj_new:Membership_
def update_membership_type_person_obj( def update_membership_type_person_obj(
membership_type_person_id: int|str, # This allows for updating of the id_random value. membership_type_person_id: int|str, # This allows for updating of the id_random value.
membership_type_person_obj_up: Membership_Type_Person_Base, membership_type_person_obj_up: Membership_Type_Person_Base,
create_missing_obj: bool = False, create_sub_obj: bool = False,
) -> bool: ) -> bool:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())

View File

@@ -74,7 +74,7 @@ def load_order_cart_line_obj(
def update_order_cart_line_obj( def update_order_cart_line_obj(
order_cart_line_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value. order_cart_line_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
order_cart_line_obj_up: Order_Cart_Line_Base, order_cart_line_obj_up: Order_Cart_Line_Base,
create_missing_obj: bool = False, create_sub_obj: bool = False,
) -> bool: ) -> bool:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())
@@ -97,9 +97,9 @@ def update_order_cart_line_obj(
# log.debug(person_id) # log.debug(person_id)
# log.debug(person_obj_up) # log.debug(person_obj_up)
# if person_obj_up_result := update_person_obj( # if person_obj_up_result := update_person_obj(
# person_id=person_id, # person_id = person_id,
# person_obj_up=person_obj_up, # person_obj_up = person_obj_up,
# create_missing_obj=create_missing_obj, # create_sub_obj = create_sub_obj,
# ): # ):
# log.debug(person_obj_up_result) # log.debug(person_obj_up_result)
# else: # else:
@@ -112,9 +112,9 @@ def update_order_cart_line_obj(
# log.debug(user_id) # log.debug(user_id)
# log.debug(user_obj_up) # log.debug(user_obj_up)
# if user_obj_up_result := update_user_obj( # if user_obj_up_result := update_user_obj(
# user_id=user_id, # user_id = user_id,
# user_obj_up=user_obj_up, # user_obj_up = user_obj_up,
# create_missing_obj=create_missing_obj, # create_sub_obj = create_sub_obj,
# ): # ):
# log.debug(user_obj_up_result) # log.debug(user_obj_up_result)
# else: # else:

View File

@@ -72,7 +72,7 @@ def load_order_line_obj(
def update_order_line_obj( def update_order_line_obj(
order_line_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value. order_line_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
order_line_obj_up: Order_Line_Base, order_line_obj_up: Order_Line_Base,
create_missing_obj: bool = False, create_sub_obj: bool = False,
) -> bool: ) -> bool:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())
@@ -95,9 +95,9 @@ def update_order_line_obj(
# log.debug(person_id) # log.debug(person_id)
# log.debug(person_obj_up) # log.debug(person_obj_up)
# if person_obj_up_result := update_person_obj( # if person_obj_up_result := update_person_obj(
# person_id=person_id, # person_id = person_id,
# person_obj_up=person_obj_up, # person_obj_up = person_obj_up,
# create_missing_obj=create_missing_obj, # create_sub_obj = create_sub_obj,
# ): # ):
# log.debug(person_obj_up_result) # log.debug(person_obj_up_result)
# else: # else:
@@ -110,9 +110,9 @@ def update_order_line_obj(
# log.debug(user_id) # log.debug(user_id)
# log.debug(user_obj_up) # log.debug(user_obj_up)
# if user_obj_up_result := update_user_obj( # if user_obj_up_result := update_user_obj(
# user_id=user_id, # user_id = user_id,
# user_obj_up=user_obj_up, # user_obj_up = user_obj_up,
# create_missing_obj=create_missing_obj, # create_sub_obj = create_sub_obj,
# ): # ):
# log.debug(user_obj_up_result) # log.debug(user_obj_up_result)
# else: # else:

View File

@@ -127,7 +127,7 @@ def get_organization_rec_list(
def update_organization_obj( def update_organization_obj(
organization_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value. organization_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
organization_obj_up: Organization_Base, organization_obj_up: Organization_Base,
create_missing_obj: bool = False, create_sub_obj: bool = False,
) -> bool: ) -> bool:
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())
@@ -140,7 +140,7 @@ def update_organization_obj(
if contact_obj_up_result := update_contact_obj( if contact_obj_up_result := update_contact_obj(
contact_id=contact_id, contact_id=contact_id,
contact_obj_up=contact_obj_up, contact_obj_up=contact_obj_up,
create_missing_obj=create_missing_obj, create_sub_obj=create_sub_obj,
): ):
log.debug(contact_obj_up_result) log.debug(contact_obj_up_result)
else: else:

View File

@@ -339,6 +339,37 @@ def get_person_rec_w_external_id(
# ### END ### API Person Methods ### get_person_rec_w_external_id() ### # ### END ### API Person Methods ### get_person_rec_w_external_id() ###
# ### BEGIN ### API Person Methods ### get_account_id_w_person_id() ###
# Updated 2021-08-25
def get_account_id_w_person_id(
person_id: int|str,
) -> bool|int|None:
log.setLevel(logging.WARNING) # 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
else: return False
data = {}
data['person_id'] = person_id
sql = f"""
SELECT `person`.id AS 'person_id', `person`.id_random AS 'person_id_random', `person`.account_id AS account_id
FROM `person` AS `person`
WHERE `person`.id = :person_id
LIMIT 1;
"""
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
if person_data_result := sql_select(data=data, sql=sql):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(person_data_result)
if account_id := person_data_result.get('account_id', None): return account_id
else: return False
else: return None
# ### END ### API Person Methods ### get_account_id_w_person_id() ###
# ### BEGIN ### API Person Methods ### create_person_obj_v3() ### # ### 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. # 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-24
@@ -373,6 +404,7 @@ def create_person_obj_v3(
return_dict['contact_id'] = None return_dict['contact_id'] = None
return_dict['contact'] = {} return_dict['contact'] = {}
return_dict['contact']['address_id'] = None return_dict['contact']['address_id'] = None
return_dict['organization_id'] = None
return_dict['user_id'] = None return_dict['user_id'] = None
if person_obj_new.contact and isinstance(person_obj_new.contact, dict): if person_obj_new.contact and isinstance(person_obj_new.contact, dict):
@@ -386,7 +418,7 @@ def create_person_obj_v3(
if update_contact_obj_result := update_contact_obj( if update_contact_obj_result := update_contact_obj(
contact_id = contact_id, contact_id = contact_id,
contact_obj_up = contact_obj_unknown, contact_obj_up = contact_obj_unknown,
create_missing_obj = create_sub_obj, create_sub_obj = create_sub_obj,
fail_any = fail_any, fail_any = fail_any,
): ):
contact_id = update_contact_obj_result contact_id = update_contact_obj_result
@@ -463,7 +495,7 @@ def create_person_obj_v3(
if update_organization_obj_result := update_organization_obj( if update_organization_obj_result := update_organization_obj(
organization_id = organization_id, organization_id = organization_id,
organization_obj_up = organization_obj_unknown, organization_obj_up = organization_obj_unknown,
create_missing_obj = create_sub_obj, create_sub_obj = create_sub_obj,
fail_any = fail_any, fail_any = fail_any,
): ):
organization_id = update_organization_obj_result organization_id = update_organization_obj_result
@@ -508,9 +540,6 @@ def create_person_obj_v3(
log.info('Organization not found or not in a dict.') log.info('Organization not found or not in a dict.')
pass pass
if person_obj_new.user and isinstance(person_obj_new.user, dict): 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.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 log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
@@ -522,7 +551,7 @@ def create_person_obj_v3(
if update_user_obj_result := update_user_obj_v3( if update_user_obj_result := update_user_obj_v3(
user_id = user_id, user_id = user_id,
user_obj_up = user_obj_unknown, user_obj_up = user_obj_unknown,
# create_missing_obj = create_sub_obj, # create_sub_obj = create_sub_obj,
# fail_any = fail_any, # fail_any = fail_any,
): ):
user_id = update_user_obj_result user_id = update_user_obj_result
@@ -616,13 +645,220 @@ def create_person_obj_v3(
# ### END ### API Person Methods ### create_person_obj_v3() ### # ### END ### API Person Methods ### create_person_obj_v3() ###
# ### BEGIN ### API Person Methods ### update_person_obj_v3() ###
# Updated 2021-08-24
def update_person_obj_v3(
person_id: int|str,
person_obj_exist: Event_Person_Base,
create_sub_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())
if person_id := redis_lookup_id_random(record_id_random=person_id, table_name='person'): pass
else: 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:
person_obj_exist.id = person_id
person_obj_data = person_obj_exist.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'contact', 'organization', 'user', 'created_on', 'updated_on'})
log.debug(person_obj_data)
if person_obj_up_result := sql_update(data=person_obj_data, table_name='person', rm_id_random=True): pass
else:
log.warning(f'Person not updated.')
log.debug(person_obj_up_result)
return False
return_dict = {}
return_dict['person_id'] = person_id
return_dict['contact_id'] = None
return_dict['contact'] = {}
return_dict['contact']['address_id'] = None
return_dict['organization_id'] = None
return_dict['user_id'] = None
if person_obj_exist.contact and isinstance(person_obj_exist.contact, dict):
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(
contact_id = contact_id,
contact_obj_exist = contact_obj_unknown,
create_sub_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
if create_contact_obj_result := create_contact_obj(
person_id = person_id,
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
if person_obj_exist.organization and isinstance(person_obj_exist.organization, dict):
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
organization_obj_unknown = person_obj_exist.organization
log.debug(organization_obj_unknown)
if organization_id := organization_obj_unknown.get('organization_id_random', None):
# from app.methods.organization_methods import update_organization_obj_v3
if update_organization_obj_result := update_organization_obj(
organization_id = organization_id,
organization_obj_exist = organization_obj_unknown,
create_sub_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(
person_id = person_id,
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_exist.user and isinstance(person_obj_exist.user, dict):
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
user_obj_unknown = person_obj_exist.user
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
if update_user_obj_result := update_user_obj(
user_id = user_id,
user_obj_exist = user_obj_unknown,
create_sub_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
if create_user_obj_result := create_user_obj(
person_id = person_id,
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
return_dict['user_id'] = user_id
else:
log.info('User not found or not in a dict.')
pass
log.info(f'The Person has been updated. Person ID: {person_id}')
return True
# ### END ### API Person Methods ### update_person_obj_v3() ###
# ### BEGIN ### API Person Methods ### update_person_obj() ### # ### BEGIN ### API Person Methods ### update_person_obj() ###
# NOTE: This will update a person and then also create or update 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. The update_contact_obj will update a contact and then also create or update a linked address if person_obj.contact.address data is passed. # NOTE: This will update a person and then also create or update 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. The update_contact_obj will update a contact and then also create or update a linked address if person_obj.contact.address data is passed.
# Reviewed and updated 2021-08-10 # Reviewed and updated 2021-08-10
def update_person_obj( def update_person_obj(
person_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value. person_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
person_obj_up: Person_Base, person_obj_up: Person_Base,
create_missing_obj: bool = False, create_sub_obj: bool = False,
fail_any: bool = True, # Fail if any thing goes wrong for sub objects fail_any: bool = True, # Fail if any thing goes wrong for sub objects
) -> bool: ) -> bool:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
@@ -646,7 +882,7 @@ def update_person_obj(
if contact_obj_up_result := update_contact_obj( if contact_obj_up_result := update_contact_obj(
contact_id = contact_id, contact_id = contact_id,
contact_obj_up = contact_obj_up, contact_obj_up = contact_obj_up,
create_missing_obj = create_missing_obj, create_sub_obj = create_sub_obj,
): ):
log.debug(contact_obj_up_result) log.debug(contact_obj_up_result)
else: else:
@@ -675,7 +911,7 @@ def update_person_obj(
if organization_obj_up_result := update_organization_obj( if organization_obj_up_result := update_organization_obj(
organization_id = organization_id, organization_id = organization_id,
organization_obj_up = organization_obj_up, organization_obj_up = organization_obj_up,
create_missing_obj = create_missing_obj, create_sub_obj = create_sub_obj,
): ):
log.debug(organization_obj_up_result) log.debug(organization_obj_up_result)
else: else:
@@ -702,9 +938,9 @@ def update_person_obj(
log.debug(user_id) log.debug(user_id)
log.debug(user_obj_up) log.debug(user_obj_up)
if user_obj_up_result := update_user_obj( if user_obj_up_result := update_user_obj(
user_id=user_id, user_id = user_id,
user_obj_up=user_obj_up, user_obj_up = user_obj_up,
create_missing_obj=create_missing_obj, create_sub_obj = create_sub_obj,
): ):
log.debug(user_obj_up_result) log.debug(user_obj_up_result)
else: else:

View File

@@ -107,7 +107,7 @@ def load_post_comment_obj(
def update_post_comment_obj( def update_post_comment_obj(
post_comment_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value. post_comment_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
post_comment_obj_up: Post_Comment_Base, post_comment_obj_up: Post_Comment_Base,
create_missing_obj: bool = False, create_sub_obj: bool = False,
) -> bool: ) -> bool:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())
@@ -130,9 +130,9 @@ def update_post_comment_obj(
# log.debug(person_id) # log.debug(person_id)
# log.debug(person_obj_up) # log.debug(person_obj_up)
# if person_obj_up_result := update_person_obj( # if person_obj_up_result := update_person_obj(
# person_id=person_id, # person_id = person_id,
# person_obj_up=person_obj_up, # person_obj_up = person_obj_up,
# create_missing_obj=create_missing_obj, # create_sub_obj = create_sub_obj,
# ): # ):
# log.debug(person_obj_up_result) # log.debug(person_obj_up_result)
# else: # else:
@@ -145,9 +145,9 @@ def update_post_comment_obj(
# log.debug(user_id) # log.debug(user_id)
# log.debug(user_obj_up) # log.debug(user_obj_up)
# if user_obj_up_result := update_user_obj( # if user_obj_up_result := update_user_obj(
# user_id=user_id, # user_id = user_id,
# user_obj_up=user_obj_up, # user_obj_up = user_obj_up,
# create_missing_obj=create_missing_obj, # create_sub_obj = create_sub_obj,
# ): # ):
# log.debug(user_obj_up_result) # log.debug(user_obj_up_result)
# else: # else:

View File

@@ -134,7 +134,7 @@ def load_post_obj(
def update_post_obj( def update_post_obj(
post_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value. post_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
post_obj_up: Post_Base, post_obj_up: Post_Base,
create_missing_obj: bool = False, create_sub_obj: bool = False,
) -> bool: ) -> bool:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())
@@ -159,7 +159,7 @@ def update_post_obj(
# if person_obj_up_result := update_person_obj( # if person_obj_up_result := update_person_obj(
# person_id=person_id, # person_id=person_id,
# person_obj_up=person_obj_up, # person_obj_up=person_obj_up,
# create_missing_obj=create_missing_obj, # create_sub_obj=create_sub_obj,
# ): # ):
# log.debug(person_obj_up_result) # log.debug(person_obj_up_result)
# else: # else:
@@ -174,7 +174,7 @@ def update_post_obj(
# if user_obj_up_result := update_user_obj( # if user_obj_up_result := update_user_obj(
# user_id=user_id, # user_id=user_id,
# user_obj_up=user_obj_up, # user_obj_up=user_obj_up,
# create_missing_obj=create_missing_obj, # create_sub_obj=create_sub_obj,
# ): # ):
# log.debug(user_obj_up_result) # log.debug(user_obj_up_result)
# else: # else:

View File

@@ -76,7 +76,7 @@ def load_site_domain_obj(
def update_site_domain_obj( def update_site_domain_obj(
site_domain_id: int|str, # This allows for updating of the id_random value. site_domain_id: int|str, # This allows for updating of the id_random value.
site_domain_obj_up: Site_Domain_Base, site_domain_obj_up: Site_Domain_Base,
create_missing_obj: bool = False, create_sub_obj: bool = False,
) -> bool: ) -> bool:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())

View File

@@ -98,7 +98,7 @@ def load_site_obj(
def update_site_obj( def update_site_obj(
site_id: int|str, # This allows for updating of the id_random value. site_id: int|str, # This allows for updating of the id_random value.
site_obj_up: Site_Base, site_obj_up: Site_Base,
create_missing_obj: bool = False, create_sub_obj: bool = False,
) -> bool: ) -> bool:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())

View File

@@ -95,6 +95,112 @@ def create_user_obj(
# ### END ### API User Methods ### create_user_obj() ### # ### END ### API User Methods ### create_user_obj() ###
# ### BEGIN ### API User Methods ### update_user_obj() ###
def update_user_obj(
user_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
user_obj_up: User_Base,
create_sub_obj: bool = False,
) -> bool:
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
if user_id := redis_lookup_id_random(record_id_random=user_id, table_name='user'): pass
else: return False
user_obj_up.id = user_id
log.debug(user_obj_up)
# log.debug(user_obj_up.dict(by_alias=True, exclude_unset=True))
log.debug(user_obj_up.dict(by_alias=False, exclude_unset=True))
# log.debug(user_obj_up.dict(by_alias=False, exclude_unset=False))
# if user_obj_up.contact_id and user_obj_up.contact:
# contact_id = user_obj_up.contact_id
# contact_obj_up = user_obj_up.contact
# log.debug(contact_id)
# log.debug(contact_obj_up)
# if contact_obj_up_result := update_contact_obj(
# contact_id=contact_id,
# contact_obj_up=contact_obj_up,
# create_sub_obj=create_sub_obj,
# ):
# log.debug(contact_obj_up_result)
# else:
# log.debug(contact_obj_up_result)
# return False
# elif user_obj_up.contact and not user_obj_up.contact.id:
# # NOTE: This will blindly create a new contact even if there was one associated but the user.contact_id was not found.
# contact_obj_in = user_obj_up.contact
# log.debug(contact_obj_in)
# if contact_obj_in_result := create_contact_obj(contact_obj_new=contact_obj_in):
# # log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
# log.debug(contact_obj_in_result)
# user_obj_up.contact_id = contact_obj_in_result
# else:
# # log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
# log.debug(contact_obj_in_result)
# return False
# if organization_obj_update := user_obj_up.organization:
# log.debug(organization_obj_update)
# if organization_obj_up_result := update_organization_obj(organization_obj_update):
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
# log.debug(organization_obj_up_result)
# return True
# else:
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
# log.debug(organization_obj_up_result)
# return False
# else:
# if organization_obj_in_result := insert_organization_obj(organization_obj_insert):
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
# log.debug(organization_obj_in_result)
# return True # NOTE: This needs to return the new organization ID
# else:
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
# log.debug(organization_obj_in_result)
# return False
# if user_obj_up.person_id and user_obj_up.person:
# person_id = user_obj_up.person_id
# person_obj_up = user_obj_up.person
# log.debug(person_id)
# log.debug(person_obj_up)
# if person_obj_up_result := update_person_obj(
# person_id=person_id,
# person_obj_up=person_obj_up,
# create_sub_obj=create_sub_obj,
# ):
# log.debug(person_obj_up_result)
# else:
# log.debug(person_obj_up_result)
# return False
# elif user_obj_up.person and not user_obj_up.person.id:
# # 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_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
# else:
# # log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
# log.debug(person_obj_in_result)
# return False
# IMPORTANT NOTE: Need to be extra careful if allowing an update to password, super, or manager. Maybe other fields?
user_dict_up = user_obj_up.dict(by_alias=False, exclude_unset=True, exclude={'password', 'super', 'manager', 'contact', 'organization', 'person'})
log.debug(user_dict_up)
if user_obj_up_result := sql_update(data=user_dict_up, table_name='user', rm_id_random=True):
log.debug(user_obj_up_result)
return True
else:
log.debug(user_obj_up_result)
return False
# ### END ### API User Methods ### update_user_obj() ###
# ### BEGIN ### API User Methods ### load_user_obj() ### # ### BEGIN ### API User Methods ### load_user_obj() ###
def load_user_obj( def load_user_obj(
user_id: int|str, user_id: int|str,
@@ -283,112 +389,6 @@ def load_user_obj(
# ### END ### API User Methods ### load_user_obj() ### # ### END ### API User Methods ### load_user_obj() ###
# ### BEGIN ### API User Methods ### update_user_obj() ###
def update_user_obj(
user_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
user_obj_up: User_Base,
create_missing_obj: bool = False,
) -> bool:
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
if user_id := redis_lookup_id_random(record_id_random=user_id, table_name='user'): pass
else: return False
user_obj_up.id = user_id
log.debug(user_obj_up)
# log.debug(user_obj_up.dict(by_alias=True, exclude_unset=True))
log.debug(user_obj_up.dict(by_alias=False, exclude_unset=True))
# log.debug(user_obj_up.dict(by_alias=False, exclude_unset=False))
# if user_obj_up.contact_id and user_obj_up.contact:
# contact_id = user_obj_up.contact_id
# contact_obj_up = user_obj_up.contact
# log.debug(contact_id)
# log.debug(contact_obj_up)
# if contact_obj_up_result := update_contact_obj(
# contact_id=contact_id,
# contact_obj_up=contact_obj_up,
# create_missing_obj=create_missing_obj,
# ):
# log.debug(contact_obj_up_result)
# else:
# log.debug(contact_obj_up_result)
# return False
# elif user_obj_up.contact and not user_obj_up.contact.id:
# # NOTE: This will blindly create a new contact even if there was one associated but the user.contact_id was not found.
# contact_obj_in = user_obj_up.contact
# log.debug(contact_obj_in)
# if contact_obj_in_result := create_contact_obj(contact_obj_new=contact_obj_in):
# # log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
# log.debug(contact_obj_in_result)
# user_obj_up.contact_id = contact_obj_in_result
# else:
# # log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
# log.debug(contact_obj_in_result)
# return False
# if organization_obj_update := user_obj_up.organization:
# log.debug(organization_obj_update)
# if organization_obj_up_result := update_organization_obj(organization_obj_update):
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
# log.debug(organization_obj_up_result)
# return True
# else:
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
# log.debug(organization_obj_up_result)
# return False
# else:
# if organization_obj_in_result := insert_organization_obj(organization_obj_insert):
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
# log.debug(organization_obj_in_result)
# return True # NOTE: This needs to return the new organization ID
# else:
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
# log.debug(organization_obj_in_result)
# return False
# if user_obj_up.person_id and user_obj_up.person:
# person_id = user_obj_up.person_id
# person_obj_up = user_obj_up.person
# log.debug(person_id)
# log.debug(person_obj_up)
# if person_obj_up_result := update_person_obj(
# person_id=person_id,
# person_obj_up=person_obj_up,
# create_missing_obj=create_missing_obj,
# ):
# log.debug(person_obj_up_result)
# else:
# log.debug(person_obj_up_result)
# return False
# elif user_obj_up.person and not user_obj_up.person.id:
# # 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_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
# else:
# # log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
# log.debug(person_obj_in_result)
# return False
# IMPORTANT NOTE: Need to be extra careful if allowing an update to password, super, or manager. Maybe other fields?
user_dict_up = user_obj_up.dict(by_alias=False, exclude_unset=True, exclude={'password', 'super', 'manager', 'contact', 'organization', 'person'})
log.debug(user_dict_up)
if user_obj_up_result := sql_update(data=user_dict_up, table_name='user', rm_id_random=True):
log.debug(user_obj_up_result)
return True
else:
log.debug(user_obj_up_result)
return False
# ### END ### API User Methods ### update_user_obj() ###
# ### BEGIN ### API User Methods ### get_user_rec_list() ### # ### BEGIN ### API User Methods ### get_user_rec_list() ###
def get_user_rec_list( def get_user_rec_list(
for_obj_type: str, for_obj_type: str,

View File

@@ -78,7 +78,7 @@ async def patch_address_obj(
async def patch_address_json( async def patch_address_json(
address_obj: Address_Base, address_obj: Address_Base,
address_id: str = Query(..., min_length=1, max_length=22), address_id: str = Query(..., min_length=1, max_length=22),
create_missing_obj: bool = False, create_sub_obj: bool = False,
x_account_id: Optional[str] = Header(..., ), x_account_id: Optional[str] = Header(..., ),
return_obj: Optional[bool] = True, return_obj: Optional[bool] = True,
by_alias: Optional[bool] = True, by_alias: Optional[bool] = True,
@@ -98,7 +98,7 @@ async def patch_address_json(
if address_obj_up_result := update_address_obj( if address_obj_up_result := update_address_obj(
address_id=address_id, address_id=address_id,
address_obj_up=address_obj, address_obj_up=address_obj,
create_missing_obj=create_missing_obj, create_sub_obj=create_sub_obj,
): ):
log.debug(address_obj_up_result) log.debug(address_obj_up_result)

View File

@@ -75,7 +75,7 @@ async def patch_cont_edu_cert_obj(
async def patch_cont_edu_cert_json( async def patch_cont_edu_cert_json(
cont_edu_cert_obj: Cont_Edu_Cert_Base, cont_edu_cert_obj: Cont_Edu_Cert_Base,
cont_edu_cert_id: str = Query(..., min_length=1, max_length=22), cont_edu_cert_id: str = Query(..., min_length=1, max_length=22),
create_missing_obj: bool = False, create_sub_obj: bool = False,
x_account_id: Optional[str] = Header(..., ), x_account_id: Optional[str] = Header(..., ),
return_obj: Optional[bool] = True, return_obj: Optional[bool] = True,
by_alias: Optional[bool] = True, by_alias: Optional[bool] = True,
@@ -95,7 +95,7 @@ async def patch_cont_edu_cert_json(
if cont_edu_cert_obj_up_result := update_cont_edu_cert_obj( if cont_edu_cert_obj_up_result := update_cont_edu_cert_obj(
cont_edu_cert_id=cont_edu_cert_id, cont_edu_cert_id=cont_edu_cert_id,
cont_edu_cert_obj_up=cont_edu_cert_obj, cont_edu_cert_obj_up=cont_edu_cert_obj,
create_missing_obj=create_missing_obj, create_sub_obj=create_sub_obj,
): ):
log.debug(cont_edu_cert_obj_up_result) log.debug(cont_edu_cert_obj_up_result)

View File

@@ -75,7 +75,7 @@ async def patch_cont_edu_cert_person_obj(
async def patch_cont_edu_cert_person_json( async def patch_cont_edu_cert_person_json(
cont_edu_cert_person_obj: Cont_Edu_Cert_Person_Base, cont_edu_cert_person_obj: Cont_Edu_Cert_Person_Base,
cont_edu_cert_person_id: str = Query(..., min_length=1, max_length=22), cont_edu_cert_person_id: str = Query(..., min_length=1, max_length=22),
create_missing_obj: bool = False, create_sub_obj: bool = False,
x_account_id: Optional[str] = Header(..., ), x_account_id: Optional[str] = Header(..., ),
return_obj: Optional[bool] = True, return_obj: Optional[bool] = True,
by_alias: Optional[bool] = True, by_alias: Optional[bool] = True,
@@ -95,7 +95,7 @@ async def patch_cont_edu_cert_person_json(
if cont_edu_cert_person_obj_up_result := update_cont_edu_cert_person_obj( if cont_edu_cert_person_obj_up_result := update_cont_edu_cert_person_obj(
cont_edu_cert_person_id=cont_edu_cert_person_id, cont_edu_cert_person_id=cont_edu_cert_person_id,
cont_edu_cert_person_obj_up=cont_edu_cert_person_obj, cont_edu_cert_person_obj_up=cont_edu_cert_person_obj,
create_missing_obj=create_missing_obj, create_sub_obj=create_sub_obj,
): ):
log.debug(cont_edu_cert_person_obj_up_result) log.debug(cont_edu_cert_person_obj_up_result)

View File

@@ -75,7 +75,7 @@ async def patch_contact_obj(
async def patch_contact_json( async def patch_contact_json(
contact_obj: Contact_Base, contact_obj: Contact_Base,
contact_id: str = Query(..., min_length=1, max_length=22), contact_id: str = Query(..., min_length=1, max_length=22),
create_missing_obj: bool = False, create_sub_obj: bool = False,
x_account_id: Optional[str] = Header(..., ), x_account_id: Optional[str] = Header(..., ),
return_obj: Optional[bool] = True, return_obj: Optional[bool] = True,
by_alias: Optional[bool] = True, by_alias: Optional[bool] = True,
@@ -95,7 +95,7 @@ async def patch_contact_json(
if contact_obj_up_result := update_contact_obj( if contact_obj_up_result := update_contact_obj(
contact_id=contact_id, contact_id=contact_id,
contact_obj_up=contact_obj, contact_obj_up=contact_obj,
create_missing_obj=create_missing_obj, create_sub_obj=create_sub_obj,
): ):
log.debug(contact_obj_up_result) log.debug(contact_obj_up_result)

View File

@@ -75,7 +75,7 @@ async def patch_event_obj(
async def patch_event_json( async def patch_event_json(
event_obj: Event_Base, event_obj: Event_Base,
event_id: str = Query(..., min_length=1, max_length=22), event_id: str = Query(..., min_length=1, max_length=22),
create_missing_obj: bool = False, create_sub_obj: bool = False,
x_account_id: Optional[str] = Header(..., ), x_account_id: Optional[str] = Header(..., ),
return_obj: Optional[bool] = True, return_obj: Optional[bool] = True,
by_alias: Optional[bool] = True, by_alias: Optional[bool] = True,
@@ -95,7 +95,7 @@ async def patch_event_json(
if event_obj_up_result := update_event_obj( if event_obj_up_result := update_event_obj(
event_id=event_id, event_id=event_id,
event_obj_up=event_obj, event_obj_up=event_obj,
create_missing_obj=create_missing_obj, create_sub_obj=create_sub_obj,
): ):
log.debug(event_obj_up_result) log.debug(event_obj_up_result)

View File

@@ -308,7 +308,7 @@ async def post_event_person_new(
async def patch_event_person_json( async def patch_event_person_json(
event_person_obj: Event_Person_Base, event_person_obj: Event_Person_Base,
event_person_id: str = Query(..., min_length=1, max_length=22), event_person_id: str = Query(..., min_length=1, max_length=22),
create_missing_obj: bool = False, create_sub_obj: bool = False,
x_account_id: Optional[str] = Header(..., ), x_account_id: Optional[str] = Header(..., ),
return_obj: Optional[bool] = True, return_obj: Optional[bool] = True,
by_alias: Optional[bool] = True, by_alias: Optional[bool] = True,
@@ -328,7 +328,7 @@ async def patch_event_person_json(
if event_person_obj_up_result := update_event_person_obj( if event_person_obj_up_result := update_event_person_obj(
event_person_id=event_person_id, event_person_id=event_person_id,
event_person_obj_up=event_person_obj, event_person_obj_up=event_person_obj,
create_missing_obj=create_missing_obj, create_sub_obj=create_sub_obj,
): ):
log.debug(event_person_obj_up_result) log.debug(event_person_obj_up_result)

View File

@@ -75,7 +75,7 @@ async def patch_event_presentation_obj(
async def patch_event_presentation_json( async def patch_event_presentation_json(
event_presentation_obj: Event_Presentation_Base, event_presentation_obj: Event_Presentation_Base,
event_presentation_id: str = Query(..., min_length=1, max_length=22), event_presentation_id: str = Query(..., min_length=1, max_length=22),
create_missing_obj: bool = False, create_sub_obj: bool = False,
x_account_id: Optional[str] = Header(..., ), x_account_id: Optional[str] = Header(..., ),
return_obj: Optional[bool] = True, return_obj: Optional[bool] = True,
by_alias: Optional[bool] = True, by_alias: Optional[bool] = True,
@@ -95,7 +95,7 @@ async def patch_event_presentation_json(
if event_presentation_obj_up_result := update_event_presentation_obj( if event_presentation_obj_up_result := update_event_presentation_obj(
event_presentation_id=event_presentation_id, event_presentation_id=event_presentation_id,
event_presentation_obj_up=event_presentation_obj, event_presentation_obj_up=event_presentation_obj,
create_missing_obj=create_missing_obj, create_sub_obj=create_sub_obj,
): ):
log.debug(event_presentation_obj_up_result) log.debug(event_presentation_obj_up_result)

View File

@@ -75,7 +75,7 @@ async def patch_event_presenter_obj(
async def patch_event_presenter_json( async def patch_event_presenter_json(
event_presenter_obj: Event_Presenter_Base, event_presenter_obj: Event_Presenter_Base,
event_presenter_id: str = Query(..., min_length=1, max_length=22), event_presenter_id: str = Query(..., min_length=1, max_length=22),
create_missing_obj: bool = False, create_sub_obj: bool = False,
x_account_id: Optional[str] = Header(..., ), x_account_id: Optional[str] = Header(..., ),
return_obj: Optional[bool] = True, return_obj: Optional[bool] = True,
by_alias: Optional[bool] = True, by_alias: Optional[bool] = True,
@@ -95,7 +95,7 @@ async def patch_event_presenter_json(
if event_presenter_obj_up_result := update_event_presenter_obj( if event_presenter_obj_up_result := update_event_presenter_obj(
event_presenter_id=event_presenter_id, event_presenter_id=event_presenter_id,
event_presenter_obj_up=event_presenter_obj, event_presenter_obj_up=event_presenter_obj,
create_missing_obj=create_missing_obj, create_sub_obj=create_sub_obj,
): ):
log.debug(event_presenter_obj_up_result) log.debug(event_presenter_obj_up_result)

View File

@@ -173,7 +173,7 @@ async def patch_event_session_obj(
async def patch_event_session_json( async def patch_event_session_json(
event_session_obj: Event_Session_Base, event_session_obj: Event_Session_Base,
event_session_id: str = Query(..., min_length=1, max_length=22), event_session_id: str = Query(..., min_length=1, max_length=22),
create_missing_obj: bool = False, create_sub_obj: bool = False,
x_account_id: Optional[str] = Header(..., ), x_account_id: Optional[str] = Header(..., ),
return_obj: Optional[bool] = True, return_obj: Optional[bool] = True,
by_alias: Optional[bool] = True, by_alias: Optional[bool] = True,
@@ -193,7 +193,7 @@ async def patch_event_session_json(
if event_session_obj_up_result := update_event_session_obj( if event_session_obj_up_result := update_event_session_obj(
event_session_id=event_session_id, event_session_id=event_session_id,
event_session_obj_up=event_session_obj, event_session_obj_up=event_session_obj,
create_missing_obj=create_missing_obj, create_sub_obj=create_sub_obj,
): ):
log.debug(event_session_obj_up_result) log.debug(event_session_obj_up_result)

View File

@@ -76,7 +76,7 @@ async def patch_organization_obj(
async def post_organization_json( async def post_organization_json(
organization_obj: Organization_Base, organization_obj: Organization_Base,
# organization_id: str = Query(..., min_length=1, max_length=22), # organization_id: str = Query(..., min_length=1, max_length=22),
# create_missing_obj: bool = False, # create_sub_obj: bool = False,
process_contact: bool = False, process_contact: bool = False,
x_account_id: Optional[str] = Header(..., ), x_account_id: Optional[str] = Header(..., ),
return_obj: Optional[bool] = True, return_obj: Optional[bool] = True,

View File

@@ -116,6 +116,54 @@ async def post_person_obj_new_v3(
# ### BEGIN ### API Person ### post_person_obj_new_v3() ### # ### BEGIN ### API Person ### post_person_obj_new_v3() ###
# ### BEGIN ### API Person ### patch_person_obj_exist_v3() ###
# Updated 2021-08-24
@router.patch('/{person_id}/exist_v3', response_model=Resp_Body_Base)
async def patch_person_obj_exist_v3(
person_obj: Person_Base,
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 person_id := redis_lookup_id_random(record_id_random=person_id, table_name='person'): pass
else: return mk_resp(data=None, status_code=404)
if update_person_obj_result := update_person_obj_v3(
person_id = person_id,
person_obj_exist = 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_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_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 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 Person ### patch_person_obj_exist_v3() ###
# ### BEGIN ### API Person ### post_person_json() ### # ### BEGIN ### API Person ### post_person_json() ###
@@ -124,7 +172,7 @@ async def post_person_obj_new_v3(
async def post_person_json( async def post_person_json(
person_obj: Person_Base, person_obj: Person_Base,
# person_id: str = Query(..., min_length=1, max_length=22), # person_id: str = Query(..., min_length=1, max_length=22),
# create_missing_obj: bool = False, # create_sub_obj: bool = False,
process_contact: bool = False, process_contact: bool = False,
process_organization: bool = False, process_organization: bool = False,
x_account_id: Optional[str] = Header(..., ), x_account_id: Optional[str] = Header(..., ),