Code clean up. Work on event session and file counts for event models
This commit is contained in:
@@ -23,6 +23,8 @@ from app.models.event_presentation_models import Event_Presentation_Base
|
||||
def load_event_presentation_obj(
|
||||
event_presentation_id: int|str,
|
||||
enabled: str = 'enabled', # enabled, disabled, all
|
||||
hidden: str = 'not_hidden', # hidden, not_hidden, all
|
||||
inc_file_count: bool = False, # NOTE: file counts are from separate views
|
||||
limit: int = 1000,
|
||||
by_alias: bool = True,
|
||||
exclude_unset: bool = True,
|
||||
@@ -54,8 +56,13 @@ def load_event_presentation_obj(
|
||||
if event_presentation_id := redis_lookup_id_random(record_id_random=event_presentation_id, table_name='event_presentation'): pass
|
||||
else: return False
|
||||
|
||||
if event_presentation_rec := sql_select(table_name='v_event_presentation', record_id=event_presentation_id): pass
|
||||
else: return False
|
||||
if inc_file_count:
|
||||
log.info('Using view with file count')
|
||||
if event_presentation_rec := sql_select(table_name='v_event_presentation_w_file_count', record_id=event_presentation_id): pass
|
||||
else: return False
|
||||
else:
|
||||
if event_presentation_rec := sql_select(table_name='v_event_presentation', record_id=event_presentation_id): pass
|
||||
else: return False
|
||||
|
||||
# log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(event_presentation_rec)
|
||||
@@ -125,6 +132,10 @@ def load_event_presentation_obj(
|
||||
if event_presenter_obj := load_event_presenter_obj(
|
||||
event_presenter_id = event_presenter_id,
|
||||
enabled = enabled,
|
||||
# review = review,
|
||||
# approved = approved,
|
||||
hidden = hidden,
|
||||
inc_file_count = inc_file_count,
|
||||
inc_address = inc_address,
|
||||
inc_contact = inc_contact,
|
||||
inc_event_abstract_list = inc_event_abstract_list,
|
||||
|
||||
@@ -19,6 +19,8 @@ from app.models.event_presenter_models import Event_Presenter_Base
|
||||
def load_event_presenter_obj(
|
||||
event_presenter_id: int|str,
|
||||
enabled: str = 'enabled', # enabled, disabled, all
|
||||
hidden: str = 'not_hidden', # hidden, not_hidden, all
|
||||
inc_file_count: bool = False, # NOTE: file counts are from separate views
|
||||
limit: int = 1000,
|
||||
by_alias: bool = True,
|
||||
exclude_unset: bool = True,
|
||||
@@ -48,8 +50,13 @@ def load_event_presenter_obj(
|
||||
if event_presenter_id := redis_lookup_id_random(record_id_random=event_presenter_id, table_name='event_presenter'): pass
|
||||
else: return False
|
||||
|
||||
if event_presenter_rec := sql_select(table_name='v_event_presenter', record_id=event_presenter_id): pass
|
||||
else: return False
|
||||
if inc_file_count:
|
||||
log.info('Using view with file count')
|
||||
if event_presenter_rec := sql_select(table_name='v_event_presenter_w_file_count', record_id=event_presenter_id): pass
|
||||
else: return False
|
||||
else:
|
||||
if event_presenter_rec := sql_select(table_name='v_event_presenter', record_id=event_presenter_id): pass
|
||||
else: return False
|
||||
|
||||
# log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(event_presenter_rec)
|
||||
|
||||
@@ -27,6 +27,8 @@ def load_event_session_obj(
|
||||
exclude_unset: bool = True,
|
||||
model_as_dict: bool = False,
|
||||
enabled: str = 'enabled', # enabled, disabled, all
|
||||
hidden: str = 'not_hidden', # hidden, not_hidden, all
|
||||
inc_file_count: bool = False, # NOTE: file counts are from separate views
|
||||
event_file_file_purpose_id: int = None,
|
||||
event_file_file_purpose: str = None,
|
||||
event_file_priority: bool = None,
|
||||
@@ -57,9 +59,15 @@ def load_event_session_obj(
|
||||
if event_session_id := redis_lookup_id_random(record_id_random=event_session_id, table_name='event_session'): pass
|
||||
else: return False
|
||||
|
||||
if event_session_rec := sql_select(table_name='v_event_session', record_id=event_session_id): pass
|
||||
if inc_file_count:
|
||||
log.info('Using view with file count')
|
||||
if event_session_rec := sql_select(table_name='v_event_session_w_file_count', record_id=event_session_id): pass
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
if event_session_rec := sql_select(table_name='v_event_session', record_id=event_session_id): pass
|
||||
else:
|
||||
return False
|
||||
|
||||
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(event_session_rec)
|
||||
@@ -184,6 +192,10 @@ def load_event_session_obj(
|
||||
if event_presentation_obj := load_event_presentation_obj(
|
||||
event_presentation_id = event_presentation_id,
|
||||
enabled = enabled,
|
||||
# review = review,
|
||||
# approved = approved,
|
||||
hidden = hidden,
|
||||
inc_file_count = inc_file_count,
|
||||
inc_address = inc_address,
|
||||
inc_contact = inc_contact,
|
||||
inc_event_abstract_list = inc_event_abstract_list,
|
||||
@@ -250,6 +262,7 @@ def get_event_session_rec_list(
|
||||
event_id: str,
|
||||
review: str = 'ready', # ready, not_ready, all
|
||||
approved: str = 'approved', # approved, not_approved, all
|
||||
hidden: str = 'hidden', # hidden, not_hidden, all
|
||||
enabled: str = 'enabled', # enabled, disabled, all
|
||||
limit: int = 100,
|
||||
) -> list|bool:
|
||||
@@ -284,6 +297,16 @@ def get_event_session_rec_list(
|
||||
elif approved == 'all':
|
||||
sql_approved = ''
|
||||
|
||||
if hidden in ['hidden', 'not_hidden', 'all']:
|
||||
if hidden == 'hidden':
|
||||
data['hidden'] = True
|
||||
sql_hidden = f'AND `event_session`.hidden = :hidden'
|
||||
elif hidden == 'not_hidden':
|
||||
data['hidden'] = False
|
||||
sql_hidden = f'AND `event_session`.hidden = :hidden'
|
||||
elif hidden == 'all':
|
||||
sql_hidden = ''
|
||||
|
||||
if enabled in ['enabled', 'disabled', 'all']:
|
||||
if enabled == 'enabled':
|
||||
data['enable'] = True
|
||||
@@ -307,6 +330,7 @@ def get_event_session_rec_list(
|
||||
{sql_where_event_id}
|
||||
{sql_review}
|
||||
{sql_approved}
|
||||
{sql_hidden}
|
||||
{sql_enabled}
|
||||
ORDER BY `event_session`.created_on DESC, `event_session`.updated_on DESC
|
||||
{sql_limit};
|
||||
|
||||
@@ -37,6 +37,8 @@ class Event_Location_Base(BaseModel):
|
||||
name: Optional[str]
|
||||
description: Optional[str]
|
||||
|
||||
file_count: Optional[int]
|
||||
|
||||
enable: Optional[bool]
|
||||
enable_from: Optional[datetime.datetime] = None
|
||||
enable_to: Optional[datetime.datetime] = None
|
||||
|
||||
@@ -114,6 +114,8 @@ class Event_Base(BaseModel):
|
||||
|
||||
# access_key: Optional[str] # Maybe use in the future?
|
||||
|
||||
file_count: Optional[int]
|
||||
|
||||
enable: Optional[bool] # Also in Event_Cfg_Base model
|
||||
enable_from: Optional[datetime.datetime] = None
|
||||
enable_to: Optional[datetime.datetime] = None
|
||||
|
||||
@@ -55,6 +55,8 @@ class Event_Person_Base(BaseModel):
|
||||
user_id_random: Optional[str]
|
||||
user_id: Optional[int]
|
||||
|
||||
file_count: Optional[int]
|
||||
|
||||
priority: Optional[bool]
|
||||
sort: Optional[int]
|
||||
group: Optional[str]
|
||||
|
||||
@@ -60,6 +60,8 @@ class Event_Presentation_Base(BaseModel):
|
||||
start_datetime: Optional[datetime.datetime]
|
||||
end_datetime: Optional[datetime.datetime]
|
||||
|
||||
file_count: Optional[int]
|
||||
|
||||
enable: Optional[bool]
|
||||
enable_from: Optional[datetime.datetime] = None
|
||||
enable_to: Optional[datetime.datetime] = None
|
||||
|
||||
@@ -100,6 +100,8 @@ class Event_Presenter_Base(BaseModel):
|
||||
|
||||
role: Optional[str]
|
||||
|
||||
file_count: Optional[int]
|
||||
|
||||
enable: Optional[bool]
|
||||
enable_from: Optional[datetime.datetime] = None
|
||||
enable_to: Optional[datetime.datetime] = None
|
||||
|
||||
@@ -77,6 +77,8 @@ class Event_Session_Base(BaseModel):
|
||||
presentation_file_path: Optional[str]
|
||||
presentation_file_size: Optional[str]
|
||||
|
||||
file_count: Optional[int]
|
||||
|
||||
status: Optional[int]
|
||||
review: Optional[bool]
|
||||
approve: Optional[bool]
|
||||
|
||||
@@ -462,10 +462,10 @@ async def get_event_session_obj_li(
|
||||
|
||||
|
||||
# ### BEGIN ### API Event Session ### get_event_session_obj() ###
|
||||
# Working well as of 2021-06-04. Using as a template for other routes.
|
||||
# Updated 2021-09-28
|
||||
@router.get('/event/session/{event_session_id}', response_model=Resp_Body_Base)
|
||||
async def get_event_session_obj(
|
||||
event_session_id: str = Query(..., min_length=1, max_length=22),
|
||||
event_session_id: str = Query(..., min_length=11, max_length=22),
|
||||
enabled: str = 'enabled', # For now this covers any included objects or object lists
|
||||
limit: int = 500, # For now this covers any included objects or object lists
|
||||
inc_address: bool = False, # Under contact
|
||||
@@ -486,21 +486,28 @@ async def get_event_session_obj(
|
||||
inc_poc_event_person: bool = False,
|
||||
inc_person: bool = False, # Under event_person
|
||||
inc_user: bool = False, # Under event_person
|
||||
review: str = 'ready', # ready, not_ready, all
|
||||
approved: str = 'approved', # approved, not_approved, all
|
||||
hidden: str = 'not_hidden', # hidden, not_hidden, all
|
||||
inc_file_count: bool = False, # NOTE: file counts are from separate views
|
||||
x_account_id: str = Header(...),
|
||||
by_alias: Optional[bool] = True,
|
||||
exclude_unset: Optional[bool] = True,
|
||||
response: Response = Response,
|
||||
):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if event_session_id := redis_lookup_id_random(record_id_random=event_session_id, table_name='event_session'): pass
|
||||
else:
|
||||
return mk_resp(data=None, status_code=404, response=response)
|
||||
else: return mk_resp(data=None, status_code=404, response=response)
|
||||
|
||||
if event_session_obj := load_event_session_obj(
|
||||
event_session_id = event_session_id,
|
||||
enabled = enabled,
|
||||
# review = review,
|
||||
# approved = approved,
|
||||
hidden = hidden,
|
||||
inc_file_count = inc_file_count,
|
||||
limit = limit,
|
||||
inc_address = inc_address,
|
||||
inc_contact = inc_contact,
|
||||
@@ -550,6 +557,8 @@ async def get_event_event_session_obj_li(
|
||||
inc_poc_event_person: bool = False,
|
||||
review: str = 'ready', # ready, not_ready, all
|
||||
approved: str = 'approved', # approved, not_approved, all
|
||||
hidden: str = 'not_hidden', # hidden, not_hidden, all
|
||||
inc_file_count: bool = False, # NOTE: file counts are from separate views
|
||||
x_account_id: str = Header(...),
|
||||
by_alias: Optional[bool] = True,
|
||||
exclude_unset: Optional[bool] = True,
|
||||
@@ -566,6 +575,7 @@ async def get_event_event_session_obj_li(
|
||||
event_id = event_id,
|
||||
review = review, # ready, not_ready, all
|
||||
approved = approved, # approve(d), not_approved, all
|
||||
hidden = hidden, # hidden, not_hidden, all
|
||||
enabled = enabled,
|
||||
limit = limit,
|
||||
):
|
||||
@@ -574,6 +584,10 @@ async def get_event_event_session_obj_li(
|
||||
if load_event_session_result := load_event_session_obj(
|
||||
event_session_id = event_session_rec.get('event_session_id', None),
|
||||
enabled = enabled,
|
||||
# review = review,
|
||||
# approved = approved,
|
||||
hidden = hidden,
|
||||
inc_file_count = inc_file_count,
|
||||
limit = limit,
|
||||
inc_event_file_list = inc_event_file_list,
|
||||
inc_event_presentation_list = inc_event_presentation_list,
|
||||
|
||||
Reference in New Issue
Block a user