General code clean up
This commit is contained in:
@@ -1264,7 +1264,7 @@ def get_account_id_w_for_type_id(
|
||||
# ### BEGIN ### API DB SQL Methods ### sql_enable_part() ###
|
||||
# Updated 2022-01-17
|
||||
@logger_reset
|
||||
def sql_enable_part(table_name:str, enabled: str) -> bool|dict:
|
||||
def sql_enable_part(table_name: str, enabled: str) -> bool|dict:
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
|
||||
@@ -93,13 +93,13 @@ async def common_route_params(
|
||||
# ### END ### API Lib General ### async route_commons() ###
|
||||
|
||||
|
||||
def secure_hash_string(string:str):
|
||||
def secure_hash_string(string: str):
|
||||
string_hash = argon2.using(rounds=14, memory_cost=1536, parallelism=2).hash(string)
|
||||
|
||||
return string_hash
|
||||
|
||||
|
||||
def verify_secure_hash_string(string:str, string_hash:str):
|
||||
def verify_secure_hash_string(string: str, string_hash: str):
|
||||
if argon2.verify(string, string_hash):
|
||||
return True
|
||||
else:
|
||||
@@ -235,7 +235,7 @@ def create_export_file(
|
||||
# Updated 2021-12-02
|
||||
@logger_reset
|
||||
def send_email(
|
||||
from_email:str,
|
||||
from_email: str,
|
||||
to_email: str,
|
||||
subject: str,
|
||||
body_html: str,
|
||||
|
||||
@@ -14,7 +14,7 @@ from app.models.common_field_schema import default_num_bytes
|
||||
# ### BEGIN ### API Address Methods ### load_address_obj() ###
|
||||
@logger_reset
|
||||
def load_address_obj(
|
||||
address_id:int|str,
|
||||
address_id: int|str,
|
||||
enabled: str = 'enabled', # enabled, disabled, all # Probably not needed for the address
|
||||
limit: int = 100, # Probably not needed for the address
|
||||
offset: int = 0,
|
||||
|
||||
@@ -100,13 +100,13 @@ async def get_file_object_hash(file_object:File):
|
||||
|
||||
|
||||
# ### BEGIN ### API Hosted File Route ### guess_file_extension() ###
|
||||
def guess_file_extension(filename:str):
|
||||
def guess_file_extension(filename: str):
|
||||
return filename.rsplit('.', 1)[1].lower()
|
||||
# ### END ### API Hosted File Route ### guess_file_extension() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Hosted File Route ### allowed_file_extension() ###
|
||||
def allowed_file_extension(extension:str, extension_list:list):
|
||||
def allowed_file_extension(extension: str, extension_list: list):
|
||||
return extension.lower() in extension_list # app.config['ALLOWED_EXTENSIONS']
|
||||
# ### END ### API Hosted File Route ### allowed_file_extension() ###
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ from app.models.membership_person_models import Membership_Person_Base
|
||||
# ### BEGIN ### API Membership Person Methods ### load_membership_person_obj() ###
|
||||
# Updated 2022-01-11
|
||||
def load_membership_person_obj(
|
||||
membership_person_id:int|str,
|
||||
membership_person_id: int|str,
|
||||
limit: int = 100,
|
||||
by_alias: bool = True,
|
||||
exclude_unset: bool = True,
|
||||
|
||||
@@ -16,7 +16,7 @@ from app.models.membership_type_models import Membership_Type_Base
|
||||
|
||||
# ### BEGIN ### API Membership Type Methods ### load_membership_type_obj() ###
|
||||
def load_membership_type_obj(
|
||||
membership_type_id:int|str,
|
||||
membership_type_id: int|str,
|
||||
limit: int = 1000,
|
||||
by_alias: bool = True,
|
||||
exclude_unset: bool = True,
|
||||
|
||||
@@ -43,8 +43,8 @@ def update_order_cart_obj(
|
||||
log.info('Loop through lines to update and calculate totals')
|
||||
|
||||
# Calculate totals
|
||||
order_cart_total_amount:int = 0
|
||||
order_cart_total_quantity:int = 0
|
||||
order_cart_total_amount: int = 0
|
||||
order_cart_total_quantity: int = 0
|
||||
for order_cart_line_obj in order_cart_obj.order_cart_line_list:
|
||||
log.debug(order_cart_line_obj)
|
||||
|
||||
|
||||
@@ -369,7 +369,7 @@ def get_order_id_cart_for_person_id_v3(
|
||||
|
||||
# ### BEGIN ### API Order Methods ### save_order_obj() ###
|
||||
# @logger_reset
|
||||
def save_order_obj(order_obj_new:Order_Base, repl_order_line_li:bool=False):
|
||||
def save_order_obj(order_obj_new:Order_Base, repl_order_line_li: bool=False):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
@@ -466,8 +466,8 @@ def save_order_obj(order_obj_new:Order_Base, repl_order_line_li:bool=False):
|
||||
|
||||
# Final loop through to get the new order totals
|
||||
# Calculate totals
|
||||
order_total_amount:int = 0
|
||||
order_total_quantity:int = 0
|
||||
order_total_amount: int = 0
|
||||
order_total_quantity: int = 0
|
||||
for order_line_obj_new in order_obj_new.order_line_li:
|
||||
order_total_amount += order_line_obj_new.quantity * order_line_obj_new.amount
|
||||
order_total_quantity += order_line_obj_new.quantity
|
||||
|
||||
@@ -16,14 +16,14 @@ from app.models.organization_models import Organization_Base
|
||||
# ### BEGIN ### API Organization Methods ### load_organization_obj() ###
|
||||
# NOTE: This needs to be updated to the newer method template. Like address, contact, or person -STI 2021-06-10
|
||||
def load_organization_obj(
|
||||
organization_id:int|str,
|
||||
organization_id: int|str,
|
||||
limit: int = 1000,
|
||||
by_alias: bool = True,
|
||||
exclude_unset: bool = True,
|
||||
model_as_dict: bool = False,
|
||||
enabled: str = 'enabled', # enabled, disabled, all
|
||||
inc_contact:bool=False,
|
||||
inc_address:bool=False
|
||||
inc_contact: bool=False,
|
||||
inc_address: bool=False
|
||||
) -> Organization_Base|bool:
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
@@ -387,10 +387,10 @@ async def delete_obj(
|
||||
|
||||
|
||||
def post_obj_template(
|
||||
obj_type:str,
|
||||
data:dict,
|
||||
return_obj:bool=True,
|
||||
by_alias:bool=True,
|
||||
obj_type: str,
|
||||
data: dict,
|
||||
return_obj: bool=True,
|
||||
by_alias: bool=True,
|
||||
include: Optional[list] = [],
|
||||
exclude: Optional[list] = [],
|
||||
exclude_unset: Optional[bool] = True,
|
||||
@@ -427,11 +427,11 @@ def post_obj_template(
|
||||
|
||||
|
||||
def patch_obj_template(
|
||||
obj_type:str,
|
||||
data:dict,
|
||||
obj_id:str,
|
||||
return_obj:bool=True,
|
||||
by_alias:bool=True,
|
||||
obj_type: str,
|
||||
data: dict,
|
||||
obj_id: str,
|
||||
return_obj: bool=True,
|
||||
by_alias: bool=True,
|
||||
include: Optional[list] = [],
|
||||
exclude: Optional[list] = [],
|
||||
exclude_unset: Optional[bool] = True,
|
||||
|
||||
@@ -42,7 +42,7 @@ async def event_importing_create_update_w_external_id(
|
||||
event_id = 1438 # CMSC 2021 1438 8nMUlA93Ybw
|
||||
full_file_path = 'admin/temp/import_event_program_external_id.csv'
|
||||
|
||||
df = pandas.read_csv(full_file_path, na_filter=False, dtype={'external_id':str, 'External ID':str, 'event_presentation_external_id':str, 'event_presentation_code':str, 'event_presentation_sort':int, 'event_presenter_external_id':str, 'event_presenter_code':str, 'event_presenter_designations':str, 'event_presenter_sort':int, 'event_session_external_id':str, 'event_session_code':str, 'event_session_sort':int, 'source_id':str, 'Source ID':str, 'email':str, 'Email Address':str})
|
||||
df = pandas.read_csv(full_file_path, na_filter=False, dtype={'external_id': str, 'External ID': str, 'event_presentation_external_id': str, 'event_presentation_code': str, 'event_presentation_sort': int, 'event_presenter_external_id': str, 'event_presenter_code': str, 'event_presenter_designations': str, 'event_presenter_sort': int, 'event_session_external_id': str, 'event_session_code': str, 'event_session_sort': int, 'source_id': str, 'Source ID': str, 'email': str, 'Email Address': str})
|
||||
log.debug(df)
|
||||
|
||||
df_dict = df.to_dict(orient='records')
|
||||
|
||||
@@ -86,7 +86,7 @@ async def importing_update_w_external_id(
|
||||
|
||||
log.info(f'Starting import for Account ID {account_id} File Name: {full_file_path}')
|
||||
|
||||
df = pandas.read_csv(full_file_path, na_filter=False, dtype={'external_id':str, 'External ID':str, 'source_id':str, 'Source ID':str, 'email':str, 'Email Address':str})
|
||||
df = pandas.read_csv(full_file_path, na_filter=False, dtype={'external_id': str, 'External ID': str, 'source_id': str, 'Source ID': str, 'email': str, 'Email Address': str})
|
||||
log.debug(df)
|
||||
|
||||
df_dict = df.to_dict(orient='records')
|
||||
@@ -199,18 +199,18 @@ async def ins_up_person_contact_address_user_data(
|
||||
|
||||
df = pandas.read_csv(
|
||||
full_file_path, na_filter=False,
|
||||
dtype={'external_id':str,
|
||||
'External ID':str,
|
||||
'source_id':str,
|
||||
'Source ID':str,
|
||||
'email':str,
|
||||
'Email Address':str,
|
||||
'phone_home':str,
|
||||
'phone_mobile':str,
|
||||
'city':str,
|
||||
'state_province':str,
|
||||
'address_postal_code':str,
|
||||
'country':str})
|
||||
dtype={'external_id': str,
|
||||
'External ID': str,
|
||||
'source_id': str,
|
||||
'Source ID': str,
|
||||
'email': str,
|
||||
'Email Address': str,
|
||||
'phone_home': str,
|
||||
'phone_mobile': str,
|
||||
'city': str,
|
||||
'state_province': str,
|
||||
'address_postal_code': str,
|
||||
'country': str})
|
||||
#df = df.fillna('') # replace NaN with ''
|
||||
# df = df.fillna(None)
|
||||
# df = df.fillna('', inplace=True)
|
||||
@@ -759,18 +759,18 @@ async def ins_up_membership_person_data(
|
||||
|
||||
df = pandas.read_csv(
|
||||
full_file_path, na_filter=False,
|
||||
dtype={'external_id':str,
|
||||
'External ID':str,
|
||||
'source_id':str,
|
||||
'Source ID':str,
|
||||
'email':str,
|
||||
'Email Address':str,
|
||||
'phone_home':str,
|
||||
'phone_mobile':str,
|
||||
'city':str,
|
||||
'state_province':str,
|
||||
'address_postal_code':str,
|
||||
'country':str})
|
||||
dtype={'external_id': str,
|
||||
'External ID': str,
|
||||
'source_id': str,
|
||||
'Source ID': str,
|
||||
'email': str,
|
||||
'Email Address': str,
|
||||
'phone_home': str,
|
||||
'phone_mobile': str,
|
||||
'city': str,
|
||||
'state_province': str,
|
||||
'address_postal_code': str,
|
||||
'country': str})
|
||||
|
||||
df.rename(columns={
|
||||
'Source ID': 'source_id',
|
||||
@@ -1096,7 +1096,7 @@ async def importing_person_data(
|
||||
account_id = 99
|
||||
full_file_path = 'admin/temp/import_person_data.xlsx'
|
||||
|
||||
df = pandas.read_excel(full_file_path, na_filter=False, dtype={'external_import_id':str, 'phone_home':str, 'phone_mobile':str, 'city':str, 'state_province':str, 'address_postal_code':str, 'country':str})
|
||||
df = pandas.read_excel(full_file_path, na_filter=False, dtype={'external_import_id': str, 'phone_home': str, 'phone_mobile': str, 'city': str, 'state_province': str, 'address_postal_code': str, 'country': str})
|
||||
#df = df.fillna('') # replace NaN with ''
|
||||
# df = df.fillna(None)
|
||||
# df = df.fillna('', inplace=True)
|
||||
@@ -1417,7 +1417,7 @@ async def importing_cont_edu_cert_person_data(
|
||||
cont_edu_cert_id = 3
|
||||
full_file_path = 'admin/temp/import_cont_edu_cert_person_data.xlsx'
|
||||
|
||||
df = pandas.read_excel(full_file_path, na_filter=False, dtype={'external_import_id':str, 'phone_home':str, 'phone_mobile':str, 'city':str, 'state_province':str, 'address_postal_code':str, 'country':str})
|
||||
df = pandas.read_excel(full_file_path, na_filter=False, dtype={'external_import_id': str, 'phone_home': str, 'phone_mobile': str, 'city': str, 'state_province': str, 'address_postal_code': str, 'country': str})
|
||||
log.debug(df)
|
||||
|
||||
df_dict = df.to_dict(orient='records')
|
||||
@@ -1549,7 +1549,7 @@ async def importing_cont_edu_cert_person_data_touch(
|
||||
cont_edu_cert_id = 3
|
||||
full_file_path = 'admin/temp/import_cont_edu_cert_person_data.xlsx'
|
||||
|
||||
df = pandas.read_excel(full_file_path, na_filter=False, dtype={'external_import_id':str, 'phone_home':str, 'phone_mobile':str, 'city':str, 'state_province':str, 'address_postal_code':str, 'country':str})
|
||||
df = pandas.read_excel(full_file_path, na_filter=False, dtype={'external_import_id': str, 'phone_home': str, 'phone_mobile': str, 'city': str, 'state_province': str, 'address_postal_code': str, 'country': str})
|
||||
log.debug(df)
|
||||
|
||||
df_dict = df.to_dict(orient='records')
|
||||
|
||||
Reference in New Issue
Block a user