Working on event person, registration, badge, session, presentation, and presenter create and update. _v3 things
This commit is contained in:
@@ -21,6 +21,7 @@ from app.models.user_models import User_Base, User_New_Base, User_Out_Base
|
||||
# ### BEGIN ### API User Methods ### create_user_obj() ###
|
||||
# NOTE: This will create a new user and also hash a new password string if given.
|
||||
# NOTE: This uses the User_New_Base model, not User_Base or User_Out_Base
|
||||
# Updated 2021-08-25
|
||||
# Reviewed and updated 2021-08-21
|
||||
# Reviewed and updated 2021-08-10
|
||||
def create_user_obj(
|
||||
@@ -33,8 +34,23 @@ def create_user_obj(
|
||||
log.setLevel(logging.DEBUG) # 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
|
||||
|
||||
log.debug(type(user_obj_new))
|
||||
if isinstance(user_obj_new, dict):
|
||||
user_obj_new['account_id'] = account_id
|
||||
try:
|
||||
user_obj_new = User_New_Base(**user_obj_new)
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(user_obj_new)
|
||||
except ValidationError as e:
|
||||
log.error(e.json())
|
||||
return False
|
||||
|
||||
user_obj_data = user_obj_new.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'contact', 'new_password', 'organization', 'person', 'created_on', 'updated_on'})
|
||||
log.debug(user_obj_data)
|
||||
user_obj_data['account_id'] = account_id
|
||||
|
||||
user_obj_data['password'] = user_obj_new.password # There has to be a better way to do this??? It thinks "password" is unset and so is excluded?
|
||||
log.debug(user_obj_data)
|
||||
@@ -101,10 +117,13 @@ def create_user_obj(
|
||||
|
||||
|
||||
# ### BEGIN ### API User Methods ### update_user_obj() ###
|
||||
# Updated 2021-08-25
|
||||
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,
|
||||
fail_any: bool = True, # 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.debug(locals())
|
||||
@@ -112,6 +131,16 @@ def update_user_obj(
|
||||
if user_id := redis_lookup_id_random(record_id_random=user_id, table_name='user'): pass
|
||||
else: return False
|
||||
|
||||
log.debug(type(user_obj_up))
|
||||
if isinstance(user_obj_up, dict):
|
||||
try:
|
||||
user_obj_up = User_Base(**user_obj_up)
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(user_obj_up)
|
||||
except ValidationError as e:
|
||||
log.error(e.json())
|
||||
return False
|
||||
|
||||
user_obj_up.id = user_id
|
||||
|
||||
log.debug(user_obj_up)
|
||||
|
||||
Reference in New Issue
Block a user