Working on continuing education certs
This commit is contained in:
@@ -820,6 +820,14 @@ def lookup_id_random_pop(obj_data:dict):
|
|||||||
obj_data['contact_2_id'] = redis_lookup_id_random(record_id_random=obj_data['contact_2_id_random'], table_name='contact')
|
obj_data['contact_2_id'] = redis_lookup_id_random(record_id_random=obj_data['contact_2_id_random'], table_name='contact')
|
||||||
obj_data.pop('contact_2_id_random')
|
obj_data.pop('contact_2_id_random')
|
||||||
|
|
||||||
|
if 'cont_edu_cert_id_random' in obj_data:
|
||||||
|
obj_data['cont_edu_cert_id'] = redis_lookup_id_random(record_id_random=obj_data['cont_edu_cert_id_random'], table_name='cont_edu_cert')
|
||||||
|
obj_data.pop('cont_edu_cert_id_random')
|
||||||
|
|
||||||
|
if 'cont_edu_cert_person_id_random' in obj_data:
|
||||||
|
obj_data['cont_edu_cert_person_id'] = redis_lookup_id_random(record_id_random=obj_data['cont_edu_cert_person_id_random'], table_name='cont_edu_cert_person')
|
||||||
|
obj_data.pop('cont_edu_cert_person_id_random')
|
||||||
|
|
||||||
if 'event_id_random' in obj_data:
|
if 'event_id_random' in obj_data:
|
||||||
obj_data['event_id'] = redis_lookup_id_random(record_id_random=obj_data.get('event_id_random', None), table_name='event')
|
obj_data['event_id'] = redis_lookup_id_random(record_id_random=obj_data.get('event_id_random', None), table_name='event')
|
||||||
obj_data.pop('event_id_random')
|
obj_data.pop('event_id_random')
|
||||||
|
|||||||
10
app/main.py
10
app/main.py
@@ -18,7 +18,7 @@ from app.lib_general import log, logging
|
|||||||
from app.log import log
|
from app.log import log
|
||||||
|
|
||||||
# Import the routers here first:
|
# Import the routers here first:
|
||||||
from app.routers import api_crud, api, account, address, archive, archive_content, contact, cont_edu_cert_person, event, event_exhibit, event_file, event_person, event_person_detail, event_presentation, event_presenter, event_registration, event_session, flask_cfg, hosted_file, journal, journal_entry, log_client_viewing, lookup, membership_cfg, membership_group, membership_group_person, membership_person, membership_person_profile, membership_type, membership_type_person, order, order_cart, organization, page, person, post, post_comment, product, site, site_domain, user, user_person, websockets # , items, journals
|
from app.routers import api_crud, api, account, address, archive, archive_content, contact, cont_edu_cert, cont_edu_cert_person, event, event_exhibit, event_file, event_person, event_person_detail, event_presentation, event_presenter, event_registration, event_session, flask_cfg, hosted_file, journal, journal_entry, log_client_viewing, lookup, membership_cfg, membership_group, membership_group_person, membership_person, membership_person_profile, membership_type, membership_type_person, order, order_cart, organization, page, person, post, post_comment, product, site, site_domain, user, user_person, websockets # , items, journals
|
||||||
|
|
||||||
from app.db_sql import db
|
from app.db_sql import db
|
||||||
|
|
||||||
@@ -94,10 +94,10 @@ app.include_router(
|
|||||||
prefix='/contact',
|
prefix='/contact',
|
||||||
tags=['Contact'],
|
tags=['Contact'],
|
||||||
)
|
)
|
||||||
# app.include_router(
|
app.include_router(
|
||||||
# cont_edu_cert.router,
|
cont_edu_cert.router,
|
||||||
# tags=['Cont Edu Cert'],
|
tags=['Cont Edu Cert'],
|
||||||
# )
|
)
|
||||||
app.include_router(
|
app.include_router(
|
||||||
cont_edu_cert_person.router,
|
cont_edu_cert_person.router,
|
||||||
tags=['Cont Edu Cert Person'],
|
tags=['Cont Edu Cert Person'],
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ def load_cont_edu_cert_obj(
|
|||||||
exclude_unset: bool = True,
|
exclude_unset: bool = True,
|
||||||
model_as_dict: bool = False,
|
model_as_dict: bool = False,
|
||||||
enabled: str = 'enabled', # enabled, disabled, all
|
enabled: str = 'enabled', # enabled, disabled, all
|
||||||
|
inc_cont_edu_cert_person_list: bool = False,
|
||||||
) -> Cont_Edu_Cert_Base|dict|bool:
|
) -> Cont_Edu_Cert_Base|dict|bool:
|
||||||
# log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
# log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(locals())
|
log.debug(locals())
|
||||||
@@ -36,6 +37,30 @@ def load_cont_edu_cert_obj(
|
|||||||
log.error(e.json())
|
log.error(e.json())
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# Updated 2021-07-28
|
||||||
|
if inc_cont_edu_cert_person_list:
|
||||||
|
from app.methods.cont_edu_cert_person_methods import get_cont_edu_cert_person_rec_list, load_cont_edu_cert_person_obj
|
||||||
|
if cont_edu_cert_person_rec_list_result := get_cont_edu_cert_person_rec_list(
|
||||||
|
cont_edu_cert_id = cont_edu_cert_id,
|
||||||
|
limit = limit,
|
||||||
|
enabled = enabled,
|
||||||
|
):
|
||||||
|
cont_edu_cert_person_result_list = []
|
||||||
|
for cont_edu_cert_person_rec in cont_edu_cert_person_rec_list_result:
|
||||||
|
if load_cont_edu_cert_person_result := load_cont_edu_cert_person_obj(
|
||||||
|
cont_edu_cert_person_id = cont_edu_cert_person_rec.get('cont_edu_cert_person_id', None),
|
||||||
|
limit = limit,
|
||||||
|
by_alias = by_alias,
|
||||||
|
exclude_unset = exclude_unset,
|
||||||
|
model_as_dict = model_as_dict,
|
||||||
|
enabled = enabled,
|
||||||
|
# inc_cont_edu_cert = inc_cont_edu_cert,
|
||||||
|
):
|
||||||
|
cont_edu_cert_person_result_list.append(load_cont_edu_cert_person_result)
|
||||||
|
else: cont_edu_cert_person_result_list.append(None)
|
||||||
|
cont_edu_cert_obj.cont_edu_cert_person_list = cont_edu_cert_person_result_list
|
||||||
|
else: cont_edu_cert_obj.cont_edu_cert_person_list = []
|
||||||
|
|
||||||
if model_as_dict:
|
if model_as_dict:
|
||||||
return cont_edu_cert_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset) # pylint: disable=no-member
|
return cont_edu_cert_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset) # pylint: disable=no-member
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -62,7 +62,12 @@ def load_cont_edu_cert_person_obj(
|
|||||||
|
|
||||||
# ### BEGIN ### API Cont Edu Cert Person Methods ### get_cont_edu_cert_person_rec_list() ###
|
# ### BEGIN ### API Cont Edu Cert Person Methods ### get_cont_edu_cert_person_rec_list() ###
|
||||||
def get_cont_edu_cert_person_rec_list(
|
def get_cont_edu_cert_person_rec_list(
|
||||||
cont_edu_cert_id: str,
|
account_id: str = None,
|
||||||
|
cont_edu_cert_id: str = None,
|
||||||
|
given_name: str = None,
|
||||||
|
family_name: str = None,
|
||||||
|
from_datetime: Optional[datetime.datetime] = None, # based on created_on
|
||||||
|
to_datetime: Optional[datetime.datetime] = None, # based on created_on
|
||||||
limit: int = 1000,
|
limit: int = 1000,
|
||||||
enabled: str = 'enabled', # enabled, disabled, all
|
enabled: str = 'enabled', # enabled, disabled, all
|
||||||
) -> list|bool:
|
) -> list|bool:
|
||||||
@@ -72,8 +77,13 @@ def get_cont_edu_cert_person_rec_list(
|
|||||||
if cont_edu_cert_id := redis_lookup_id_random(record_id_random=cont_edu_cert_id, table_name='cont_edu_cert'): pass
|
if cont_edu_cert_id := redis_lookup_id_random(record_id_random=cont_edu_cert_id, table_name='cont_edu_cert'): pass
|
||||||
else: return False
|
else: return False
|
||||||
data = {}
|
data = {}
|
||||||
data['cont_edu_cert_id'] = cont_edu_cert_id
|
if account_id:
|
||||||
sql_cont_edu_cert_id = f'`tbl`.cont_edu_cert_id = :cont_edu_cert_id'
|
data['account_id'] = account_id
|
||||||
|
sql_where_id = f'`tbl`.account_id = :account_id'
|
||||||
|
elif cont_edu_cert_id:
|
||||||
|
data['cont_edu_cert_id'] = cont_edu_cert_id
|
||||||
|
sql_where_id = f'`tbl`.cont_edu_cert_id = :cont_edu_cert_id'
|
||||||
|
else: return False
|
||||||
|
|
||||||
if enabled in ['enabled', 'disabled', 'all']:
|
if enabled in ['enabled', 'disabled', 'all']:
|
||||||
if enabled == 'enabled':
|
if enabled == 'enabled':
|
||||||
@@ -86,6 +96,19 @@ def get_cont_edu_cert_person_rec_list(
|
|||||||
sql_enabled = ''
|
sql_enabled = ''
|
||||||
# sql_enabled = ''
|
# sql_enabled = ''
|
||||||
|
|
||||||
|
if from_datetime and to_datetime:
|
||||||
|
data['from_datetime'] = from_datetime
|
||||||
|
data['to_datetime'] = to_datetime
|
||||||
|
sql_from_to_datetime = f'AND `tbl`.created_on >= :from_datetime AND `tbl`.created_on <= :to_datetime'
|
||||||
|
elif from_datetime:
|
||||||
|
data['from_datetime'] = from_datetime
|
||||||
|
sql_from_to_datetime = f'AND `tbl`.created_on >= :from_datetime'
|
||||||
|
elif to_datetime:
|
||||||
|
data['to_datetime'] = to_datetime
|
||||||
|
sql_from_to_datetime = f'AND `tbl`.created_on <= :to_datetime'
|
||||||
|
else:
|
||||||
|
sql_from_to_datetime = ''
|
||||||
|
|
||||||
if limit:
|
if limit:
|
||||||
data['limit'] = limit
|
data['limit'] = limit
|
||||||
sql_limit = f'LIMIT :limit'
|
sql_limit = f'LIMIT :limit'
|
||||||
@@ -96,8 +119,9 @@ def get_cont_edu_cert_person_rec_list(
|
|||||||
SELECT `tbl`.id AS 'cont_edu_cert_person_id', `tbl`.id_random AS 'cont_edu_cert_person_id_random'
|
SELECT `tbl`.id AS 'cont_edu_cert_person_id', `tbl`.id_random AS 'cont_edu_cert_person_id_random'
|
||||||
FROM `cont_edu_cert_person` AS `tbl`
|
FROM `cont_edu_cert_person` AS `tbl`
|
||||||
WHERE
|
WHERE
|
||||||
{sql_cont_edu_cert_id}
|
{sql_where_id}
|
||||||
{sql_enabled}
|
{sql_enabled}
|
||||||
|
{sql_from_to_datetime}
|
||||||
ORDER BY `tbl`.created_on DESC, `tbl`.updated_on DESC
|
ORDER BY `tbl`.created_on DESC, `tbl`.updated_on DESC
|
||||||
{sql_limit};
|
{sql_limit};
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ class Cont_Edu_Cert_Base(BaseModel):
|
|||||||
updated_on: Optional[datetime.datetime] = None
|
updated_on: Optional[datetime.datetime] = None
|
||||||
|
|
||||||
# Including other related objects
|
# Including other related objects
|
||||||
|
cont_edu_cert_person_list: Optional[list] # Cont_Edu_Cert_Person_Base()
|
||||||
product: Optional[Union[Product_Base, None]]
|
product: Optional[Union[Product_Base, None]]
|
||||||
|
|
||||||
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ async def get_account_obj_cont_edu_cert_list(
|
|||||||
account_id: str = Query(..., min_length=1, max_length=22),
|
account_id: str = Query(..., min_length=1, max_length=22),
|
||||||
limit: int = 500, # For now this covers any included objects or object lists
|
limit: int = 500, # For now this covers any included objects or object lists
|
||||||
enabled: str = 'enabled', # For now this covers any included objects or object lists
|
enabled: str = 'enabled', # For now this covers any included objects or object lists
|
||||||
inc_cont_edu_cert: bool = False,
|
inc_cont_edu_cert_person_list: bool = False,
|
||||||
x_account_id: str = Header(...),
|
x_account_id: str = Header(...),
|
||||||
by_alias: Optional[bool] = True,
|
by_alias: Optional[bool] = True,
|
||||||
exclude_unset: Optional[bool] = True,
|
exclude_unset: Optional[bool] = True,
|
||||||
@@ -225,6 +225,7 @@ async def get_account_obj_cont_edu_cert_list(
|
|||||||
exclude_unset = exclude_unset,
|
exclude_unset = exclude_unset,
|
||||||
# model_as_dict = model_as_dict,
|
# model_as_dict = model_as_dict,
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
|
inc_cont_edu_cert_person_list = inc_cont_edu_cert_person_list,
|
||||||
):
|
):
|
||||||
cont_edu_cert_result_list.append(load_cont_edu_cert_result)
|
cont_edu_cert_result_list.append(load_cont_edu_cert_result)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -169,6 +169,84 @@ async def get_cont_edu_cert_person_obj_li(
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
# ### BEGIN ### API Cont Edu Cert Person ### search_cont_edu_cert_person_obj_li() ###
|
||||||
|
# Updated 2021-07-28
|
||||||
|
@router.get('/cont_edu/cert/person/search', response_model=Resp_Body_Base)
|
||||||
|
async def search_cont_edu_cert_person_obj_li(
|
||||||
|
account_id: str = Query(None, min_length=2, max_length=22),
|
||||||
|
external_id: str = Query('%', min_length=1, max_length=50),
|
||||||
|
given_name: str = Query('%', min_length=1, max_length=25),
|
||||||
|
family_name: str = Query('%', min_length=1, max_length=25),
|
||||||
|
email: str = Query('%', min_length=1, max_length=50),
|
||||||
|
from_datetime: Optional[datetime.datetime] = None, # based on created_on
|
||||||
|
to_datetime: Optional[datetime.datetime] = None, # based on created_on
|
||||||
|
limit: int = 50,
|
||||||
|
enabled: str = 'enabled',
|
||||||
|
x_account_id: str = Header(...),
|
||||||
|
by_alias: bool = True,
|
||||||
|
exclude_unset: bool = True,
|
||||||
|
):
|
||||||
|
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
log.debug(locals())
|
||||||
|
|
||||||
|
cont_edu_cert_id_list = [1, 2]
|
||||||
|
# cont_edu_cert_id_list = [3, 4]
|
||||||
|
# cont_edu_cert_id_list = ['3vqsbpWjd9s', 'bCv8WBzdRJQ']
|
||||||
|
|
||||||
|
data = {}
|
||||||
|
data['account_id_random'] = account_id
|
||||||
|
data['cont_edu_cert_id_list'] = cont_edu_cert_id_list
|
||||||
|
data['external_id'] = external_id
|
||||||
|
data['given_name'] = given_name
|
||||||
|
data['family_name'] = family_name
|
||||||
|
data['email'] = email
|
||||||
|
data['from_datetime'] = from_datetime
|
||||||
|
data['to_datetime'] = to_datetime
|
||||||
|
log.debug(data)
|
||||||
|
|
||||||
|
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 limit:
|
||||||
|
data['limit'] = limit
|
||||||
|
sql_limit = f'LIMIT :limit'
|
||||||
|
else:
|
||||||
|
sql_limit = ''
|
||||||
|
|
||||||
|
sql = f"""
|
||||||
|
SELECT *
|
||||||
|
FROM `v_cont_edu_cert_person` AS cont_edu_cert_person
|
||||||
|
WHERE cont_edu_cert_person.account_id = :account_id
|
||||||
|
AND cont_edu_cert_person.cont_edu_cert_id IN :cont_edu_cert_id_list
|
||||||
|
AND cont_edu_cert_person.external_id LIKE :external_id
|
||||||
|
AND (cont_edu_cert_person.given_name LIKE :given_name
|
||||||
|
AND cont_edu_cert_person.family_name LIKE :family_name)
|
||||||
|
AND cont_edu_cert_person.email LIKE :email
|
||||||
|
{sql_enabled}
|
||||||
|
ORDER BY cont_edu_cert_person.given_name ASC, cont_edu_cert_person.family_name ASC, cont_edu_cert_person.created_on DESC, cont_edu_cert_person.updated_on DESC
|
||||||
|
{sql_limit};
|
||||||
|
"""
|
||||||
|
log.debug(sql)
|
||||||
|
if sql_result := sql_select(data=data, sql=sql, as_list=True, rm_id_random=True):
|
||||||
|
resp_data_li = []
|
||||||
|
for record in sql_result:
|
||||||
|
resp_data = Cont_Edu_Cert_Person_Base(**record).dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
||||||
|
resp_data_li.append(resp_data)
|
||||||
|
|
||||||
|
return mk_resp(data=resp_data_li)
|
||||||
|
else:
|
||||||
|
log.debug(sql_result)
|
||||||
|
return mk_resp(data=False, status_code=404)
|
||||||
|
# ### END ### API Cont Edu Cert Person ### search_cont_edu_cert_person_obj_li() ###
|
||||||
|
|
||||||
|
|
||||||
@router.get('/cont_edu/cert/person/{obj_id}', response_model=Resp_Body_Base)
|
@router.get('/cont_edu/cert/person/{obj_id}', response_model=Resp_Body_Base)
|
||||||
async def get_cont_edu_cert_person_obj(
|
async def get_cont_edu_cert_person_obj(
|
||||||
obj_id: str = Query(..., min_length=1, max_length=22),
|
obj_id: str = Query(..., min_length=1, max_length=22),
|
||||||
@@ -235,7 +313,56 @@ async def get_account_obj_cont_edu_cert_person_list(
|
|||||||
return mk_resp(data=False, status_code=400) # Bad Request
|
return mk_resp(data=False, status_code=400) # Bad Request
|
||||||
|
|
||||||
return mk_resp(data=response_data)
|
return mk_resp(data=response_data)
|
||||||
# ### END ### API Person ### get_account_obj_cont_edu_cert_person_list() ###
|
# ### END ### API Cont Edu Cert Person ### get_account_obj_cont_edu_cert_person_list() ###
|
||||||
|
|
||||||
|
|
||||||
|
# ### BEGIN ### API Cont Edu Cert Person ### get_cont_edu_cert_obj_cont_edu_cert_person_list() ###
|
||||||
|
# Updated 2021-07-28
|
||||||
|
@router.get('/cont_edu/cert/{cont_edu_cert_id}/cont_edu/cert/person/list', response_model=Resp_Body_Base)
|
||||||
|
async def get_cont_edu_cert_obj_cont_edu_cert_person_list(
|
||||||
|
cont_edu_cert_id: str = Query(..., min_length=1, max_length=22),
|
||||||
|
limit: int = 500, # For now this covers any included objects or object lists
|
||||||
|
enabled: str = 'enabled', # For now this covers any included objects or object lists
|
||||||
|
inc_cont_edu_cert: bool = False,
|
||||||
|
x_account_id: str = Header(...),
|
||||||
|
by_alias: Optional[bool] = True,
|
||||||
|
exclude_unset: Optional[bool] = True,
|
||||||
|
):
|
||||||
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
log.debug(locals())
|
||||||
|
|
||||||
|
if cont_edu_cert_id := redis_lookup_id_random(record_id_random=cont_edu_cert_id, table_name='cont_edu_cert'): pass
|
||||||
|
else: return mk_resp(data=None, status_code=404)
|
||||||
|
|
||||||
|
response_data = None
|
||||||
|
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
|
||||||
|
# Updated 2021-07-28
|
||||||
|
if cont_edu_cert_person_rec_list_result := get_cont_edu_cert_person_rec_list(
|
||||||
|
cont_edu_cert_id = cont_edu_cert_id,
|
||||||
|
limit = limit,
|
||||||
|
enabled = enabled,
|
||||||
|
):
|
||||||
|
cont_edu_cert_person_result_list = []
|
||||||
|
for cont_edu_cert_person_rec in cont_edu_cert_person_rec_list_result:
|
||||||
|
if load_cont_edu_cert_person_result := load_cont_edu_cert_person_obj(
|
||||||
|
cont_edu_cert_person_id = cont_edu_cert_person_rec.get('cont_edu_cert_person_id', None),
|
||||||
|
limit = limit,
|
||||||
|
by_alias = by_alias,
|
||||||
|
exclude_unset = exclude_unset,
|
||||||
|
# model_as_dict = model_as_dict,
|
||||||
|
enabled = enabled,
|
||||||
|
inc_cont_edu_cert = inc_cont_edu_cert,
|
||||||
|
):
|
||||||
|
cont_edu_cert_person_result_list.append(load_cont_edu_cert_person_result)
|
||||||
|
else:
|
||||||
|
cont_edu_cert_person_result_list.append(None)
|
||||||
|
response_data = cont_edu_cert_person_result_list
|
||||||
|
else:
|
||||||
|
return mk_resp(data=False, status_code=400) # Bad Request
|
||||||
|
|
||||||
|
return mk_resp(data=response_data)
|
||||||
|
# ### END ### API Cont Edu Cert Person ### get_cont_edu_cert_obj_cont_edu_cert_person_list() ###
|
||||||
|
|
||||||
|
|
||||||
@router.delete('/cont_edu/cert/person/{obj_id}', response_model=Resp_Body_Base)
|
@router.delete('/cont_edu/cert/person/{obj_id}', response_model=Resp_Body_Base)
|
||||||
|
|||||||
Reference in New Issue
Block a user