A lot of changes related to person and membership and event

This commit is contained in:
Scott Idem
2021-07-12 17:47:16 -04:00
parent 49805f48c9
commit 9d1b520718
8 changed files with 265 additions and 47 deletions

View File

@@ -215,8 +215,9 @@ def load_account_obj(
# Updated 2021-06-17
if inc_event_list:
if event_rec_list_result := get_event_rec_list(
for_obj_type = 'account',
for_obj_id = account_id,
# for_obj_type = 'account',
# for_obj_id = account_id,
account_id = account_id,
limit = limit,
enabled = enabled,
):

View File

@@ -249,38 +249,47 @@ def load_event_obj(
# ### BEGIN ### API Event Methods ### get_event_rec_list() ###
def get_event_rec_list(
for_obj_type: str,
for_obj_id: str,
account_id: str = None,
organization_id: str = None,
person_id: str = None,
user_id: str = None,
limit: int = 1000,
enabled: str = 'enabled', # enabled, disabled, all
conference: bool = False,
conference: bool = False, # If it is a conference then organization, person, and user are queried as participants (not the owner/organizer)
) -> list|bool:
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
if for_obj_id := redis_lookup_id_random(record_id_random=for_obj_id, table_name=for_obj_type): pass
if account_id or organization_id or person_id or user_id: pass
else: return False
data = {}
data[f'{for_obj_type}_id'] = for_obj_id
# data['for_obj_type'] = for_obj_type
sql_obj_type_id = f'`tbl`.{for_obj_type}_id = :{for_obj_type}_id'
if enabled in ['enabled', 'disabled', 'all']:
if enabled == 'enabled':
data['enable'] = True
sql_enabled = f'AND `tbl`.enable = :enable'
elif enabled == 'disabled':
data['enable'] = False
sql_enabled = f'AND `tbl`.enable = :enable'
elif enabled == 'all':
sql_enabled = ''
if account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'): pass
else: pass
if organization_id := redis_lookup_id_random(record_id_random=organization_id, table_name='organization'): pass
else: pass
if person_id := redis_lookup_id_random(record_id_random=person_id, table_name='person'): pass
else: pass
if user_id := redis_lookup_id_random(record_id_random=user_id, table_name='user'): pass
else: pass
data = {}
data['account_id'] = account_id
data['organization_id'] = organization_id
data['person_id'] = person_id
data['user_id'] = user_id
data['conference'] = conference
if conference:
data['conference'] = True
sql_conference = f'AND `tbl`.conference = :conference'
sql_conference = f'AND `event`.conference = :conference'
else:
data['conference'] = False
sql_conference = f'AND `tbl`.conference = :conference'
sql_conference = f'AND `event`.conference = :conference'
if limit:
data['limit'] = limit
@@ -288,16 +297,70 @@ def get_event_rec_list(
else:
sql_limit = ''
sql = f"""
SELECT `tbl`.id AS 'event_id', `tbl`.id_random AS 'event_id_random'
FROM `event` AS `tbl`
WHERE
{sql_obj_type_id}
{sql_enabled}
{sql_conference}
ORDER BY `tbl`.created_on DESC, `tbl`.updated_on DESC
{sql_limit};
"""
if account_id or not conference and (organization_id or person_id or user_id):
if account_id:
sql_where_type_id = f'`event`.account_id = :account_id'
elif organization_id:
sql_where_type_id = f'`event`.organization_id = :organization_id'
elif person_id:
sql_where_type_id = f'`event`.person_id = :person_id'
elif user_id:
sql_where_type_id = f'`event`.user_id = :user_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:
sql_enabled = f'AND `event`.enable = :enable'
sql = f"""
SELECT `event`.id AS 'event_id', `event`.id_random AS 'event_id_random'
FROM `event` AS `event`
WHERE
{sql_where_type_id}
{sql_enabled}
{sql_conference}
ORDER BY `event`.created_on DESC, `event`.updated_on DESC
{sql_limit};
"""
elif conference and (organization_id or person_id or user_id): # If it is a conference then organization, person, and user are queried as participants (not the owner/organizer)
if organization_id: # Not sure if this makes sense?
sql_inner_join = f'`organization` ON event_person.organization_id = organization.id AND organization.id AND organization.id = :organization_id'
elif person_id:
sql_inner_join = f'`person` ON event_person.person_id = person.id AND person.id AND person.id = :person_id'
elif user_id:
sql_inner_join = f'`user` ON event_person.user_id = user.id AND user.id AND user.id = :user_id'
if enabled in ['enabled', 'disabled', 'all']:
if enabled == 'enabled':
data['enable'] = True
sql_enabled = f'`event`.enable = :enable'
elif enabled == 'disabled':
data['enable'] = False
sql_enabled = f'`event`.enable = :enable'
elif enabled == 'all':
sql_enabled = ''
else:
sql_enabled = f'`event`.enable = :enable'
sql = f"""
SELECT `event`.id AS 'event_id', `event`.id_random AS 'event_id_random'
FROM `event` AS `event`
INNER JOIN `event_person` ON event.id = event_person.event_id
/*INNER JOIN `person` ON event_person.person_id = person.id*/
INNER JOIN {sql_inner_join}
WHERE
{sql_enabled}
{sql_conference}
ORDER BY `event`.created_on DESC, `event`.updated_on DESC
{sql_limit};
"""
if event_rec_li_result := sql_select(data=data, sql=sql, as_list=True):
event_rec_li = event_rec_li_result