Clean up and working on user related models, methods, and routes.
This commit is contained in:
@@ -8,8 +8,9 @@ from app.db_sql import redis_lookup_id_random, sql_select
|
||||
from app.lib_general import log, logging
|
||||
|
||||
from app.methods.account_cfg_methods import load_account_cfg_obj
|
||||
from app.methods.archive_methods import load_archive_obj, load_archive_obj_list
|
||||
from app.methods.event_methods import load_event_obj
|
||||
from app.methods.archive_methods import load_archive_obj_list
|
||||
from app.methods.event_methods import load_event_obj_list
|
||||
from app.methods.post_methods import load_post_obj_list
|
||||
|
||||
from app.models.account_models import Account_Base
|
||||
from app.models.account_cfg_models import Account_Cfg_Base
|
||||
@@ -79,6 +80,8 @@ def load_account_obj(
|
||||
inc_person_list: bool = False, # Priority l2
|
||||
inc_post: bool = False,
|
||||
inc_post_list: bool = False, # Priority l1
|
||||
inc_post_comment: bool = False,
|
||||
inc_post_comment_list: bool = False,
|
||||
inc_product: bool = False,
|
||||
inc_product_list: bool = False, # Priority l3
|
||||
# inc_site: bool = False,
|
||||
@@ -121,11 +124,10 @@ def load_account_obj(
|
||||
limit = limit,
|
||||
model_as_dict = True,
|
||||
enabled = enabled,
|
||||
inc_archive_content_list = inc_archive_content_list
|
||||
inc_archive_content_list = inc_archive_content_list,
|
||||
):
|
||||
account_obj.archive_list = archive_dict_list
|
||||
else: account_obj.archive_list = None
|
||||
|
||||
else: account_obj.archive_list = []
|
||||
|
||||
# if inc_contact:
|
||||
# contact_id = account_rec.get('contact_id', None)
|
||||
@@ -156,75 +158,45 @@ def load_account_obj(
|
||||
# else: account_obj.organization = None
|
||||
|
||||
if inc_event_list:
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
if event_dict_list := load_event_obj_list(
|
||||
account_id = account_id,
|
||||
limit = limit,
|
||||
model_as_dict = True,
|
||||
enabled = enabled,
|
||||
# inc_location_address = inc_address,
|
||||
# inc_contact_1 = inc_contact,
|
||||
# inc_contact_2 = inc_contact,
|
||||
# inc_contact_3 = inc_contact,
|
||||
# inc_event_abstract_list = inc_event_abstract_list,
|
||||
# inc_event_badge_list = inc_event_badge_list,
|
||||
# inc_event_device_list = inc_event_device_list,
|
||||
inc_event_exhibit_list = inc_event_exhibit_list,
|
||||
inc_event_file_list = inc_event_file_list,
|
||||
inc_event_location_list = inc_event_location_list,
|
||||
inc_event_person_list = inc_event_person_list,
|
||||
inc_event_presentation_list = inc_event_presentation_list,
|
||||
inc_event_presenter_list = inc_event_presenter_list,
|
||||
inc_event_registration_list = inc_event_registration_list,
|
||||
inc_event_session_list = inc_event_session_list,
|
||||
inc_event_track_list = inc_event_track_list,
|
||||
# inc_person = inc_person,
|
||||
# inc_user = inc_user,
|
||||
):
|
||||
account_obj.event_list = event_dict_list
|
||||
else: account_obj.event_list = []
|
||||
|
||||
data = {}
|
||||
data['account_id'] = account_id
|
||||
|
||||
if enabled in ['enabled', 'disabled', 'all']:
|
||||
if enabled == 'enabled':
|
||||
data['enable'] = True
|
||||
sql_enabled = f'AND `event`.enable = :enable'
|
||||
elif enabled == 'disabled':
|
||||
data['enable'] = False
|
||||
sql_enabled = f'AND `event`.enable = :enable'
|
||||
elif enabled == 'all':
|
||||
sql_enabled = ''
|
||||
# else: event_obj['account'] = None
|
||||
|
||||
if limit:
|
||||
data['limit'] = limit
|
||||
sql_limit = f'LIMIT :limit'
|
||||
else:
|
||||
sql_limit = ''
|
||||
|
||||
sql = f"""
|
||||
SELECT `event`.id AS 'event_id', `event`.id_random AS 'event_id_random'
|
||||
FROM `event` AS `event`
|
||||
WHERE `event`.account_id = :account_id
|
||||
{sql_enabled}
|
||||
ORDER BY `event`.created_on DESC, `event`.updated_on DESC
|
||||
{sql_limit};
|
||||
"""
|
||||
|
||||
#log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
if event_rec_li_result := sql_select(data=data, sql=sql, as_list=True):
|
||||
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(event_rec_li_result)
|
||||
event_obj_li = []
|
||||
for event_rec in event_rec_li_result:
|
||||
event_id = event_rec.get('event_id', None)
|
||||
if event_obj := load_event_obj(
|
||||
event_id=event_id,
|
||||
enabled=enabled,
|
||||
# inc_location_address=inc_address,
|
||||
# inc_contact_1=inc_contact,
|
||||
# inc_contact_2=inc_contact,
|
||||
# inc_contact_3=inc_contact,
|
||||
# inc_event_abstract_list=inc_event_abstract_list,
|
||||
# inc_event_badge_list=inc_event_badge_list,
|
||||
# inc_event_device_list=inc_event_device_list,
|
||||
inc_event_exhibit_list=inc_event_exhibit_list,
|
||||
inc_event_file_list=inc_event_file_list,
|
||||
inc_event_location_list=inc_event_location_list,
|
||||
inc_event_person_list=inc_event_person_list,
|
||||
inc_event_presentation_list=inc_event_presentation_list,
|
||||
inc_event_presenter_list=inc_event_presenter_list,
|
||||
inc_event_registration_list=inc_event_registration_list,
|
||||
inc_event_session_list=inc_event_session_list,
|
||||
inc_event_track_list=inc_event_track_list,
|
||||
# inc_person=inc_person,
|
||||
# inc_user=inc_user
|
||||
):
|
||||
data = event_obj.dict(by_alias=True, exclude_unset=True)
|
||||
event_obj_li.append(data)
|
||||
log.debug(event_obj_li)
|
||||
account_obj.event_list = event_obj_li
|
||||
else:
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(event_rec_li_result)
|
||||
account_obj.event_list = []
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
if inc_post_list:
|
||||
if post_dict_list := load_post_obj_list(
|
||||
account_id = account_id,
|
||||
limit = limit,
|
||||
model_as_dict = True,
|
||||
enabled = enabled,
|
||||
inc_post_comment_list = inc_post_comment_list,
|
||||
inc_person = inc_person,
|
||||
inc_user = inc_user,
|
||||
):
|
||||
account_obj.post_list = post_dict_list
|
||||
else: account_obj.post_list = []
|
||||
|
||||
if model_as_dict:
|
||||
return account_obj.dict(by_alias=True, exclude_unset=True) # pylint: disable=no-member
|
||||
|
||||
Reference in New Issue
Block a user