General bug fixes and clean up. Starting on a better version 2 of the CRUD endpoints.
This commit is contained in:
191
app/ae_obj_types_def.py
Normal file
191
app/ae_obj_types_def.py
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
from app.models.response_models import *
|
||||||
|
|
||||||
|
from app.models.api_crud_models import *
|
||||||
|
|
||||||
|
from app.models.account_models import *
|
||||||
|
from app.models.account_cfg_models import *
|
||||||
|
from app.models.activity_log_models import *
|
||||||
|
from app.models.address_models import *
|
||||||
|
from app.models.archive_models import *
|
||||||
|
from app.models.archive_content_models import *
|
||||||
|
from app.models.contact_models import *
|
||||||
|
from app.models.cont_edu_cert_models import *
|
||||||
|
from app.models.cont_edu_cert_person_models import *
|
||||||
|
from app.models.data_store_models import *
|
||||||
|
from app.models.event_models import *
|
||||||
|
from app.models.event_abstract_models import *
|
||||||
|
from app.models.event_badge_models import *
|
||||||
|
from app.models.event_exhibit_models import *
|
||||||
|
from app.models.event_exhibit_tracking_models import *
|
||||||
|
from app.models.event_file_models import *
|
||||||
|
from app.models.event_location_models import *
|
||||||
|
from app.models.event_person_models import *
|
||||||
|
from app.models.event_person_tracking_models import *
|
||||||
|
from app.models.event_presentation_models import *
|
||||||
|
from app.models.event_presenter_models import *
|
||||||
|
from app.models.event_registration_models import *
|
||||||
|
from app.models.event_session_models import *
|
||||||
|
from app.models.event_track_models import *
|
||||||
|
from app.models.grant_models import *
|
||||||
|
from app.models.hosted_file_models import *
|
||||||
|
from app.models.journal_models import *
|
||||||
|
from app.models.journal_entry_models import *
|
||||||
|
from app.models.log_client_viewing_models import Log_Client_Viewing_Base
|
||||||
|
from app.models.membership_cfg_models import *
|
||||||
|
from app.models.membership_group_models import *
|
||||||
|
from app.models.membership_person_group_models import *
|
||||||
|
from app.models.membership_person_models import *
|
||||||
|
from app.models.membership_person_profile_models import *
|
||||||
|
from app.models.membership_type_models import *
|
||||||
|
from app.models.membership_person_type_models import *
|
||||||
|
from app.models.order_models import *
|
||||||
|
from app.models.order_cart_models import *
|
||||||
|
from app.models.organization_models import *
|
||||||
|
from app.models.page_models import *
|
||||||
|
from app.models.person_models import *
|
||||||
|
from app.models.product_models import *
|
||||||
|
from app.models.post_models import *
|
||||||
|
from app.models.post_comment_models import *
|
||||||
|
from app.models.site_models import *
|
||||||
|
from app.models.site_domain_models import *
|
||||||
|
from app.models.sponsorship_cfg_models import *
|
||||||
|
from app.models.sponsorship_models import *
|
||||||
|
from app.models.user_models import *
|
||||||
|
from app.models.user_role_models import *
|
||||||
|
|
||||||
|
from app.models.e_stripe_models import *
|
||||||
|
|
||||||
|
|
||||||
|
obj_type_kv_li = {
|
||||||
|
'sponsorship': {
|
||||||
|
'tbl': 'sponsorship', 'tbl_default': 'v_sponsorship', 'tbl_update': 'sponsorship',
|
||||||
|
'mdl': Sponsorship_Base, 'mdl_default': Sponsorship_Base, 'mdl_in': None, 'mdl_out': None
|
||||||
|
},
|
||||||
|
'sponsorship_cfg': {
|
||||||
|
'tbl': 'sponsorship_cfg', 'tbl_default': 'v_sponsorship_cfg', 'tbl_update': 'sponsorship_cfg',
|
||||||
|
'mdl': Sponsorship_Cfg_Base, 'mdl_default': Sponsorship_Cfg_Base, 'mdl_in': None, 'mdl_out': None
|
||||||
|
},
|
||||||
|
'event_presenter': {
|
||||||
|
'tbl': 'event_presenter', 'tbl_default': 'v_event_presenter', 'tbl_update': 'event_presenter', 'mdl': Event_Presenter_Base, 'mdl_default': Event_Presenter_Base,
|
||||||
|
},
|
||||||
|
} # New 2024-04-23
|
||||||
|
# obj_type_kv_li['example_template'] = {'tbl': 'example_template', 'tbl_default': 'v_example_template', 'tbl_update': 'example_template', 'mdl': Example_Template_Base, 'mdl_in': Example_Template_In_Base, 'mdl_out': Example_Template_Out_Base }
|
||||||
|
|
||||||
|
# obj_type_kv_li['sponsorship'] = {'tbl': 'sponsorship', 'tbl_default': 'v_sponsorship', 'tbl_update': 'sponsorship', 'mdl': Sponsorship_Base, 'mdl_in': None, 'mdl_out': None }
|
||||||
|
# obj_type_kv_li['sponsorship_cfg'] = {'table_name': 'v_sponsorship_cfg', 'tbl_name_update': 'sponsorship_cfg', 'base_name': Sponsorship_Cfg_Base}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# ### Need to update everything below this line! ###
|
||||||
|
|
||||||
|
|
||||||
|
# ### Core module objects
|
||||||
|
obj_type_kv_li['account'] = {'table_name': 'account', 'tbl_name_update': 'account', 'base_name': Account_Base}
|
||||||
|
obj_type_kv_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_kv_li['activity_log'] = {'table_name': 'activity_log', 'tbl_name_update': 'activity_log', 'base_name': Activity_Log_Base}
|
||||||
|
obj_type_kv_li['address'] = {'table_name': 'v_address', 'tbl_name_update': 'address', 'base_name': Address_Base}
|
||||||
|
#obj_type_kv_li['change_log'] = {'table_name': 'change_log', 'tbl_name_update': 'change_log', 'base_name': Change_Log_Base}
|
||||||
|
obj_type_kv_li['contact'] = {'table_name': 'v_contact', 'tbl_name_update': 'contact', 'base_name': Contact_Base}
|
||||||
|
|
||||||
|
obj_type_kv_li['data_store'] = {'table_name': 'v_data_store', 'tbl_name_update': 'data_store', 'base_name': Data_Store_Base}
|
||||||
|
|
||||||
|
obj_type_kv_li['hosted_file'] = {'table_name': 'v_hosted_file', 'tbl_name_update': 'hosted_file', 'base_name': Hosted_File_Base}
|
||||||
|
#obj_type_kv_li['hosted_file_link'] = {'table_name': 'hosted_file_link', 'tbl_name_update': 'hosted_file_link', 'base_name': Hosted_File_Link_Base}
|
||||||
|
|
||||||
|
obj_type_kv_li['log_client_viewing'] = {'table_name': 'log_client_viewing', 'tbl_name_update': 'log_client_viewing', 'base_name': Log_Client_Viewing_Base}
|
||||||
|
|
||||||
|
obj_type_kv_li['order'] = {'table_name': 'v_order', 'tbl_name_update': 'order', 'base_name': Order_Base}
|
||||||
|
obj_type_kv_li['order_cart'] = {'table_name': 'v_order_cart', 'tbl_name_update': 'order_cart', 'base_name': Order_Cart_Base}
|
||||||
|
obj_type_kv_li['order_cart_line'] = {'table_name': 'v_order_cart_line', 'tbl_name_update': 'order_cart_line', 'base_name': Order_Cart_Line_Base}
|
||||||
|
obj_type_kv_li['order_line'] = {'table_name': 'v_order_line', 'tbl_name_update': 'order_line', 'base_name': Order_Line_Base}
|
||||||
|
#obj_type_kv_li['order_transaction'] = {'table_name': 'order_transaction', 'tbl_name_update': 'order_transaction', 'base_name': Order_Transaction_Base}
|
||||||
|
|
||||||
|
obj_type_kv_li['organization'] = {'table_name': 'v_organization', 'tbl_name_update': 'organization', 'base_name': Organization_Base}
|
||||||
|
|
||||||
|
obj_type_kv_li['page'] = {'table_name': 'page', 'tbl_name_update': 'page', 'base_name': Page_Base}
|
||||||
|
|
||||||
|
obj_type_kv_li['person'] = {'table_name': 'v_person', 'tbl_name_update': 'person', 'base_name': Person_Base}
|
||||||
|
|
||||||
|
obj_type_kv_li['site'] = {'table_name': 'site', 'tbl_name_update': 'site', 'base_name': Site_Base}
|
||||||
|
obj_type_kv_li['site_domain'] = {'table_name': 'v_site_domain', 'table_name_alt': 'v_site_domain_fqdn_id', 'tbl_name_update': 'site_domain', 'base_name': Site_Domain_Base, 'base_name_alt': Site_Domain_FQDN_ID_Base} # NOTE check view name: *_detail?
|
||||||
|
|
||||||
|
obj_type_kv_li['user'] = {'table_name': 'v_user', 'tbl_name_update': 'user', 'base_name': User_Base}
|
||||||
|
obj_type_kv_li['user_role'] = {'table_name': 'v_user_role', 'tbl_name_update': 'user_role', 'base_name': User_Role_Base} # NOTE check view name: *_detail?
|
||||||
|
|
||||||
|
|
||||||
|
# ### Common shared lookup objects
|
||||||
|
obj_type_kv_li['lu_country'] = {'table_name': 'lu_country', 'tbl_name_update': 'lu_country', 'base_name': None}
|
||||||
|
obj_type_kv_li['lu_country_subdivision'] = {'table_name': 'lu_country_subdivision', 'tbl_name_update': 'lu_country_subdivision', 'base_name': None}
|
||||||
|
#obj_type_kv_li['lu_education_degree'] = {'table_name': 'lu_education_degree', 'tbl_name_update': 'lu_education_degree', 'base_name': Lu_Education_Degree_Base}
|
||||||
|
#obj_type_kv_li['lu_education_level'] = {'table_name': 'lu_education_level', 'tbl_name_update': 'lu_education_level', 'base_name': Lu_Education_Level_Base}
|
||||||
|
#obj_type_kv_li['lu_ethnicity'] = {'table_name': 'lu_ethnicity', 'tbl_name_update': 'lu_ethnicity', 'base_name': Lu_Ethnicity_Base}
|
||||||
|
#obj_type_kv_li['lu_file_purpose'] = {'table_name': 'lu_file_purpose', 'tbl_name_update': 'lu_file_purpose', 'base_name': Lu_File_Purpose_Base}
|
||||||
|
#obj_type_kv_li['lu_gender'] = {'table_name': 'lu_gender', 'tbl_name_update': 'lu_gender', 'base_name': Lu_Gender_Base}
|
||||||
|
#obj_type_kv_li['lu_html_color'] = {'table_name': 'lu_html_color', 'tbl_name_update': 'lu_html_color', 'base_name': Lu_Html_Color_Base}
|
||||||
|
#obj_type_kv_li['lu_media_type'] = {'table_name': 'lu_media_type', 'tbl_name_update': 'lu_media_type', 'base_name': Lu_Media_Type_Base}
|
||||||
|
#obj_type_kv_li['lu_membership_status'] = {'table_name': 'lu_membership_status', 'tbl_name_update': 'lu_membership_status', 'base_name': Lu_Membership_Status_Base}
|
||||||
|
#obj_type_kv_li['lu_membership_type'] = {'table_name': 'lu_membership_type', 'tbl_name_update': 'lu_membership_type', 'base_name': Lu_Membership_Type_Base}
|
||||||
|
#obj_type_kv_li['lu_order_status'] = {'table_name': 'lu_order_status', 'tbl_name_update': 'lu_order_status', 'base_name': Lu_Order_Status_Base}
|
||||||
|
#obj_type_kv_li['lu_post_topic'] = {'table_name': 'lu_post_topic', 'tbl_name_update': 'lu_post_topic', 'base_name': Lu_Post_Topic_Base}
|
||||||
|
#obj_type_kv_li['lu_product_type'] = {'table_name': 'lu_product_type', 'tbl_name_update': 'lu_product_type', 'base_name': Lu_Product_Type_Base}
|
||||||
|
#obj_type_kv_li['lu_pronoun'] = {'table_name': 'lu_pronoun', 'tbl_name_update': 'lu_pronoun', 'base_name': Lu_Pronoun_Base}
|
||||||
|
#obj_type_kv_li['lu_race'] = {'table_name': 'lu_race', 'tbl_name_update': 'lu_race', 'base_name': Lu_Race_Base}
|
||||||
|
obj_type_kv_li['lu_time_zone'] = {'table_name': 'v_lu_time_zone', 'tbl_name_update': 'lu_time_zone', 'base_name': None}
|
||||||
|
#obj_type_kv_li['lu_user_role'] = {'table_name': 'lu_user_role', 'tbl_name_update': 'lu_user_role', 'base_name': Lu_User_Role_Base}
|
||||||
|
#obj_type_kv_li['lu_user_status'] = {'table_name': 'lu_user_status', 'tbl_name_update': 'lu_user_status', 'base_name': Lu_User_Status_Base}
|
||||||
|
|
||||||
|
|
||||||
|
# ### Additional module objects
|
||||||
|
obj_type_kv_li['archive'] = {'table_name': 'v_archive', 'table_name_alt': 'v_archive_w_content_count', 'tbl_name_update': 'archive', 'base_name': Archive_Base}
|
||||||
|
obj_type_kv_li['archive_content'] = {'table_name': 'v_archive_content', 'tbl_name_update': 'archive_content', 'base_name': Archive_Content_Base}
|
||||||
|
|
||||||
|
obj_type_kv_li['cont_edu_cert'] = {'table_name': 'v_cont_edu_cert', 'tbl_name_update': 'cont_edu_cert', 'base_name': Cont_Edu_Cert_Base}
|
||||||
|
obj_type_kv_li['cont_edu_cert_person'] = {'table_name': 'v_cont_edu_cert_person', 'tbl_name_update': 'cont_edu_cert_person', 'base_name': Cont_Edu_Cert_Person_Base}
|
||||||
|
obj_type_kv_li['event'] = {'table_name': 'v_event', 'table_name_alt': 'v_event_w_file_count',
|
||||||
|
'tbl_name_update': 'event', 'base_name': Event_Base, 'base_name_alt': Event_Meeting_Flat_Base}
|
||||||
|
|
||||||
|
obj_type_kv_li['event_abstract'] = {'table_name': 'v_event_abstract', 'tbl_name_update': 'event_abstract', 'base_name': Event_Abstract_In}
|
||||||
|
obj_type_kv_li['event_badge'] = {'table_name': 'v_event_badge', 'table_name_alt': 'v_event_badge_only', 'tbl_name_update': 'event_badge', 'base_name': Event_Badge_Base, 'base_name_alt': Event_Badge_Basic_Base}
|
||||||
|
#obj_type_kv_li['event_badge_log'] = {'table_name': 'event_badge_log', 'tbl_name_update': 'event_badge_log', 'base_name': Event_Badge_Log_Base}
|
||||||
|
#obj_type_kv_li['event_badge_template'] = {'table_name': 'event_badge_template', 'tbl_name_update': 'event_badge_template', 'base_name': Event_Badge_Template_Base}
|
||||||
|
#obj_type_kv_li['event_device'] = {'table_name': 'event_device', 'tbl_name_update': 'event_device', 'base_name': Event_Device_Base}
|
||||||
|
obj_type_kv_li['event_exhibit'] = {'table_name': 'v_event_exhibit', 'tbl_name_update': 'event_exhibit', 'base_name': Event_Exhibit_Base} # NOTE check view name: *_detail?
|
||||||
|
obj_type_kv_li['event_exhibit_tracking'] = {'table_name': 'v_event_exhibit_tracking', 'tbl_name_update': 'event_exhibit_tracking', 'base_name': Event_Exhibit_Tracking_Base}
|
||||||
|
# NOTE: Using v_event_file_simple instead of v_event_file because of linking with for_type and for_id versus event_id, event_session_id, event_presenter_id, etc. 2022-08-19
|
||||||
|
# NOTE: This will not pull in linked to details like a session name, presentation time, or presenter name.
|
||||||
|
obj_type_kv_li['event_file'] = {'table_name': 'v_event_file_simple', 'tbl_name_update': 'event_file_simple', 'base_name': Event_File_Base} # Should this eventually be changed to event_hosted_file
|
||||||
|
obj_type_kv_li['event_location'] = {'table_name': 'v_event_location', 'tbl_name_update': 'event_location', 'base_name': Event_Location_Base}
|
||||||
|
obj_type_kv_li['event_person'] = {'table_name': 'v_event_person', 'tbl_name_update': 'event_person', 'base_name': Event_Person_Base}
|
||||||
|
obj_type_kv_li['event_person_tracking'] = {'table_name': 'v_event_person_tracking', 'tbl_name_update': 'event_person_tracking', 'base_name': Event_Person_Tracking_Base}
|
||||||
|
obj_type_kv_li['event_presentation'] = {'table_name': 'v_event_presentation', 'tbl_name_update': 'event_presentation', 'base_name': Event_Presentation_Base}
|
||||||
|
obj_type_kv_li['event_presenter'] = {'table_name': 'v_event_presenter', 'tbl_name_update': 'event_presenter', 'base_name': Event_Presenter_Base}
|
||||||
|
obj_type_kv_li['event_registration'] = {'table_name': 'v_event_registration', 'tbl_name_update': 'event_registration', 'base_name': Event_Registration_Base}
|
||||||
|
obj_type_kv_li['event_session'] = {'table_name': 'v_event_session', 'tbl_name_update': 'event_session', 'base_name': Event_Session_Base, 'exclude_for_db': {'poc_person_id', 'file_count', 'internal_use_count', 'enable_from', 'enable_to', 'event_name', 'event_start_datetime', 'event_end_datetime', 'event_location_name', 'event_track_name', 'event_abstract_list', 'event_badge_list', 'event_device_list', 'event_file_list', 'event_file_internal_use_list', 'event_location', 'event_location_list', 'event_person_list', 'event_presenter_cat', 'event_presentation_list', 'event_presenter_list', 'event_track', 'poc_event_person'}}
|
||||||
|
obj_type_kv_li['event_track'] = {'table_name': 'v_event_track', 'tbl_name_update': 'event_track', 'base_name': Event_Track_Base}
|
||||||
|
|
||||||
|
obj_type_kv_li['grant'] = {'table_name': 'v_grant', 'tbl_name_update': 'grant', 'base_name': Grant_Base}
|
||||||
|
|
||||||
|
obj_type_kv_li['journal'] = {'table_name': 'v_journal', 'tbl_name_update': 'journal', 'base_name': Journal_Base}
|
||||||
|
obj_type_kv_li['journal_entry'] = {'table_name': 'v_journal_entry', 'tbl_name_update': 'journal_entry', 'base_name': Journal_Entry_Base}
|
||||||
|
#obj_type_kv_li['log'] = {'table_name': 'log', 'tbl_name_update': 'log', 'base_name': Log_Base} #'v_log'
|
||||||
|
|
||||||
|
obj_type_kv_li['membership_cfg'] = {'table_name': 'v_membership_cfg', 'tbl_name_update': 'membership_cfg', 'base_name': Membership_Cfg_Base}
|
||||||
|
obj_type_kv_li['membership_group'] = {'table_name': 'v_membership_group', 'tbl_name_update': 'membership_group', 'base_name': Membership_Group_Base}
|
||||||
|
obj_type_kv_li['membership_person_group'] = {'table_name': 'v_membership_person_group', 'tbl_name_update': 'membership_person_group', 'base_name': Membership_Person_Group_Base}
|
||||||
|
obj_type_kv_li['membership_person'] = {'table_name': 'v_membership_person', 'tbl_name_update': 'membership_person', 'base_name': Membership_Person_Base}
|
||||||
|
obj_type_kv_li['membership_person_profile'] = {'table_name': 'v_membership_person_profile', 'tbl_name_update': 'membership_person_profile', 'base_name': Membership_Person_Profile_Base}
|
||||||
|
obj_type_kv_li['membership_type'] = {'table_name': 'v_membership_type', 'tbl_name_update': 'membership_type', 'base_name': Membership_Type_Base}
|
||||||
|
obj_type_kv_li['membership_person_type'] = {'table_name': 'v_membership_person_type', 'tbl_name_update': 'membership_person_type', 'base_name': Membership_Person_Type_Base}
|
||||||
|
|
||||||
|
#obj_type_kv_li['message'] = {'table_name': 'message', 'tbl_name_update': 'message', 'base_name': Message_Base} #'v_message'
|
||||||
|
|
||||||
|
obj_type_kv_li['post'] = {'table_name': 'v_post', 'tbl_name_update': 'post', 'base_name': Post_Base} # NOTE check view name: *_detail?
|
||||||
|
obj_type_kv_li['post_comment'] = {'table_name': 'v_post_comment', 'tbl_name_update': 'post_comment', 'base_name': Post_Comment_Base} # NOTE check view name: *_detail?
|
||||||
|
obj_type_kv_li['product'] = {'table_name': 'v_product', 'tbl_name_update': 'product', 'base_name': Product_Base}
|
||||||
|
|
||||||
|
|
||||||
|
#obj_type_kv_li['stripe_customer'] = {'table_name': 'stripe_customer', 'tbl_name_update': 'stripe_customer', 'base_name': Stripe_Customer_Base}
|
||||||
|
obj_type_kv_li['stripe_log'] = {'table_name': 'stripe_log', 'tbl_name_update': 'stripe_log', 'base_name': Stripe_Log_Base_In}
|
||||||
|
|
||||||
|
# obj_type_kv_li['c_idda_membership_person_profile'] = {'table_name': 'c_idda_membership_person_profile', 'base_name': C_Idda_membership_person_profile_Base}
|
||||||
|
# obj_type_kv_li['c_osit_demo_membership_person_profile'] = {'table_name': 'c_osit_demo_membership_person_profile', 'base_name': C_Osit_Demo_membership_person_profile_Base}
|
||||||
@@ -349,7 +349,7 @@ def create_export_file(
|
|||||||
rm_id: bool = True,
|
rm_id: bool = True,
|
||||||
export_type: str = 'CSV', # CSV, Excel
|
export_type: str = 'CSV', # CSV, Excel
|
||||||
) -> bool|str:
|
) -> bool|str:
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(locals())
|
log.debug(locals())
|
||||||
|
|
||||||
hosted_tmp_path = settings.FILES_PATH['hosted_tmp_root']
|
hosted_tmp_path = settings.FILES_PATH['hosted_tmp_root']
|
||||||
@@ -375,8 +375,7 @@ def create_export_file(
|
|||||||
if column_name.endswith('_id'):
|
if column_name.endswith('_id'):
|
||||||
column_name_li.remove(column_name)
|
column_name_li.remove(column_name)
|
||||||
log.info(f'Removing column name: {column_name}')
|
log.info(f'Removing column name: {column_name}')
|
||||||
log.debug(column_name_li)
|
log.info(column_name_li)
|
||||||
|
|
||||||
|
|
||||||
# column_name_li = ['order_line_id_random', 'order_id_random', 'product_id_random', 'product_type', 'product_name', 'quantity', 'amount', 'dollar_amount', 'message', 'person_id_random', 'person_given_name', 'person_family_name', 'person_display_name', 'person_full_name', 'person_contact_email', 'person_contact_cc_email', 'person_contact_address_name', 'person_contact_address_organization_name', 'person_contact_address_line_1', 'person_contact_address_line_2', 'person_contact_address_line_3', 'person_contact_address_city', 'person_contact_address_country_subdivision_code', 'person_contact_address_state_province', 'person_contact_address_postal_code', 'person_contact_address_country_alpha_2_code', 'person_contact_address_country_name', 'person_contact_address_country', 'order_status', 'order_created_on', 'order_updated_on']
|
# column_name_li = ['order_line_id_random', 'order_id_random', 'product_id_random', 'product_type', 'product_name', 'quantity', 'amount', 'dollar_amount', 'message', 'person_id_random', 'person_given_name', 'person_family_name', 'person_display_name', 'person_full_name', 'person_contact_email', 'person_contact_cc_email', 'person_contact_address_name', 'person_contact_address_organization_name', 'person_contact_address_line_1', 'person_contact_address_line_2', 'person_contact_address_line_3', 'person_contact_address_city', 'person_contact_address_country_subdivision_code', 'person_contact_address_state_province', 'person_contact_address_postal_code', 'person_contact_address_country_alpha_2_code', 'person_contact_address_country_name', 'person_contact_address_country', 'order_status', 'order_created_on', 'order_updated_on']
|
||||||
|
|
||||||
|
|||||||
12
app/main.py
12
app/main.py
@@ -18,7 +18,7 @@ from . import config
|
|||||||
from app.log import log, logging
|
from app.log import log, logging
|
||||||
|
|
||||||
# Import the routers here first:
|
# Import the routers here first:
|
||||||
from app.routers import aether_cfg, api_crud, api, importing, sql, account, activity_log, address, archive, archive_content, contact, cont_edu_cert, cont_edu_cert_person, data_store, event, event_abstract, event_badge, event_badge_importing, event_badge_template, event_device, event_exhibit, event_exhibit_tracking, event_file, event_importing, event_location, event_person, event_person_detail, event_person_tracking, event_presentation, event_presenter, event_registration, event_session, flask_cfg, fundraising, grant, hosted_file, journal, journal_entry, log_client_viewing, lookup, membership_cfg, membership_group, membership_person_group, membership_person, membership_person_profile, membership_type, membership_person_type, order, order_v3, order_line, order_cart, organization, page, person, person_user, post, post_comment, product, qr, site, site_domain, user, util_email, websockets_redis, e_confex, e_cvent, c_idaa, e_impexium, e_stripe
|
from app.routers import aether_cfg, api_crud, api_crud_v2, api, importing, sql, account, activity_log, address, archive, archive_content, contact, cont_edu_cert, cont_edu_cert_person, data_store, event, event_abstract, event_badge, event_badge_importing, event_badge_template, event_device, event_exhibit, event_exhibit_tracking, event_file, event_importing, event_location, event_person, event_person_detail, event_person_tracking, event_presentation, event_presenter, event_registration, event_session, flask_cfg, fundraising, grant, hosted_file, journal, journal_entry, log_client_viewing, lookup, membership_cfg, membership_group, membership_person_group, membership_person, membership_person_profile, membership_type, membership_person_type, order, order_v3, order_line, order_cart, organization, page, person, person_user, post, post_comment, product, qr, site, site_domain, user, util_email, websockets_redis, e_confex, e_cvent, c_idaa, e_impexium, e_stripe
|
||||||
|
|
||||||
# from app.routers import aether_cfg, sql
|
# from app.routers import aether_cfg, sql
|
||||||
|
|
||||||
@@ -98,7 +98,15 @@ app.include_router(
|
|||||||
app.include_router(
|
app.include_router(
|
||||||
api_crud.router,
|
api_crud.router,
|
||||||
prefix='/crud',
|
prefix='/crud',
|
||||||
tags=['CRUD'],
|
tags=['CRUD v1 (Legacy)'],
|
||||||
|
#dependencies=[Depends(get_token_header)],
|
||||||
|
#dependencies=[Depends(get_account_header)],
|
||||||
|
#responses={404: {'description': 'Not found'}},
|
||||||
|
)
|
||||||
|
app.include_router(
|
||||||
|
api_crud_v2.router,
|
||||||
|
prefix='/v2/crud',
|
||||||
|
tags=['CRUD v2'],
|
||||||
#dependencies=[Depends(get_token_header)],
|
#dependencies=[Depends(get_token_header)],
|
||||||
#dependencies=[Depends(get_account_header)],
|
#dependencies=[Depends(get_account_header)],
|
||||||
#responses={404: {'description': 'Not found'}},
|
#responses={404: {'description': 'Not found'}},
|
||||||
|
|||||||
@@ -106,6 +106,8 @@ class Site_Domain_FQDN_ID_Base(BaseModel):
|
|||||||
# This is only for convenience. Probably going to keep unless it causes a problem.
|
# This is only for convenience. Probably going to keep unless it causes a problem.
|
||||||
# account_id: Optional[int]
|
# account_id: Optional[int]
|
||||||
account_id_random: Optional[str]
|
account_id_random: Optional[str]
|
||||||
|
account_code: Optional[str] # Useful for export file naming
|
||||||
|
account_name: Optional[str] # Generally useful for display
|
||||||
account_enable: Optional[bool]
|
account_enable: Optional[bool]
|
||||||
account_enable_from: Optional[datetime.datetime]
|
account_enable_from: Optional[datetime.datetime]
|
||||||
account_enable_to: Optional[datetime.datetime]
|
account_enable_to: Optional[datetime.datetime]
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import datetime, json, time
|
import datetime, json, time
|
||||||
#from datetime import datetime, time, timedelta
|
#from datetime import datetime, time, timedelta
|
||||||
from fastapi import APIRouter, Body, Depends, Header, HTTPException, Query, Response, status
|
from fastapi import APIRouter, Body, Depends, Header, HTTPException, Query, Response, status
|
||||||
|
from fastapi.responses import FileResponse
|
||||||
from pydantic import BaseModel, EmailStr, Field
|
from pydantic import BaseModel, EmailStr, Field
|
||||||
from typing import Dict, List, Optional, Set, Union
|
from typing import Dict, List, Optional, Set, Union
|
||||||
|
|
||||||
@@ -65,7 +66,8 @@ from app.models.user_role_models import *
|
|||||||
|
|
||||||
from app.models.e_stripe_models import *
|
from app.models.e_stripe_models import *
|
||||||
|
|
||||||
obj_type_li = {}
|
obj_type_kv_li = {} # New 2024-04-23
|
||||||
|
obj_type_li = {} # Old...
|
||||||
|
|
||||||
#obj_type_li['cfg_flask'] = {'table_name': 'cfg_flask', 'base_name': Cfg_Flask_Base}
|
#obj_type_li['cfg_flask'] = {'table_name': 'cfg_flask', 'base_name': Cfg_Flask_Base}
|
||||||
|
|
||||||
@@ -178,7 +180,7 @@ obj_type_li['post'] = {'table_name': 'v_post', 'tbl_name_update': 'post', 'base_
|
|||||||
obj_type_li['post_comment'] = {'table_name': 'v_post_comment', 'tbl_name_update': 'post_comment', 'base_name': Post_Comment_Base} # NOTE check view name: *_detail?
|
obj_type_li['post_comment'] = {'table_name': 'v_post_comment', 'tbl_name_update': 'post_comment', 'base_name': Post_Comment_Base} # NOTE check view name: *_detail?
|
||||||
obj_type_li['product'] = {'table_name': 'v_product', 'tbl_name_update': 'product', 'base_name': Product_Base}
|
obj_type_li['product'] = {'table_name': 'v_product', 'tbl_name_update': 'product', 'base_name': Product_Base}
|
||||||
|
|
||||||
obj_type_li['sponsorship'] = {'table_name': 'v_sponsorship', 'tbl_name_update': 'sponsorship', 'base_name': Sponsorship_Base} # NOTE check view name: *_detail?
|
obj_type_li['sponsorship'] = {'table_name': 'v_sponsorship', 'tbl_name_update': 'sponsorship', 'base_name': Sponsorship_Base, 'tbl': 'v_sponsorship', 'tbl': 'v_sponsorship', 'mdl': Sponsorship_Base } # NOTE check view name: *_detail?
|
||||||
obj_type_li['sponsorship_cfg'] = {'table_name': 'v_sponsorship_cfg', 'tbl_name_update': 'sponsorship_cfg', 'base_name': Sponsorship_Cfg_Base}
|
obj_type_li['sponsorship_cfg'] = {'table_name': 'v_sponsorship_cfg', 'tbl_name_update': 'sponsorship_cfg', 'base_name': Sponsorship_Cfg_Base}
|
||||||
|
|
||||||
#obj_type_li['stripe_customer'] = {'table_name': 'stripe_customer', 'tbl_name_update': 'stripe_customer', 'base_name': Stripe_Customer_Base}
|
#obj_type_li['stripe_customer'] = {'table_name': 'stripe_customer', 'tbl_name_update': 'stripe_customer', 'base_name': Stripe_Customer_Base}
|
||||||
@@ -230,6 +232,9 @@ async def get_obj_li(
|
|||||||
# Get the "json" param from the query string. This is a JSON formatted string of the data to be inserted.
|
# Get the "json" param from the query string. This is a JSON formatted string of the data to be inserted.
|
||||||
jp: Optional[Union[str, None]] = None,
|
jp: Optional[Union[str, None]] = None,
|
||||||
|
|
||||||
|
file_type: str = 'CSV', # CSV, Excel
|
||||||
|
return_file: Optional[bool] = False,
|
||||||
|
|
||||||
commons: Common_Route_Params = Depends(common_route_params),
|
commons: Common_Route_Params = Depends(common_route_params),
|
||||||
):
|
):
|
||||||
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
@@ -396,6 +401,7 @@ async def get_obj_li(
|
|||||||
|
|
||||||
if sql_result:
|
if sql_result:
|
||||||
if isinstance(sql_result, list):
|
if isinstance(sql_result, list):
|
||||||
|
log.setLevel(logging.DEBUG)
|
||||||
resp_data_li = []
|
resp_data_li = []
|
||||||
for record in sql_result:
|
for record in sql_result:
|
||||||
if base_name:
|
if base_name:
|
||||||
@@ -405,7 +411,91 @@ async def get_obj_li(
|
|||||||
log.warning('base_name model was not found. Returning raw data.')
|
log.warning('base_name model was not found. Returning raw data.')
|
||||||
resp_data = record
|
resp_data = record
|
||||||
resp_data_li.append(resp_data)
|
resp_data_li.append(resp_data)
|
||||||
return mk_resp(data=resp_data_li, response=commons.response)
|
column_name_li = list(sql_result[0].keys()) # This should be the same for all records in the list.
|
||||||
|
|
||||||
|
if return_file:
|
||||||
|
log.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
|
# We want to handle any field that has a suffix of _json. It should be expanded into a list of fields that are prefixed with the original field name minus _json.
|
||||||
|
# This will also allow us to export the data to a CSV or Excel file with the correct column names.
|
||||||
|
# additional_json_field_list_for_export = []
|
||||||
|
new_resp_data_li = []
|
||||||
|
for record in resp_data_li:
|
||||||
|
new_record = record.copy()
|
||||||
|
for field_name in record.keys():
|
||||||
|
field_value = record[field_name]
|
||||||
|
if field_name.endswith('li_json') and record[field_name]:
|
||||||
|
log.info(f'Found a field that ends with li_json: {field_name}')
|
||||||
|
log.info(f'Field value is a list??: {field_value}')
|
||||||
|
|
||||||
|
# field_value = json.loads(record[key]) # Convert the string to a list of dictionaries
|
||||||
|
|
||||||
|
|
||||||
|
# Example JSON data: {'facebook': 'https://www.facebook.com/example', 'twitter': 'https://twitter.com/example', 'instagram': 'https://www.instagram.com/example/', 'linkedin': 'https://www.linkedin.com/school/example', 'org': 'https://example.com/'}
|
||||||
|
# Example new fields: social__facebook, social__twitter, social__instagram, social__linkedin, social__org
|
||||||
|
|
||||||
|
if isinstance(field_value, list):
|
||||||
|
# Loop through the list of dictionaries
|
||||||
|
log.info(f'Field value is a list: {field_value}')
|
||||||
|
for item in field_value:
|
||||||
|
# item = json.loads(item) # Convert the string to a dictionary
|
||||||
|
for key, value in item.items():
|
||||||
|
new_field_name = field_name[:-8]+'__'+key
|
||||||
|
new_record[new_field_name] = value
|
||||||
|
else:
|
||||||
|
# Loop through key value pairs in the dictionary
|
||||||
|
log.info(f'Field value is a dict: {field_value}')
|
||||||
|
for key, value in field_value.items():
|
||||||
|
new_field_name = field_name[:-8]+'__'+key
|
||||||
|
new_record[new_field_name] = value
|
||||||
|
|
||||||
|
# Create a new field for each and value to the record
|
||||||
|
# new_field_name = key[:-8]+'__cust_li'
|
||||||
|
# new_record[new_field_name] = record[key]
|
||||||
|
|
||||||
|
new_record.pop(field_name) # Remove the original field
|
||||||
|
elif field_name.endswith('_json') and record[field_name]:
|
||||||
|
log.info(f'Found a field that ends with _json: {field_name}')
|
||||||
|
log.info(f'Field value is a dict???: {field_value}')
|
||||||
|
|
||||||
|
for key, value in field_value.items():
|
||||||
|
new_field_name = field_name[:-5]+'__'+key
|
||||||
|
new_record[new_field_name] = value
|
||||||
|
|
||||||
|
new_record.pop(field_name) # Remove the original field
|
||||||
|
elif field_name.endswith('li_json') or field_name.endswith('_json'):
|
||||||
|
log.info(f'Found a field that ends with li_json or _json but no value: {field_name}')
|
||||||
|
|
||||||
|
new_record.pop(field_name) # Remove the original field
|
||||||
|
new_resp_data_li.append(new_record)
|
||||||
|
|
||||||
|
|
||||||
|
datetime_format='%Y-%m-%d_%H%M'
|
||||||
|
|
||||||
|
# current_datetime = datetime.datetime.now() # Servers timezone (Eastern)
|
||||||
|
current_datetime_utc = datetime.datetime.utcnow() # UTC timezone
|
||||||
|
current_datetime_utc = current_datetime_utc.strftime(datetime_format)
|
||||||
|
filename = f'{obj_name}_list_{current_datetime_utc}'
|
||||||
|
if file_type == 'CSV':
|
||||||
|
filename_w_ext = filename+'.csv'
|
||||||
|
elif file_type == 'Excel':
|
||||||
|
filename_w_ext = filename+'.xlsx'
|
||||||
|
|
||||||
|
log.setLevel(logging.INFO)
|
||||||
|
if result := create_export_file(data_dict_list=new_resp_data_li, column_name_li=[], subdir_path=obj_name, filename=filename, rm_id=True, export_type=file_type):
|
||||||
|
log.info(f'Export file created and saved: {result}')
|
||||||
|
else:
|
||||||
|
log.error('Something went wrong while creating or saving the export file')
|
||||||
|
tmp_file_path = result
|
||||||
|
|
||||||
|
log.info(f'Filename: {filename_w_ext}')
|
||||||
|
if full_tmp_path := return_full_tmp_path(full_tmp_path=tmp_file_path):
|
||||||
|
return FileResponse(path=full_tmp_path, filename=filename_w_ext)
|
||||||
|
|
||||||
|
else:
|
||||||
|
return mk_resp(data=resp_data_li, response=commons.response)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
status_message='Not Implemented (sort of). Attempted to process this request. Got a SQL result, but the returned data was unexpected.'
|
status_message='Not Implemented (sort of). Attempted to process this request. Got a SQL result, but the returned data was unexpected.'
|
||||||
|
|
||||||
@@ -1227,3 +1317,22 @@ def delete_obj_template(
|
|||||||
else:
|
else:
|
||||||
log.debug(sql_result)
|
log.debug(sql_result)
|
||||||
return mk_resp(data=False, status_code=404, response=response)
|
return mk_resp(data=False, status_code=404, response=response)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# New dynamic API CRUD endpoint
|
||||||
|
# The POST data should be JSON formatted
|
||||||
|
# @router.post('/query')
|
||||||
|
# def query(
|
||||||
|
# # qry JSON should contain these properties:
|
||||||
|
# # list: for_obj_type, for_obj_id, tbl_view_name, base_name
|
||||||
|
# # id: obj_id, tbl_view_name, base_name
|
||||||
|
# qry: str,
|
||||||
|
|
||||||
|
# commons: Common_Route_Params = Depends(common_route_params),
|
||||||
|
|
||||||
|
# ):
|
||||||
|
# log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
# log.debug(locals())
|
||||||
|
|
||||||
|
# import urllib
|
||||||
|
|||||||
1180
app/routers/api_crud_v2.py
Normal file
1180
app/routers/api_crud_v2.py
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user