Clean up and testing. Starting to mark things as deprecated.
This commit is contained in:
@@ -529,7 +529,7 @@ def load_account_obj(
|
||||
account_obj.site_list = site_result_list
|
||||
else: account_obj.site_list = []
|
||||
|
||||
# Updated 2021-06-17
|
||||
# Updated 2021-12-08
|
||||
if inc_user_list:
|
||||
if user_rec_list_result := get_user_rec_list(
|
||||
account_id = account_id,
|
||||
@@ -549,14 +549,10 @@ def load_account_obj(
|
||||
inc_address = inc_address,
|
||||
inc_contact = inc_contact,
|
||||
inc_event_list = inc_event_list,
|
||||
inc_journal_list = inc_journal_list,
|
||||
inc_membership_person = inc_membership_person,
|
||||
inc_order_list = inc_order_list,
|
||||
inc_order_cart_list = inc_order_cart_list,
|
||||
inc_organization = inc_organization,
|
||||
# inc_organization = inc_organization,
|
||||
inc_person = inc_person,
|
||||
inc_post_list = inc_post_list,
|
||||
inc_post_comment_list = inc_post_comment_list,
|
||||
inc_user_role_list = inc_user_role_list,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -168,6 +168,7 @@ def load_event_person_obj(
|
||||
|
||||
# Updated 2021-08-17
|
||||
if inc_user:
|
||||
log.warning(f'This is being deprecated? load_event_person_obj() inc_user')
|
||||
log.info('Need to include user data...')
|
||||
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
from app.methods.user_methods import load_user_obj
|
||||
|
||||
@@ -240,6 +240,7 @@ def load_membership_person_obj(
|
||||
|
||||
# Updated 2021-06-18
|
||||
if inc_user:
|
||||
log.warning(f'This is being deprecated? load_membership_person_obj() inc_user')
|
||||
user_id = membership_person_rec.get('user_id', None)
|
||||
if user_result := load_user_obj(
|
||||
user_id = user_id,
|
||||
|
||||
@@ -256,6 +256,7 @@ def load_order_obj(
|
||||
|
||||
# Updated 2021-06-22
|
||||
if inc_user:
|
||||
log.warning(f'This is being deprecated? load_order_obj() inc_user')
|
||||
from app.methods.user_methods import load_user_obj
|
||||
if user_result := load_user_obj(
|
||||
user_id = order_rec.get('user_id', None),
|
||||
|
||||
@@ -84,6 +84,7 @@ def load_post_comment_obj(
|
||||
|
||||
# Updated 2021-06-18
|
||||
if inc_user:
|
||||
log.warning(f'This is being deprecated? load_post_comment_obj() inc_user')
|
||||
# from app.methods.user_methods import load_user_obj
|
||||
# user_result = load_user_obj(
|
||||
# user_id = post_comment_rec.get('user_id', None),
|
||||
|
||||
@@ -111,6 +111,7 @@ def load_post_obj(
|
||||
|
||||
# Updated 2021-06-18
|
||||
if inc_user:
|
||||
log.warning(f'This is being deprecated? load_post_obj() inc_user')
|
||||
# from app.methods.user_methods import load_user_obj
|
||||
# user_result = load_user_obj(
|
||||
# user_id = post_rec.get('user_id', None),
|
||||
|
||||
@@ -1,128 +0,0 @@
|
||||
from __future__ import annotations
|
||||
import datetime
|
||||
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, validator
|
||||
|
||||
from app.db_sql import redis_lookup_id_random, sql_insert, sql_select, sql_update
|
||||
from app.lib_general import log, logging
|
||||
|
||||
from app.methods.contact_methods import load_contact_obj
|
||||
# from app.methods.event_methods import load_event_obj_list
|
||||
from app.methods.organization_methods import load_organization_obj
|
||||
# from app.methods.person_methods import load_person_obj
|
||||
# from app.methods.post_methods import load_post_obj_list
|
||||
|
||||
from app.models.user_models import User_Base, User_New_Base, User_Out_Base
|
||||
from app.models.user_role_models import User_Role_Base
|
||||
|
||||
|
||||
# ### BEGIN ### API User Methods ### load_user_obj() ###
|
||||
def load_user_obj(
|
||||
user_id: int|str,
|
||||
limit: int = 1000,
|
||||
model_as_dict: bool = False,
|
||||
enabled: str = 'enabled', # enabled, disabled, all
|
||||
inc_address: bool = False,
|
||||
inc_contact: bool = False,
|
||||
inc_event_list: bool = False,
|
||||
inc_journal_list: bool = False,
|
||||
inc_membership: bool = False,
|
||||
inc_order_list: bool = False,
|
||||
inc_order_cart_list: bool = False,
|
||||
inc_organization: bool = False,
|
||||
inc_person: bool = False,
|
||||
inc_post_list: bool = False,
|
||||
inc_post_comment_list: bool = False,
|
||||
inc_user_role_list: bool = False,
|
||||
) -> User_Out_Base|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
|
||||
|
||||
if user_rec := sql_select(table_name='v_user', record_id=user_id): pass
|
||||
else: return False
|
||||
|
||||
#log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(user_rec)
|
||||
|
||||
try:
|
||||
user_obj = User_Out_Base(**user_rec)
|
||||
log.debug(user_obj)
|
||||
except ValidationError as e:
|
||||
log.error(e.json())
|
||||
return False
|
||||
|
||||
if inc_contact:
|
||||
contact_id = user_rec.get('contact_id', None)
|
||||
if contact_obj_result := load_contact_obj(contact_id=contact_id):
|
||||
contact_obj = contact_obj_result
|
||||
user_rec['contact'] = contact_obj
|
||||
log.debug(user_rec)
|
||||
user_obj.contact = contact_obj
|
||||
else:
|
||||
user_rec['contact'] = None
|
||||
user_obj.contact = None
|
||||
|
||||
if inc_event_list:
|
||||
if event_dict_list := load_event_obj_list(
|
||||
user_id = user_id,
|
||||
limit = limit,
|
||||
model_as_dict = model_as_dict,
|
||||
enabled = enabled,
|
||||
):
|
||||
user_obj.event_list = event_dict_list
|
||||
else: user_obj.event_list = None
|
||||
|
||||
|
||||
if inc_organization:
|
||||
organization_id = user_rec.get('organization_id', None)
|
||||
if organization_obj_result := load_organization_obj(organization_id=organization_id):
|
||||
organization_obj = organization_obj_result
|
||||
user_rec['organization'] = organization_obj
|
||||
log.debug(user_rec)
|
||||
user_obj.organization = organization_obj
|
||||
else:
|
||||
user_rec['organization'] = None
|
||||
user_obj.organization = None
|
||||
|
||||
# if inc_person:
|
||||
# person_id = user_rec.get('person_id', None)
|
||||
# if person_obj_result := load_person_obj(person_id=person_id):
|
||||
# person_obj = person_obj_result
|
||||
# user_rec['person'] = person_obj
|
||||
# log.debug(user_rec)
|
||||
# user_obj.person = person_obj
|
||||
# else:
|
||||
# user_rec['person'] = None
|
||||
# user_obj.person = None
|
||||
|
||||
if inc_post_list:
|
||||
if post_dict_list := load_post_obj_list(
|
||||
user_id = user_id,
|
||||
limit = limit,
|
||||
model_as_dict = model_as_dict,
|
||||
enabled = enabled,
|
||||
):
|
||||
user_obj.post_list = post_dict_list
|
||||
else: user_obj.post_list = None
|
||||
|
||||
|
||||
# NOTE: Including user roles should probably be reviewed
|
||||
if inc_user_role_list:
|
||||
if role_rec_li := sql_select(table_name='v_user_role_detail', field_name='user_id', field_value=user_id, as_list=True):
|
||||
user_rec['role_list'] = role_rec_li
|
||||
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(role_rec_li)
|
||||
user_obj.role_list = role_rec_li
|
||||
else:
|
||||
user_rec['role_list'] = None
|
||||
user_obj.role_list = None
|
||||
|
||||
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(user_rec)
|
||||
|
||||
return user_obj
|
||||
# ### END ### API User Methods ### load_user_obj() ###
|
||||
@@ -249,22 +249,22 @@ def load_user_obj(
|
||||
model_as_dict: bool = False,
|
||||
enabled: str = 'enabled', # enabled, disabled, all
|
||||
inc_address: bool = False,
|
||||
# inc_archive_list: bool = False,
|
||||
# inc_archive_list: bool = False, # deprecated
|
||||
inc_contact: bool = False,
|
||||
inc_event_list: bool = False,
|
||||
# inc_hosted_file_list: bool = False,
|
||||
inc_journal_list: bool = False,
|
||||
inc_journal_entry_list: bool = False,
|
||||
inc_membership_person: bool = False,
|
||||
inc_order_cfg: bool = False,
|
||||
inc_order_line_list: bool = False,
|
||||
inc_order_list: bool = False,
|
||||
inc_order_cart_list: bool = False,
|
||||
inc_organization: bool = False,
|
||||
inc_event_list: bool = False, # deprecated
|
||||
# inc_hosted_file_list: bool = False, # deprecated
|
||||
# inc_journal_list: bool = False, # deprecated
|
||||
# inc_journal_entry_list: bool = False, # deprecated
|
||||
# inc_membership_person: bool = False, # deprecated
|
||||
inc_order_cfg: bool = False, # deprecated
|
||||
inc_order_line_list: bool = False, # deprecated
|
||||
inc_order_list: bool = False, # deprecated
|
||||
inc_order_cart_list: bool = False, # deprecated
|
||||
inc_organization: bool = False, # deprecated
|
||||
inc_person: bool = False,
|
||||
# inc_person_list: bool = False,
|
||||
inc_post_list: bool = False,
|
||||
inc_post_comment_list: bool = False,
|
||||
# inc_person_list: bool = False, # deprecated
|
||||
# inc_post_list: bool = False, # deprecated
|
||||
# inc_post_comment_list: bool = False, # deprecated
|
||||
inc_user_role_list: bool = False,
|
||||
) -> User_Out_Base|dict|bool:
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
@@ -286,7 +286,8 @@ def load_user_obj(
|
||||
return False
|
||||
|
||||
# Updated 2021-06-18
|
||||
# if inc_contact:
|
||||
if inc_contact:
|
||||
log.warning(f'This is being deprecated? load_user_obj() inc_contact')
|
||||
# contact_id = user_rec.get('contact_id', None)
|
||||
# log.debug(contact_id)
|
||||
# if contact_result := load_contact_obj(
|
||||
@@ -302,6 +303,7 @@ def load_user_obj(
|
||||
# else: user_obj.contact = None
|
||||
|
||||
if inc_event_list:
|
||||
log.warning(f'This is being deprecated? load_user_obj() inc_event_list')
|
||||
from app.methods.event_methods import load_event_obj_list
|
||||
if event_dict_list := load_event_obj_list(
|
||||
user_id = user_id,
|
||||
@@ -314,6 +316,7 @@ def load_user_obj(
|
||||
|
||||
# Updated 2021-06-18
|
||||
if inc_order_list:
|
||||
log.warning(f'This is being deprecated? load_user_obj() inc_order_list')
|
||||
if order_rec_list_result := get_order_rec_list(
|
||||
for_obj_type = 'user',
|
||||
for_obj_id = user_id,
|
||||
@@ -340,6 +343,7 @@ def load_user_obj(
|
||||
|
||||
# Updated 2021-06-18
|
||||
if inc_organization:
|
||||
log.warning(f'This is being deprecated? load_user_obj() inc_organization')
|
||||
organization_id = user_rec.get('organization_id', None)
|
||||
log.debug(organization_id)
|
||||
if organization_result := load_organization_obj(
|
||||
@@ -373,30 +377,31 @@ def load_user_obj(
|
||||
log.debug(person_result)
|
||||
|
||||
# Updated 2021-06-18
|
||||
if inc_post_list:
|
||||
if post_rec_list_result := get_post_rec_list(
|
||||
for_obj_type = 'user',
|
||||
for_obj_id = user_id,
|
||||
limit = limit,
|
||||
enabled = enabled,
|
||||
):
|
||||
post_result_list = []
|
||||
for post_rec in post_rec_list_result:
|
||||
if load_post_result := load_post_obj(
|
||||
post_id = post_rec.get('post_id', None),
|
||||
limit = limit,
|
||||
by_alias = by_alias,
|
||||
exclude_unset = exclude_unset,
|
||||
model_as_dict = model_as_dict,
|
||||
enabled = enabled,
|
||||
inc_post_comment_list = inc_post_comment_list,
|
||||
inc_person = inc_person,
|
||||
# inc_user = inc_user,
|
||||
):
|
||||
post_result_list.append(load_post_result)
|
||||
else: post_result_list.append(None)
|
||||
user_obj.post_list = post_result_list
|
||||
else: user_obj.post_list = []
|
||||
# if inc_post_list:
|
||||
# log.warning(f'This is being deprecated? load_user_obj() inc_post_list')
|
||||
# if post_rec_list_result := get_post_rec_list(
|
||||
# for_obj_type = 'user',
|
||||
# for_obj_id = user_id,
|
||||
# limit = limit,
|
||||
# enabled = enabled,
|
||||
# ):
|
||||
# post_result_list = []
|
||||
# for post_rec in post_rec_list_result:
|
||||
# if load_post_result := load_post_obj(
|
||||
# post_id = post_rec.get('post_id', None),
|
||||
# limit = limit,
|
||||
# by_alias = by_alias,
|
||||
# exclude_unset = exclude_unset,
|
||||
# model_as_dict = model_as_dict,
|
||||
# enabled = enabled,
|
||||
# inc_post_comment_list = inc_post_comment_list,
|
||||
# inc_person = inc_person,
|
||||
# # inc_user = inc_user,
|
||||
# ):
|
||||
# post_result_list.append(load_post_result)
|
||||
# else: post_result_list.append(None)
|
||||
# user_obj.post_list = post_result_list
|
||||
# else: user_obj.post_list = []
|
||||
|
||||
# Updated 2021-06-25
|
||||
if inc_user_role_list:
|
||||
|
||||
Reference in New Issue
Block a user