diff --git a/app/models/archive_content_models.py b/app/models/archive_content_models.py index 888d59f..dd5b2ba 100644 --- a/app/models/archive_content_models.py +++ b/app/models/archive_content_models.py @@ -41,7 +41,8 @@ class Archive_Content_Base(BaseModel): description: Optional[str] content_html: Optional[str] - content_json: Optional[str] + content_json: Optional[Union[Json, None]] + url: Optional[str] url_text: Optional[str] @@ -60,7 +61,7 @@ class Archive_Content_Base(BaseModel): api_hosted_file_path_stream: str = None # '/testing/test-test' original_datetime: Optional[datetime.datetime] - original_datetime_timezone: Optional[str] + original_timezone: Optional[str] original_location: Optional[str] original_address_id: Optional[int] original_url: Optional[str] @@ -69,6 +70,8 @@ class Archive_Content_Base(BaseModel): meta_data: Optional[str] access_key: Optional[str] + enable_for_public: Optional[bool] + enable: Optional[bool] enable_from: Optional[datetime.datetime] enable_to: Optional[datetime.datetime] diff --git a/app/models/archive_models.py b/app/models/archive_models.py index 3232e3a..ee90c4f 100644 --- a/app/models/archive_models.py +++ b/app/models/archive_models.py @@ -35,7 +35,7 @@ class Archive_Base(BaseModel): content_url_text: Optional[str] original_datetime: Optional[datetime.datetime] = None - original_datetime_timezone: Optional[str] = None + original_timezone: Optional[str] = None original_location: Optional[str] = None original_address_id: Optional[int] = None diff --git a/app/routers/api_crud.py b/app/routers/api_crud.py index 1fbb9e8..2d3b120 100644 --- a/app/routers/api_crud.py +++ b/app/routers/api_crud.py @@ -74,7 +74,7 @@ obj_type_li['account'] = {'table_name': 'account', 'tbl_name_update': 'account', obj_type_li['account_cfg'] = {'table_name': 'v_account_cfg', 'tbl_name_update': 'account_cfg', 'base_name': Account_Cfg_Base} # NOTE check view name: *_detail? obj_type_li['activity_log'] = {'table_name': 'activity_log', 'tbl_name_update': 'activity_log', 'base_name': Activity_Log_Base} obj_type_li['address'] = {'table_name': 'v_address', 'tbl_name_update': 'address', 'base_name': Address_Base} -obj_type_li['archive'] = {'table_name': 'v_archive', 'tbl_name_update': 'archive', 'base_name': Archive_Base} +obj_type_li['archive'] = {'table_name': 'v_archive', 'table_name_alt': 'v_archive_w_content_count', 'tbl_name_update': 'archive', 'base_name': Archive_Base} obj_type_li['archive_content'] = {'table_name': 'v_archive_content', 'tbl_name_update': 'archive_content', 'base_name': Archive_Content_Base} #obj_type_li['change_log'] = {'table_name': 'change_log', 'tbl_name_update': 'change_log', 'base_name': Change_Log_Base} obj_type_li['contact'] = {'table_name': 'v_contact', 'tbl_name_update': 'contact', 'base_name': Contact_Base} @@ -130,8 +130,8 @@ obj_type_li['site_domain'] = {'table_name': 'v_site_domain', 'tbl_name_update': obj_type_li['user'] = {'table_name': 'v_user', 'tbl_name_update': 'user', 'base_name': User_Base} obj_type_li['user_role'] = {'table_name': 'v_user_role', 'tbl_name_update': 'user_role', 'base_name': User_Role_Base} # NOTE check view name: *_detail? -#obj_type_li['lu_country'] = {'table_name': 'lu_country', 'tbl_name_update': 'lu_country', 'base_name': Lu_Country_Base} -#obj_type_li['lu_country_subdivision'] = {'table_name': 'lu_country_subdivision', 'tbl_name_update': 'lu_country_subdivision', 'base_name': Lu_Country_Subdivision_Base} +obj_type_li['lu_country'] = {'table_name': 'lu_country', 'tbl_name_update': 'lu_country', 'base_name': None} +obj_type_li['lu_country_subdivision'] = {'table_name': 'lu_country_subdivision', 'tbl_name_update': 'lu_country_subdivision', 'base_name': None} #obj_type_li['lu_education_degree'] = {'table_name': 'lu_education_degree', 'tbl_name_update': 'lu_education_degree', 'base_name': Lu_Education_Degree_Base} #obj_type_li['lu_education_level'] = {'table_name': 'lu_education_level', 'tbl_name_update': 'lu_education_level', 'base_name': Lu_Education_Level_Base} #obj_type_li['lu_ethnicity'] = {'table_name': 'lu_ethnicity', 'tbl_name_update': 'lu_ethnicity', 'base_name': Lu_Ethnicity_Base} @@ -146,7 +146,7 @@ obj_type_li['user_role'] = {'table_name': 'v_user_role', 'tbl_name_update': 'use #obj_type_li['lu_product_type'] = {'table_name': 'lu_product_type', 'tbl_name_update': 'lu_product_type', 'base_name': Lu_Product_Type_Base} #obj_type_li['lu_pronoun'] = {'table_name': 'lu_pronoun', 'tbl_name_update': 'lu_pronoun', 'base_name': Lu_Pronoun_Base} #obj_type_li['lu_race'] = {'table_name': 'lu_race', 'tbl_name_update': 'lu_race', 'base_name': Lu_Race_Base} -#obj_type_li['lu_time_zone'] = {'table_name': 'v_lu_time_zone', 'tbl_name_update': 'lu_time_zone', 'base_name': Lu_Time_Zone_Base} +obj_type_li['lu_time_zone'] = {'table_name': 'v_lu_time_zone', 'tbl_name_update': 'lu_time_zone', 'base_name': None} #obj_type_li['lu_user_role'] = {'table_name': 'lu_user_role', 'tbl_name_update': 'lu_user_role', 'base_name': Lu_User_Role_Base} #obj_type_li['lu_user_status'] = {'table_name': 'lu_user_status', 'tbl_name_update': 'lu_user_status', 'base_name': Lu_User_Status_Base} @@ -216,7 +216,7 @@ async def get_obj_li( except Exception as e: log.warning(e) return mk_resp(data=False, status_code=400, response=commons.response, status_message='The JSON string was not formatted correctly.') - + log.debug(jp_obj) if jp_obj.get('ft_qry'): # NOTE: This is for the fulltext query @@ -224,7 +224,7 @@ async def get_obj_li( if jp_obj.get('and_qry'): # NOTE: This is for the additional AND clauses in the WHERE statement and_qry_dict_obj = jp_obj['and_qry'] - + if order_by_li: order_by_li = json.loads(order_by_li) @@ -237,7 +237,7 @@ async def get_obj_li( # except Exception as e: # log.warning(e) # return mk_resp(data=False, status_code=400, response=commons.response, status_message='The JSON string was not formatted correctly.') - + # log.debug(json_obj) debug_data = {} @@ -255,6 +255,9 @@ async def get_obj_li( debug_data['hidden'] = hidden debug_data['order_by_li'] = order_by_li + if obj_type_l1 == 'lu': + log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL + log.debug(debug_data) if obj_type_l1 and obj_type_l2 and obj_type_l3: @@ -295,21 +298,21 @@ async def get_obj_li( log.debug(f'for_obj_id: {for_obj_id}') field_name = f'{for_obj_type}_id' - + # NOTE: The enabled and hidden parameters are new to this endpoint and the sql_select function! -2023-07-06 sql_result = sql_select( - table_name = table_name, - field_name = field_name, - field_value = for_obj_id, - enabled = commons.enabled, + table_name = table_name, + field_name = field_name, + field_value = for_obj_id, + enabled = commons.enabled, hidden = hidden, fulltext_qry_dict = fulltext_qry_dict_obj, and_qry_dict = and_qry_dict_obj, - # fulltext_qry_field_li = fulltext_qry_field_li, - # fulltext_qry_str = fulltext_qry_str, - order_by_li = order_by_li, - limit = commons.limit, - offset = commons.offset, + # fulltext_qry_field_li = fulltext_qry_field_li, + # fulltext_qry_str = fulltext_qry_str, + order_by_li = order_by_li, + limit = commons.limit, + offset = commons.offset, as_list = True, # log_lvl = logging.DEBUG ) @@ -317,18 +320,18 @@ async def get_obj_li( # NOTE: The enabled and hidden parameters are new to this endpoint and the sql_select function! -2023-07-06 # NOTE: This call (without field_name, field_value, limit, offset) may need more testing. sql_result = sql_select( - table_name = table_name, - enabled = commons.enabled, + table_name = table_name, + enabled = commons.enabled, hidden = hidden, fulltext_qry_dict = fulltext_qry_dict_obj, and_qry_dict = and_qry_dict_obj, - # fulltext_qry_field_li = fulltext_qry_field_li, - # fulltext_qry_str = fulltext_qry_str, - order_by_li = order_by_li, - limit = commons.limit, - offset = commons.offset, + # fulltext_qry_field_li = fulltext_qry_field_li, + # fulltext_qry_str = fulltext_qry_str, + order_by_li = order_by_li, + limit = commons.limit, + offset = commons.offset, as_list = True, - # log_lvl = logging.DEBUG + log_lvl = logging.DEBUG ) # log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL @@ -338,7 +341,12 @@ async def get_obj_li( if isinstance(sql_result, list): resp_data_li = [] for record in sql_result: - resp_data = base_name(**record).dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset) + if base_name: + log.info(f'base_name was found. Returning data using {base_name} model.') + resp_data = base_name(**record).dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset) + else: + log.info('base_name model was not found. Returning raw data.') + resp_data = record resp_data_li.append(resp_data) return mk_resp(data=resp_data_li, response=commons.response) else: @@ -440,7 +448,12 @@ async def get_obj( if sql_result := sql_select(table_name=table_name, record_id_random=obj_id): log.debug(sql_result) - resp_data = base_name(**sql_result).dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset) + if base_name: + log.info(f'base_name was found. Returning data using {base_name} model.') + resp_data = base_name(**sql_result).dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset) + else: + log.info('base_name model was not found. Returning raw data.') + resp_data = sql_result return mk_resp(data=resp_data, response=commons.response) #, details=debug_data) else: @@ -699,7 +712,15 @@ async def post_obj( if run_safety_check: log.info('Running safety check by default') base_name = obj_type_li[obj_name]['base_name'] - obj_model = base_name(**crud.data_list) # .dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset) + try: + obj_model = base_name(**crud.data_list) # .dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset) + except Exception as e: + log.error('An unknown exception happened. Returning False.') + log.exception('**** *** ** * ### BEGIN ### Exception Happened: Returning False * ** *** ****') + return mk_resp(data=False, status_code=400, response=commons.response, status_message='There was likely a validation error. Returned False.') + else: + log.info('Successfully created the object model.') + pass log.debug(obj_model) # obj_dict = obj_model.dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset, exclude=exclude) obj_dict = obj_model.dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset, include=field_list)