Working on all module routes, methods, and models
This commit is contained in:
@@ -117,7 +117,7 @@ def load_account_obj(
|
|||||||
inc_user_list: bool = False, # Priority l2
|
inc_user_list: bool = False, # Priority l2
|
||||||
inc_user_role_list: bool = False,
|
inc_user_role_list: bool = False,
|
||||||
) -> Account_Base|dict|bool:
|
) -> Account_Base|dict|bool:
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(locals())
|
log.debug(locals())
|
||||||
|
|
||||||
if account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'): pass
|
if account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'): pass
|
||||||
@@ -291,7 +291,7 @@ def load_account_obj(
|
|||||||
inc_journal_entry_list = inc_journal_entry_list,
|
inc_journal_entry_list = inc_journal_entry_list,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(journal_dict_list)
|
log.debug(journal_dict_list)
|
||||||
|
|
||||||
|
|
||||||
@@ -366,6 +366,7 @@ def load_account_obj(
|
|||||||
load_membership_type_obj(
|
load_membership_type_obj(
|
||||||
membership_type_id = membership_type_rec.get('membership_type_id', None),
|
membership_type_id = membership_type_rec.get('membership_type_id', None),
|
||||||
limit = limit,
|
limit = limit,
|
||||||
|
enabled = enabled,
|
||||||
by_alias = by_alias,
|
by_alias = by_alias,
|
||||||
exclude_unset = exclude_unset,
|
exclude_unset = exclude_unset,
|
||||||
model_as_dict = model_as_dict,
|
model_as_dict = model_as_dict,
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ from app.lib_general import log, logging
|
|||||||
# from app.methods.event_presenter_methods import load_event_presenter_obj
|
# from app.methods.event_presenter_methods import load_event_presenter_obj
|
||||||
# from app.methods.event_session_methods import load_event_session_obj
|
# from app.methods.event_session_methods import load_event_session_obj
|
||||||
# from app.methods.event_track_methods import load_event_track_obj
|
# from app.methods.event_track_methods import load_event_track_obj
|
||||||
# from app.methods.person_methods import load_person_obj
|
|
||||||
# from app.methods.user_methods import load_user_obj
|
|
||||||
|
|
||||||
from app.models.event_location_models import Event_Location_Base
|
from app.models.event_location_models import Event_Location_Base
|
||||||
|
|
||||||
|
|||||||
@@ -281,8 +281,8 @@ def load_membership_member_obj(
|
|||||||
by_alias = by_alias,
|
by_alias = by_alias,
|
||||||
exclude_unset = exclude_unset,
|
exclude_unset = exclude_unset,
|
||||||
model_as_dict = model_as_dict,
|
model_as_dict = model_as_dict,
|
||||||
inc_address = inc_address,
|
# inc_address = inc_address,
|
||||||
inc_contact = inc_contact,
|
# inc_contact = inc_contact,
|
||||||
# inc_organization = inc_organization,
|
# inc_organization = inc_organization,
|
||||||
# inc_person = inc_person,
|
# inc_person = inc_person,
|
||||||
):
|
):
|
||||||
@@ -304,7 +304,7 @@ def get_membership_member_rec_list(
|
|||||||
limit: int = 1000,
|
limit: int = 1000,
|
||||||
enabled: str = 'enabled', # enabled, disabled, all
|
enabled: str = 'enabled', # enabled, disabled, all
|
||||||
) -> list|bool:
|
) -> list|bool:
|
||||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(locals())
|
log.debug(locals())
|
||||||
|
|
||||||
if for_obj_id := redis_lookup_id_random(record_id_random=for_obj_id, table_name='for_obj_type'): pass
|
if for_obj_id := redis_lookup_id_random(record_id_random=for_obj_id, table_name='for_obj_type'): pass
|
||||||
|
|||||||
44
app/methods/order_cfg_methods.py
Normal file
44
app/methods/order_cfg_methods.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
from typing import Dict, List, Optional, Set, Union
|
||||||
|
from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, validator
|
||||||
|
|
||||||
|
from app.db_sql import redis_lookup_id_random, sql_select
|
||||||
|
from app.lib_general import log, logging
|
||||||
|
|
||||||
|
from app.models.order_cfg_models import Order_Cfg_Base
|
||||||
|
|
||||||
|
|
||||||
|
# ### BEGIN ### API Order Cfg Methods ### load_order_cfg_obj() ###
|
||||||
|
def load_order_cfg_obj(
|
||||||
|
account_id: int|str,
|
||||||
|
by_alias: bool = True,
|
||||||
|
exclude_unset: bool = True,
|
||||||
|
model_as_dict: bool = False,
|
||||||
|
) -> Order_Cfg_Base|dict|bool:
|
||||||
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
log.debug(locals())
|
||||||
|
|
||||||
|
if account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'): pass
|
||||||
|
else: return False
|
||||||
|
|
||||||
|
if order_cfg_rec := sql_select(
|
||||||
|
table_name = 'v_account_cfg_detail',
|
||||||
|
field_name = 'account_id',
|
||||||
|
field_value = account_id,
|
||||||
|
): pass
|
||||||
|
else: return False
|
||||||
|
log.debug(order_cfg_rec)
|
||||||
|
|
||||||
|
try:
|
||||||
|
order_cfg_obj = Order_Cfg_Base(**order_cfg_rec)
|
||||||
|
log.debug(order_cfg_obj)
|
||||||
|
except ValidationError as e:
|
||||||
|
log.error(e.json())
|
||||||
|
|
||||||
|
if model_as_dict:
|
||||||
|
return order_cfg_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset) # pylint: disable=no-member
|
||||||
|
else:
|
||||||
|
return order_cfg_obj
|
||||||
|
# ### END ### API Order Cfg Methods ### load_order_cfg_obj() ###
|
||||||
185
app/methods/order_line_methods.py
Normal file
185
app/methods/order_line_methods.py
Normal file
@@ -0,0 +1,185 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
from typing import Dict, List, Optional, Set, Union
|
||||||
|
from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, validator
|
||||||
|
|
||||||
|
from app.db_sql import redis_lookup_id_random, sql_insert, sql_select, sql_update
|
||||||
|
from app.lib_general import log, logging
|
||||||
|
|
||||||
|
|
||||||
|
from app.models.order_line_models import Order_Line_Base
|
||||||
|
|
||||||
|
|
||||||
|
# ### BEGIN ### API Order Line Methods ### create_order_line_obj() ###
|
||||||
|
def create_order_line_obj(order_line_obj_new:Order_Line_Base):
|
||||||
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
log.debug(locals())
|
||||||
|
|
||||||
|
if not order_line_obj_new:
|
||||||
|
return False
|
||||||
|
|
||||||
|
order_line_obj_data = order_line_obj_new.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'user', 'created_on', 'updated_on'})
|
||||||
|
|
||||||
|
if order_line_obj_in_result := sql_insert(data=order_line_obj_data, table_name='order_line', rm_id_random=True, id_random_length=8): pass
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
log.debug(order_line_obj_in_result)
|
||||||
|
|
||||||
|
order_line_id = order_line_obj_in_result
|
||||||
|
|
||||||
|
log.debug(f'Returning the new order_line_id: {order_line_id}')
|
||||||
|
return order_line_id
|
||||||
|
# ### END ### API Order Line Methods ### create_order_line_obj() ###
|
||||||
|
|
||||||
|
|
||||||
|
# ### BEGIN ### API Order Line Methods ### load_order_line_obj() ###
|
||||||
|
def load_order_line_obj(
|
||||||
|
order_line_id: int|str,
|
||||||
|
limit: int = 1000,
|
||||||
|
by_alias: bool = True,
|
||||||
|
exclude_unset: bool = True,
|
||||||
|
model_as_dict: bool = False,
|
||||||
|
) -> Order_Line_Base|dict|bool:
|
||||||
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
log.debug(locals())
|
||||||
|
|
||||||
|
if order_line_id := redis_lookup_id_random(record_id_random=order_line_id, table_name='order_line'): pass
|
||||||
|
else: return False
|
||||||
|
|
||||||
|
if order_line_rec := sql_select(table_name='v_order_line', record_id=order_line_id): pass
|
||||||
|
else: return False
|
||||||
|
|
||||||
|
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
log.debug(order_line_rec)
|
||||||
|
|
||||||
|
try:
|
||||||
|
order_line_obj = Order_Line_Base(**order_line_rec)
|
||||||
|
log.debug(order_line_obj)
|
||||||
|
except ValidationError as e:
|
||||||
|
log.error(e.json())
|
||||||
|
return False
|
||||||
|
|
||||||
|
if model_as_dict:
|
||||||
|
return order_line_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset) # pylint: disable=no-member
|
||||||
|
else:
|
||||||
|
return order_line_obj
|
||||||
|
# ### END ### API Order Line Methods ### load_order_line_obj() ###
|
||||||
|
|
||||||
|
|
||||||
|
# ### BEGIN ### API Order Line Methods ### update_order_line_obj() ###
|
||||||
|
def update_order_line_obj(
|
||||||
|
order_line_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
|
||||||
|
order_line_obj_up: Order_Line_Base,
|
||||||
|
create_missing_obj: bool = False,
|
||||||
|
) -> bool:
|
||||||
|
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
log.debug(locals())
|
||||||
|
|
||||||
|
if order_line_id := redis_lookup_id_random(record_id_random=order_line_id, table_name='order_line'): pass
|
||||||
|
else: return False
|
||||||
|
|
||||||
|
order_line_obj_up.id = order_line_id
|
||||||
|
|
||||||
|
log.debug(order_line_obj_up)
|
||||||
|
# log.debug(order_line_obj_up.dict(by_alias=True, exclude_unset=True))
|
||||||
|
log.debug(order_line_obj_up.dict(by_alias=False, exclude_unset=True))
|
||||||
|
# log.debug(order_line_obj_up.dict(by_alias=False, exclude_unset=False))
|
||||||
|
|
||||||
|
#order_line_dict_up = order_line_obj_up.dict(by_alias=False, exclude_unset=True)
|
||||||
|
|
||||||
|
# if order_line_obj_up.person_id and order_line_obj_up.person:
|
||||||
|
# person_id = order_line_obj_up.person_id
|
||||||
|
# person_obj_up = order_line_obj_up.person
|
||||||
|
# log.debug(person_id)
|
||||||
|
# log.debug(person_obj_up)
|
||||||
|
# if person_obj_up_result := update_person_obj(
|
||||||
|
# person_id=person_id,
|
||||||
|
# person_obj_up=person_obj_up,
|
||||||
|
# create_missing_obj=create_missing_obj,
|
||||||
|
# ):
|
||||||
|
# log.debug(person_obj_up_result)
|
||||||
|
# else:
|
||||||
|
# log.debug(person_obj_up_result)
|
||||||
|
# return False
|
||||||
|
|
||||||
|
# if order_line_obj_up.user_id and order_line_obj_up.user:
|
||||||
|
# user_id = order_line_obj_up.user_id
|
||||||
|
# user_obj_up = order_line_obj_up.user
|
||||||
|
# log.debug(user_id)
|
||||||
|
# log.debug(user_obj_up)
|
||||||
|
# if user_obj_up_result := update_user_obj(
|
||||||
|
# user_id=user_id,
|
||||||
|
# user_obj_up=user_obj_up,
|
||||||
|
# create_missing_obj=create_missing_obj,
|
||||||
|
# ):
|
||||||
|
# log.debug(user_obj_up_result)
|
||||||
|
# else:
|
||||||
|
# log.debug(user_obj_up_result)
|
||||||
|
# return False
|
||||||
|
|
||||||
|
order_line_dict_up = order_line_obj_up.dict(by_alias=False, exclude_unset=True, exclude={'user'})
|
||||||
|
log.debug(order_line_dict_up)
|
||||||
|
|
||||||
|
if order_line_obj_up_result := sql_update(data=order_line_dict_up, table_name='order_line', rm_id_random=True):
|
||||||
|
log.debug(order_line_obj_up_result)
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
log.debug(order_line_obj_up_result)
|
||||||
|
return False
|
||||||
|
# ### END ### API Order Line Methods ### update_order_line_obj() ###
|
||||||
|
|
||||||
|
|
||||||
|
# ### BEGIN ### API Order Line Methods ### get_order_line_rec_list() ###
|
||||||
|
def get_order_line_rec_list(
|
||||||
|
for_obj_type: str,
|
||||||
|
for_obj_id: str,
|
||||||
|
limit: int = 1000,
|
||||||
|
) -> list|bool:
|
||||||
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
log.debug(locals())
|
||||||
|
|
||||||
|
if for_obj_id := redis_lookup_id_random(record_id_random=for_obj_id, table_name='for_obj_type'): pass
|
||||||
|
else: return False
|
||||||
|
data = {}
|
||||||
|
data[f'{for_obj_type}_id'] = for_obj_id
|
||||||
|
# data['for_obj_type'] = for_obj_type
|
||||||
|
sql_obj_type_id = f'`tbl`.{for_obj_type}_id = :{for_obj_type}_id'
|
||||||
|
|
||||||
|
# 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 = ''
|
||||||
|
sql_enabled = ''
|
||||||
|
|
||||||
|
if limit:
|
||||||
|
data['limit'] = limit
|
||||||
|
sql_limit = f'LIMIT :limit'
|
||||||
|
else:
|
||||||
|
sql_limit = ''
|
||||||
|
|
||||||
|
sql = f"""
|
||||||
|
SELECT `tbl`.id AS 'order_line_id', `tbl`.id_random AS 'order_line_id_random'
|
||||||
|
FROM `order_line` AS `tbl`
|
||||||
|
WHERE
|
||||||
|
{sql_obj_type_id}
|
||||||
|
{sql_enabled}
|
||||||
|
ORDER BY `tbl`.created_on DESC, `tbl`.updated_on DESC
|
||||||
|
{sql_limit};
|
||||||
|
"""
|
||||||
|
|
||||||
|
if order_line_rec_li_result := sql_select(data=data, sql=sql, as_list=True):
|
||||||
|
order_line_rec_li = order_line_rec_li_result
|
||||||
|
else:
|
||||||
|
order_line_rec_li = []
|
||||||
|
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
log.debug(order_line_rec_li_result)
|
||||||
|
|
||||||
|
return order_line_rec_li
|
||||||
|
# ### END ### API Order Line Methods ### get_order_line_rec_list() ###
|
||||||
@@ -7,10 +7,15 @@ from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, v
|
|||||||
from app.db_sql import redis_lookup_id_random, sql_delete, sql_insert_or_update, sql_select
|
from app.db_sql import redis_lookup_id_random, sql_delete, sql_insert_or_update, sql_select
|
||||||
from app.lib_general import log, logging
|
from app.lib_general import log, logging
|
||||||
|
|
||||||
|
from app.methods.order_cfg_methods import load_order_cfg_obj
|
||||||
|
from app.methods.order_line_methods import get_order_line_rec_list, load_order_line_obj
|
||||||
|
# from app.methods.person_methods import load_person_obj
|
||||||
|
# from app.methods.user_methods import load_user_obj
|
||||||
|
|
||||||
from app.models.order_models import Order_Base
|
from app.models.order_models import Order_Base
|
||||||
from app.models.order_line_models import Order_Line_Base # This should go away later.
|
from app.models.order_line_models import Order_Line_Base # This should go away later.
|
||||||
#from app.models.person_models import Person_Base
|
# from app.models.person_models import Person_Base
|
||||||
#from app.models.user_models import User_Base
|
# from app.models.user_models import User_Base
|
||||||
|
|
||||||
|
|
||||||
# ### BEGIN ### API Order Methods ### save_order_obj() ###
|
# ### BEGIN ### API Order Methods ### save_order_obj() ###
|
||||||
@@ -165,46 +170,22 @@ def load_order_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_order_line_list: bool = False,
|
|
||||||
inc_order_cfg: bool = False,
|
inc_order_cfg: bool = False,
|
||||||
inc_person_obj: bool = False,
|
inc_order_line_list: bool = False,
|
||||||
inc_user_obj: bool = False,
|
inc_person: bool = False,
|
||||||
|
inc_user: bool = False,
|
||||||
):
|
):
|
||||||
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())
|
||||||
|
|
||||||
if order_id := redis_lookup_id_random(record_id_random=order_id, table_name='order'): pass
|
if order_id := redis_lookup_id_random(record_id_random=order_id, table_name='order'): pass
|
||||||
else:
|
else: return False
|
||||||
return False
|
|
||||||
|
|
||||||
if order_rec := sql_select(table_name='v_order', record_id=order_id):
|
if order_rec := sql_select(table_name='v_order', record_id=order_id): pass
|
||||||
#log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
else: return False
|
||||||
log.debug(order_rec)
|
|
||||||
|
|
||||||
if inc_order_line_list:
|
#log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
order_line_data = {}
|
log.debug(order_rec)
|
||||||
order_line_data['order_id'] = order_id
|
|
||||||
if order_line_rec_li := sql_select(table_name='v_order_line', data=order_line_data, as_list=True):#, field_name='order_id', field_value=order_id):
|
|
||||||
log.debug(order_line_rec_li)
|
|
||||||
order_rec['order_line_li'] = order_line_rec_li
|
|
||||||
|
|
||||||
if inc_order_cfg:
|
|
||||||
if order_cfg_rec := sql_select(table_name='v_account_cfg_detail', field_name='account_id', field_value=order_rec.get('account_id', None)):
|
|
||||||
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
||||||
log.debug(order_cfg_rec)
|
|
||||||
|
|
||||||
order_rec['cfg'] = order_cfg_rec
|
|
||||||
|
|
||||||
if inc_person_obj:
|
|
||||||
if person_rec := sql_select(table_name='v_person', field_name='person_id', field_value=order_rec.get('person_id', None)):
|
|
||||||
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
||||||
log.debug(person_rec)
|
|
||||||
|
|
||||||
order_rec['person'] = person_rec
|
|
||||||
|
|
||||||
log.debug(order_rec)
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
order_obj = Order_Base(**order_rec)
|
order_obj = Order_Base(**order_rec)
|
||||||
@@ -212,6 +193,76 @@ def load_order_obj(
|
|||||||
except ValidationError as e:
|
except ValidationError as e:
|
||||||
log.error(e.json())
|
log.error(e.json())
|
||||||
|
|
||||||
|
# Updated 2021-06-18
|
||||||
|
if inc_order_line_list:
|
||||||
|
if order_line_rec_list_result := get_order_line_rec_list(
|
||||||
|
for_obj_type = 'order',
|
||||||
|
for_obj_id = order_id,
|
||||||
|
limit = limit,
|
||||||
|
):
|
||||||
|
order_line_result_list = []
|
||||||
|
for order_line_rec in order_line_rec_list_result:
|
||||||
|
order_line_result_list.append(
|
||||||
|
load_order_line_obj(
|
||||||
|
order_line_id = order_line_rec.get('order_line_id', None),
|
||||||
|
limit = limit,
|
||||||
|
by_alias = by_alias,
|
||||||
|
exclude_unset = exclude_unset,
|
||||||
|
model_as_dict = model_as_dict,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
order_obj.order_line_list = order_line_result_list
|
||||||
|
else: order_obj.order_line_list = []
|
||||||
|
|
||||||
|
if inc_order_line_list:
|
||||||
|
order_line_data = {}
|
||||||
|
order_line_data['order_id'] = order_id
|
||||||
|
if order_line_rec_li := sql_select(table_name='v_order_line', data=order_line_data, as_list=True):#, field_name='order_id', field_value=order_id):
|
||||||
|
log.debug(order_line_rec_li)
|
||||||
|
order_rec['order_line_li'] = order_line_rec_li
|
||||||
|
|
||||||
|
if inc_order_cfg:
|
||||||
|
if order_cfg_result := load_order_cfg_obj(
|
||||||
|
order_cfg_id = order_rec.get('order_cfg_id', None),
|
||||||
|
limit = limit,
|
||||||
|
by_alias = by_alias,
|
||||||
|
exclude_unset = exclude_unset,
|
||||||
|
model_as_dict = model_as_dict,
|
||||||
|
enabled = enabled,
|
||||||
|
):
|
||||||
|
order_obj.order_cfg = order_cfg_result
|
||||||
|
else: order_obj.order_cfg = None
|
||||||
|
|
||||||
|
# Updated 2021-06-22
|
||||||
|
if inc_person:
|
||||||
|
from app.methods.person_methods import load_person_obj
|
||||||
|
if person_result := load_person_obj(
|
||||||
|
person_id = order_rec.get('person_id', None),
|
||||||
|
limit = limit,
|
||||||
|
by_alias = by_alias,
|
||||||
|
exclude_unset = exclude_unset,
|
||||||
|
model_as_dict = model_as_dict,
|
||||||
|
enabled = enabled,
|
||||||
|
):
|
||||||
|
order_obj.person = person_result
|
||||||
|
else: order_obj.person = None
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Updated 2021-06-22
|
||||||
|
if inc_user:
|
||||||
|
from app.methods.user_methods import load_user_obj
|
||||||
|
if user_result := load_user_obj(
|
||||||
|
user_id = order_rec.get('user_id', None),
|
||||||
|
limit = limit,
|
||||||
|
by_alias = by_alias,
|
||||||
|
exclude_unset = exclude_unset,
|
||||||
|
model_as_dict = model_as_dict,
|
||||||
|
enabled = enabled,
|
||||||
|
):
|
||||||
|
order_obj.user = user_result
|
||||||
|
else: order_obj.user = None
|
||||||
|
pass
|
||||||
|
|
||||||
if model_as_dict:
|
if model_as_dict:
|
||||||
return order_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset) # pylint: disable=no-member
|
return order_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset) # pylint: disable=no-member
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -9,8 +9,9 @@ from app.lib_general import log, logging
|
|||||||
|
|
||||||
from app.methods.address_methods import load_address_obj
|
from app.methods.address_methods import load_address_obj
|
||||||
from app.methods.contact_methods import create_contact_obj, load_contact_obj, update_contact_obj
|
from app.methods.contact_methods import create_contact_obj, load_contact_obj, update_contact_obj
|
||||||
|
from app.methods.order_methods import load_order_obj, get_order_rec_list
|
||||||
from app.methods.organization_methods import load_organization_obj, update_organization_obj
|
from app.methods.organization_methods import load_organization_obj, update_organization_obj
|
||||||
from app.methods.user_methods import create_user_obj, load_user_obj, update_user_obj
|
# from app.methods.user_methods import create_user_obj, load_user_obj, update_user_obj
|
||||||
|
|
||||||
from app.models.person_models import Person_Base
|
from app.models.person_models import Person_Base
|
||||||
|
|
||||||
@@ -69,7 +70,17 @@ def load_person_obj(
|
|||||||
enabled: str = 'enabled', # enabled, disabled, all
|
enabled: str = 'enabled', # enabled, disabled, all
|
||||||
inc_address: bool = False, # Under contact
|
inc_address: bool = False, # Under contact
|
||||||
inc_contact: bool = False,
|
inc_contact: bool = False,
|
||||||
|
inc_event_list: bool = False,
|
||||||
|
inc_journal_list: bool = False,
|
||||||
|
inc_journal_entry_list: bool = False,
|
||||||
|
inc_membership_member: bool = False,
|
||||||
|
inc_order_cfg: bool = False,
|
||||||
|
inc_order_line_list: bool = False,
|
||||||
|
inc_order_list: bool = False,
|
||||||
|
inc_order_cart_list: bool = False,
|
||||||
inc_organization: bool = False,
|
inc_organization: bool = False,
|
||||||
|
inc_post_list: bool = False,
|
||||||
|
inc_post_comment_list: bool = False,
|
||||||
inc_user: bool = False,
|
inc_user: bool = False,
|
||||||
) -> Person_Base|bool:
|
) -> Person_Base|bool:
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
@@ -103,6 +114,32 @@ def load_person_obj(
|
|||||||
person_obj.contact = contact_result
|
person_obj.contact = contact_result
|
||||||
else: person_obj.contact = None
|
else: person_obj.contact = None
|
||||||
|
|
||||||
|
# Updated 2021-06-18
|
||||||
|
if inc_order_list:
|
||||||
|
if order_rec_list_result := get_order_rec_list(
|
||||||
|
for_obj_type = 'person',
|
||||||
|
for_obj_id = person_id,
|
||||||
|
limit = limit,
|
||||||
|
enabled = enabled,
|
||||||
|
):
|
||||||
|
order_result_list = []
|
||||||
|
for order_rec in order_rec_list_result:
|
||||||
|
order_result_list.append(
|
||||||
|
load_order_obj(
|
||||||
|
order_id = order_rec.get('order_id', None),
|
||||||
|
limit = limit,
|
||||||
|
by_alias = by_alias,
|
||||||
|
exclude_unset = exclude_unset,
|
||||||
|
model_as_dict = model_as_dict,
|
||||||
|
enabled = enabled,
|
||||||
|
inc_order_cfg = inc_order_cfg,
|
||||||
|
inc_order_line_list = inc_order_line_list,
|
||||||
|
inc_user = inc_user,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
person_obj.order_list = order_result_list
|
||||||
|
else: person_obj.order_list = []
|
||||||
|
|
||||||
# Updated 2021-06-18
|
# Updated 2021-06-18
|
||||||
if inc_organization:
|
if inc_organization:
|
||||||
organization_id = person_rec.get('organization_id', None)
|
organization_id = person_rec.get('organization_id', None)
|
||||||
@@ -122,18 +159,19 @@ def load_person_obj(
|
|||||||
|
|
||||||
# Updated 2021-06-18
|
# Updated 2021-06-18
|
||||||
if inc_user:
|
if inc_user:
|
||||||
user_id = person_rec.get('user_id', None)
|
# user_id = person_rec.get('user_id', None)
|
||||||
log.debug(user_id)
|
# log.debug(user_id)
|
||||||
if user_result := load_user_obj(
|
# if user_result := load_user_obj(
|
||||||
user_id = user_id,
|
# user_id = user_id,
|
||||||
limit = limit,
|
# limit = limit,
|
||||||
by_alias = by_alias,
|
# by_alias = by_alias,
|
||||||
exclude_unset = exclude_unset,
|
# exclude_unset = exclude_unset,
|
||||||
model_as_dict = model_as_dict,
|
# model_as_dict = model_as_dict,
|
||||||
enabled = enabled,
|
# enabled = enabled,
|
||||||
):
|
# ):
|
||||||
person_obj.user = user_result
|
# person_obj.user = user_result
|
||||||
else: person_obj.user = None
|
# else: person_obj.user = None
|
||||||
|
pass
|
||||||
|
|
||||||
if model_as_dict:
|
if model_as_dict:
|
||||||
return person_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset) # pylint: disable=no-member
|
return person_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset) # pylint: disable=no-member
|
||||||
@@ -167,9 +205,9 @@ def update_person_obj(
|
|||||||
log.debug(contact_id)
|
log.debug(contact_id)
|
||||||
log.debug(contact_obj_up)
|
log.debug(contact_obj_up)
|
||||||
if contact_obj_up_result := update_contact_obj(
|
if contact_obj_up_result := update_contact_obj(
|
||||||
contact_id=contact_id,
|
contact_id = contact_id,
|
||||||
contact_obj_up=contact_obj_up,
|
contact_obj_up = contact_obj_up,
|
||||||
create_missing_obj=create_missing_obj,
|
create_missing_obj = create_missing_obj,
|
||||||
):
|
):
|
||||||
log.debug(contact_obj_up_result)
|
log.debug(contact_obj_up_result)
|
||||||
else:
|
else:
|
||||||
@@ -194,9 +232,9 @@ def update_person_obj(
|
|||||||
log.debug(organization_id)
|
log.debug(organization_id)
|
||||||
log.debug(organization_obj_up)
|
log.debug(organization_obj_up)
|
||||||
if organization_obj_up_result := update_organization_obj(
|
if organization_obj_up_result := update_organization_obj(
|
||||||
organization_id=organization_id,
|
organization_id = organization_id,
|
||||||
organization_obj_up=organization_obj_up,
|
organization_obj_up = organization_obj_up,
|
||||||
create_missing_obj=create_missing_obj,
|
create_missing_obj = create_missing_obj,
|
||||||
):
|
):
|
||||||
log.debug(organization_obj_up_result)
|
log.debug(organization_obj_up_result)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, v
|
|||||||
from app.db_sql import redis_lookup_id_random, sql_insert, sql_select, sql_update
|
from app.db_sql import redis_lookup_id_random, sql_insert, sql_select, sql_update
|
||||||
from app.lib_general import log, logging
|
from app.lib_general import log, logging
|
||||||
|
|
||||||
# from app.methods.person_methods import load_person_obj
|
from app.methods.person_methods import load_person_obj
|
||||||
# from app.methods.user_methods import load_user_obj
|
# from app.methods.user_methods import load_user_obj
|
||||||
|
|
||||||
from app.models.post_comment_models import Post_Comment_Base
|
from app.models.post_comment_models import Post_Comment_Base
|
||||||
@@ -66,33 +66,35 @@ def load_post_comment_obj(
|
|||||||
log.error(e.json())
|
log.error(e.json())
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Updated 2021-06-18
|
|
||||||
|
# Updated 2021-06-22
|
||||||
if inc_person:
|
if inc_person:
|
||||||
from app.methods.person_methods import load_person_obj
|
# from app.methods.person_methods import load_person_obj
|
||||||
person_result = load_person_obj(
|
if person_result := load_person_obj(
|
||||||
person_id = post_comment_rec.get('person_id', None),
|
person_id = post_comment_rec.get('person_id', None),
|
||||||
limit = limit,
|
limit = limit,
|
||||||
by_alias = by_alias,
|
by_alias = by_alias,
|
||||||
exclude_unset = exclude_unset,
|
exclude_unset = exclude_unset,
|
||||||
model_as_dict = model_as_dict,
|
model_as_dict = model_as_dict,
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
)
|
):
|
||||||
post_comment_obj.person = person_result
|
post_comment_obj.person = person_result
|
||||||
else: post_comment_obj.person = None
|
else: post_comment_obj.person = None
|
||||||
|
|
||||||
|
|
||||||
# Updated 2021-06-18
|
# Updated 2021-06-18
|
||||||
if inc_user:
|
if inc_user:
|
||||||
from app.methods.user_methods import load_user_obj
|
# from app.methods.user_methods import load_user_obj
|
||||||
user_result = load_user_obj(
|
# user_result = load_user_obj(
|
||||||
user_id = post_comment_rec.get('user_id', None),
|
# user_id = post_comment_rec.get('user_id', None),
|
||||||
limit = limit,
|
# limit = limit,
|
||||||
by_alias = by_alias,
|
# by_alias = by_alias,
|
||||||
exclude_unset = exclude_unset,
|
# exclude_unset = exclude_unset,
|
||||||
model_as_dict = model_as_dict,
|
# model_as_dict = model_as_dict,
|
||||||
enabled = enabled,
|
# enabled = enabled,
|
||||||
)
|
# )
|
||||||
post_comment_obj.user = user_result
|
# post_comment_obj.user = user_result
|
||||||
else: post_comment_obj.user = None
|
pass
|
||||||
|
|
||||||
if model_as_dict:
|
if model_as_dict:
|
||||||
return post_comment_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset) # pylint: disable=no-member
|
return post_comment_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset) # pylint: disable=no-member
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, v
|
|||||||
from app.db_sql import redis_lookup_id_random, sql_insert, sql_select, sql_update
|
from app.db_sql import redis_lookup_id_random, sql_insert, sql_select, sql_update
|
||||||
from app.lib_general import log, logging
|
from app.lib_general import log, logging
|
||||||
|
|
||||||
# from app.methods.person_methods import load_person_obj
|
from app.methods.person_methods import load_person_obj
|
||||||
# from app.methods.post_comment_methods import create_post_comment_obj, update_post_comment_obj
|
# from app.methods.post_comment_methods import create_post_comment_obj, update_post_comment_obj
|
||||||
from app.methods.post_comment_methods import get_post_comment_rec_list, load_post_comment_obj
|
from app.methods.post_comment_methods import get_post_comment_rec_list, load_post_comment_obj
|
||||||
# from app.methods.user_methods import load_user_obj
|
# from app.methods.user_methods import load_user_obj
|
||||||
@@ -70,19 +70,19 @@ def load_post_obj(
|
|||||||
except ValidationError as e:
|
except ValidationError as e:
|
||||||
log.error(e.json())
|
log.error(e.json())
|
||||||
|
|
||||||
# Updated 2021-06-18
|
# Updated 2021-06-22
|
||||||
if inc_person:
|
if inc_person:
|
||||||
from app.methods.person_methods import load_person_obj
|
# from app.methods.person_methods import load_person_obj
|
||||||
person_result = load_person_obj(
|
if person_result := load_person_obj(
|
||||||
person_id = post_rec.get('person_id', None),
|
person_id = post_rec.get('person_id', None),
|
||||||
limit = limit,
|
limit = limit,
|
||||||
by_alias = by_alias,
|
by_alias = by_alias,
|
||||||
exclude_unset = exclude_unset,
|
exclude_unset = exclude_unset,
|
||||||
model_as_dict = model_as_dict,
|
model_as_dict = model_as_dict,
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
)
|
):
|
||||||
post_obj.person = person_result
|
post_obj.person = person_result
|
||||||
else: post_obj.person = None
|
else: post_obj.person = None
|
||||||
|
|
||||||
# Updated 2021-06-17
|
# Updated 2021-06-17
|
||||||
if inc_post_comment_list:
|
if inc_post_comment_list:
|
||||||
@@ -111,17 +111,17 @@ def load_post_obj(
|
|||||||
|
|
||||||
# Updated 2021-06-18
|
# Updated 2021-06-18
|
||||||
if inc_user:
|
if inc_user:
|
||||||
from app.methods.user_methods import load_user_obj
|
# from app.methods.user_methods import load_user_obj
|
||||||
user_result = load_user_obj(
|
# user_result = load_user_obj(
|
||||||
user_id = post_rec.get('user_id', None),
|
# user_id = post_rec.get('user_id', None),
|
||||||
limit = limit,
|
# limit = limit,
|
||||||
by_alias = by_alias,
|
# by_alias = by_alias,
|
||||||
exclude_unset = exclude_unset,
|
# exclude_unset = exclude_unset,
|
||||||
model_as_dict = model_as_dict,
|
# model_as_dict = model_as_dict,
|
||||||
enabled = enabled,
|
# enabled = enabled,
|
||||||
)
|
# )
|
||||||
post_obj.user = user_result
|
# post_obj.user = user_result
|
||||||
else: post_obj.user = None
|
pass
|
||||||
|
|
||||||
if model_as_dict:
|
if model_as_dict:
|
||||||
return post_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset) # pylint: disable=no-member
|
return post_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset) # pylint: disable=no-member
|
||||||
@@ -130,90 +130,6 @@ def load_post_obj(
|
|||||||
# ### END ### API Post Methods ### load_post_obj() ###
|
# ### END ### API Post Methods ### load_post_obj() ###
|
||||||
|
|
||||||
|
|
||||||
# ### BEGIN ### API Post Methods ### load_post_obj_list() ###
|
|
||||||
def load_post_obj_list(
|
|
||||||
account_id: int|str|None = None,
|
|
||||||
user_id: int|str|None = None,
|
|
||||||
limit: int = 1000,
|
|
||||||
by_alias: bool = True,
|
|
||||||
exclude_unset: bool = True,
|
|
||||||
model_as_dict: bool = False,
|
|
||||||
enabled: str = 'enabled', # enabled, disabled, all
|
|
||||||
inc_post_comment_list: bool = False,
|
|
||||||
inc_person: bool = False,
|
|
||||||
inc_user: bool = False,
|
|
||||||
) -> list|bool:
|
|
||||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
||||||
log.debug(locals())
|
|
||||||
|
|
||||||
data = {}
|
|
||||||
if account_id:
|
|
||||||
if account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'): pass
|
|
||||||
else: return False
|
|
||||||
data['account_id'] = account_id
|
|
||||||
sql_obj_type_id = f'`tbl`.account_id = :account_id'
|
|
||||||
elif user_id:
|
|
||||||
if user_id := redis_lookup_id_random(record_id_random=user_id, table_name='user'): pass
|
|
||||||
else: return False
|
|
||||||
data['user_id'] = user_id
|
|
||||||
sql_obj_type_id = f'`tbl`.user_id = :user_id'
|
|
||||||
|
|
||||||
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 = ''
|
|
||||||
# else: tbl_obj['account'] = None
|
|
||||||
|
|
||||||
if limit:
|
|
||||||
data['limit'] = limit
|
|
||||||
sql_limit = f'LIMIT :limit'
|
|
||||||
else:
|
|
||||||
sql_limit = ''
|
|
||||||
|
|
||||||
sql = f"""
|
|
||||||
SELECT `tbl`.id AS 'post_id', `tbl`.id_random AS 'post_id_random'
|
|
||||||
FROM `post` AS `tbl`
|
|
||||||
WHERE
|
|
||||||
{sql_obj_type_id}
|
|
||||||
{sql_enabled}
|
|
||||||
ORDER BY `tbl`.created_on DESC, `tbl`.updated_on DESC
|
|
||||||
{sql_limit};
|
|
||||||
"""
|
|
||||||
|
|
||||||
if post_rec_li_result := sql_select(data=data, sql=sql, as_list=True):
|
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
||||||
log.debug(post_rec_li_result)
|
|
||||||
post_result_li = []
|
|
||||||
for post_rec in post_rec_li_result:
|
|
||||||
post_id = post_rec.get('post_id', None)
|
|
||||||
if post_result := load_post_obj(
|
|
||||||
post_id = post_id,
|
|
||||||
model_as_dict = model_as_dict,
|
|
||||||
enabled = enabled,
|
|
||||||
inc_post_comment_list = inc_post_comment_list,
|
|
||||||
inc_person = inc_person,
|
|
||||||
inc_user = inc_user,
|
|
||||||
):
|
|
||||||
log.debug(post_result)
|
|
||||||
post_result_li.append(post_result)
|
|
||||||
else:
|
|
||||||
log.debug(post_result)
|
|
||||||
post_result_li.append(None)
|
|
||||||
log.debug(post_result_li)
|
|
||||||
else:
|
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
||||||
log.debug(post_rec_li_result)
|
|
||||||
post_result_li = []
|
|
||||||
|
|
||||||
return post_result_li
|
|
||||||
# ### END ### API Post Methods ### load_post_obj_list() ###
|
|
||||||
|
|
||||||
|
|
||||||
# ### BEGIN ### API Post Methods ### update_post_obj() ###
|
# ### BEGIN ### API Post Methods ### update_post_obj() ###
|
||||||
def update_post_obj(
|
def update_post_obj(
|
||||||
post_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
|
post_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
|
||||||
|
|||||||
@@ -7,9 +7,7 @@ from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, v
|
|||||||
from app.db_sql import redis_lookup_id_random, sql_insert, sql_select, sql_update
|
from app.db_sql import redis_lookup_id_random, sql_insert, sql_select, sql_update
|
||||||
from app.lib_general import log, logging
|
from app.lib_general import log, logging
|
||||||
|
|
||||||
# from app.methods.person_methods import load_person_obj
|
|
||||||
from app.methods.site_domain_methods import get_site_domain_rec_list, load_site_domain_obj
|
from app.methods.site_domain_methods import get_site_domain_rec_list, load_site_domain_obj
|
||||||
# from app.methods.user_methods import load_user_obj
|
|
||||||
|
|
||||||
from app.models.site_models import Site_Base
|
from app.models.site_models import Site_Base
|
||||||
|
|
||||||
@@ -57,8 +55,7 @@ def load_site_obj(
|
|||||||
if site_id := redis_lookup_id_random(record_id_random=site_id, table_name='site'): pass
|
if site_id := redis_lookup_id_random(record_id_random=site_id, table_name='site'): pass
|
||||||
else: return False
|
else: return False
|
||||||
|
|
||||||
if site_rec := sql_select(table_name='v_site', record_id=site_id):
|
if site_rec := sql_select(table_name='v_site', record_id=site_id): pass
|
||||||
log.debug(site_rec)
|
|
||||||
else: return False
|
else: return False
|
||||||
|
|
||||||
log.debug(site_rec)
|
log.debug(site_rec)
|
||||||
|
|||||||
@@ -9,8 +9,9 @@ from app.lib_general import log, logging
|
|||||||
|
|
||||||
from app.methods.contact_methods import load_contact_obj, update_contact_obj
|
from app.methods.contact_methods import load_contact_obj, update_contact_obj
|
||||||
# from app.methods.event_methods import get_event_rec_list
|
# from app.methods.event_methods import get_event_rec_list
|
||||||
|
from app.methods.order_methods import load_order_obj, get_order_rec_list
|
||||||
from app.methods.organization_methods import load_organization_obj, update_organization_obj
|
from app.methods.organization_methods import load_organization_obj, update_organization_obj
|
||||||
# from app.methods.person_methods import load_person_obj, update_person_obj
|
from app.methods.person_methods import load_person_obj, update_person_obj
|
||||||
from app.methods.post_methods import get_post_rec_list, load_post_obj
|
from app.methods.post_methods import get_post_rec_list, load_post_obj
|
||||||
|
|
||||||
from app.models.user_models import User_Base, User_New_Base, User_Out_Base
|
from app.models.user_models import User_Base, User_New_Base, User_Out_Base
|
||||||
@@ -80,14 +81,20 @@ def load_user_obj(
|
|||||||
model_as_dict: bool = False,
|
model_as_dict: bool = False,
|
||||||
enabled: str = 'enabled', # enabled, disabled, all
|
enabled: str = 'enabled', # enabled, disabled, all
|
||||||
inc_address: bool = False,
|
inc_address: bool = False,
|
||||||
|
# inc_archive_list: bool = False,
|
||||||
inc_contact: bool = False,
|
inc_contact: bool = False,
|
||||||
inc_event_list: bool = False,
|
inc_event_list: bool = False,
|
||||||
|
# inc_hosted_file_list: bool = False,
|
||||||
inc_journal_list: bool = False,
|
inc_journal_list: bool = False,
|
||||||
inc_membership: bool = False,
|
inc_journal_entry_list: bool = False,
|
||||||
|
inc_membership_member: bool = False,
|
||||||
|
inc_order_cfg: bool = False,
|
||||||
|
inc_order_line_list: bool = False,
|
||||||
inc_order_list: bool = False,
|
inc_order_list: bool = False,
|
||||||
inc_order_cart_list: bool = False,
|
inc_order_cart_list: bool = False,
|
||||||
inc_organization: bool = False,
|
inc_organization: bool = False,
|
||||||
inc_person: bool = False,
|
inc_person: bool = False,
|
||||||
|
# inc_person_list: bool = False,
|
||||||
inc_post_list: bool = False,
|
inc_post_list: bool = False,
|
||||||
inc_post_comment_list: bool = False,
|
inc_post_comment_list: bool = False,
|
||||||
inc_user_role_list: bool = False,
|
inc_user_role_list: bool = False,
|
||||||
@@ -112,20 +119,20 @@ def load_user_obj(
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
# Updated 2021-06-18
|
# Updated 2021-06-18
|
||||||
if inc_contact:
|
# if inc_contact:
|
||||||
contact_id = user_rec.get('contact_id', None)
|
# contact_id = user_rec.get('contact_id', None)
|
||||||
log.debug(contact_id)
|
# log.debug(contact_id)
|
||||||
if contact_result := load_contact_obj(
|
# if contact_result := load_contact_obj(
|
||||||
contact_id = contact_id,
|
# contact_id = contact_id,
|
||||||
limit = limit,
|
# limit = limit,
|
||||||
by_alias = by_alias,
|
# by_alias = by_alias,
|
||||||
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_address = inc_address,
|
# inc_address = inc_address,
|
||||||
):
|
# ):
|
||||||
user_obj.contact = contact_result
|
# user_obj.contact = contact_result
|
||||||
else: user_obj.contact = None
|
# else: user_obj.contact = None
|
||||||
|
|
||||||
if inc_event_list:
|
if inc_event_list:
|
||||||
from app.methods.event_methods import load_event_obj_list
|
from app.methods.event_methods import load_event_obj_list
|
||||||
@@ -138,6 +145,33 @@ def load_user_obj(
|
|||||||
user_obj.event_list = event_dict_list
|
user_obj.event_list = event_dict_list
|
||||||
else: user_obj.event_list = []
|
else: user_obj.event_list = []
|
||||||
|
|
||||||
|
# Updated 2021-06-18
|
||||||
|
if inc_order_list:
|
||||||
|
if order_rec_list_result := get_order_rec_list(
|
||||||
|
for_obj_type = 'user',
|
||||||
|
for_obj_id = user_id,
|
||||||
|
limit = limit,
|
||||||
|
enabled = enabled,
|
||||||
|
):
|
||||||
|
order_result_list = []
|
||||||
|
for order_rec in order_rec_list_result:
|
||||||
|
order_result_list.append(
|
||||||
|
load_order_obj(
|
||||||
|
order_id = order_rec.get('order_id', None),
|
||||||
|
limit = limit,
|
||||||
|
by_alias = by_alias,
|
||||||
|
exclude_unset = exclude_unset,
|
||||||
|
model_as_dict = model_as_dict,
|
||||||
|
enabled = enabled,
|
||||||
|
inc_order_cfg = inc_order_cfg,
|
||||||
|
inc_order_line_list = inc_order_line_list,
|
||||||
|
inc_person = inc_person,
|
||||||
|
# inc_user = inc_user,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
user_obj.order_list = order_result_list
|
||||||
|
else: user_obj.order_list = []
|
||||||
|
|
||||||
# Updated 2021-06-18
|
# Updated 2021-06-18
|
||||||
if inc_organization:
|
if inc_organization:
|
||||||
organization_id = user_rec.get('organization_id', None)
|
organization_id = user_rec.get('organization_id', None)
|
||||||
@@ -166,8 +200,7 @@ def load_user_obj(
|
|||||||
model_as_dict = model_as_dict,
|
model_as_dict = model_as_dict,
|
||||||
inc_address = inc_address,
|
inc_address = inc_address,
|
||||||
inc_contact = inc_contact,
|
inc_contact = inc_contact,
|
||||||
# inc_organization = inc_organization,
|
inc_organization = inc_organization,
|
||||||
# inc_user = inc_user,
|
|
||||||
):
|
):
|
||||||
user_obj.person = person_result
|
user_obj.person = person_result
|
||||||
else: user_obj.person = None
|
else: user_obj.person = None
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ class Contact_Base(BaseModel):
|
|||||||
)
|
)
|
||||||
account_id_random: Optional[str]
|
account_id_random: Optional[str]
|
||||||
account_id: Optional[int]
|
account_id: Optional[int]
|
||||||
|
|
||||||
address_id_random: Optional[str]
|
address_id_random: Optional[str]
|
||||||
address_id: Optional[int]
|
address_id: Optional[int]
|
||||||
|
|
||||||
|
|||||||
@@ -30,12 +30,16 @@ class Membership_Member_Base(BaseModel):
|
|||||||
|
|
||||||
account_id_random: Optional[str]
|
account_id_random: Optional[str]
|
||||||
account_id: Optional[int]
|
account_id: Optional[int]
|
||||||
|
|
||||||
membership_type_id_random: Optional[str]
|
membership_type_id_random: Optional[str]
|
||||||
membership_type_id: Optional[int] # NOTE: This is not optional
|
membership_type_id: Optional[int] # NOTE: This is not optional
|
||||||
|
|
||||||
person_id_random: Optional[str]
|
person_id_random: Optional[str]
|
||||||
person_id: Optional[int]
|
person_id: Optional[int]
|
||||||
|
|
||||||
product_id_random: Optional[str]
|
product_id_random: Optional[str]
|
||||||
product_id: Optional[int] # The product they purchased to get this membership
|
product_id: Optional[int] # The product they purchased to get this membership
|
||||||
|
|
||||||
user_id_random: Optional[str]
|
user_id_random: Optional[str]
|
||||||
user_id: Optional[int]
|
user_id: Optional[int]
|
||||||
|
|
||||||
|
|||||||
31
app/models/order_cfg_models.py
Normal file
31
app/models/order_cfg_models.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||||
|
|
||||||
|
from typing import Dict, List, Optional, Set, Union
|
||||||
|
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator
|
||||||
|
|
||||||
|
from app.db_sql import redis_lookup_id_random
|
||||||
|
from app.lib_general import log, logging
|
||||||
|
|
||||||
|
from app.models.common_field_schema import base_fields, default_num_bytes
|
||||||
|
|
||||||
|
|
||||||
|
class Order_Cfg_Base(BaseModel):
|
||||||
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
log.debug(locals())
|
||||||
|
|
||||||
|
account_id_random: Optional[str]
|
||||||
|
account_id: Optional[int]
|
||||||
|
|
||||||
|
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
||||||
|
|
||||||
|
@validator('account_id', always=True)
|
||||||
|
def account_id_lookup(cls, v, values, **kwargs):
|
||||||
|
log.setLevel(logging.WARNING)
|
||||||
|
log.debug(locals())
|
||||||
|
|
||||||
|
if values['account_id_random']:
|
||||||
|
return redis_lookup_id_random(record_id_random=values['account_id_random'], table_name='account')
|
||||||
|
return None
|
||||||
|
|
||||||
|
Order_Cfg_Base.update_forward_refs()
|
||||||
@@ -10,8 +10,9 @@ from app.lib_general import log, logging
|
|||||||
from app.models.common_field_schema import base_fields, default_num_bytes
|
from app.models.common_field_schema import base_fields, default_num_bytes
|
||||||
# from app.models.account_models import Account_Base
|
# from app.models.account_models import Account_Base
|
||||||
from app.models.contact_models import Contact_Base
|
from app.models.contact_models import Contact_Base
|
||||||
|
# from app.models.membership_member_models import Membership_Member_Base
|
||||||
from app.models.organization_models import Organization_Base
|
from app.models.organization_models import Organization_Base
|
||||||
from app.models.user_models import User_Base
|
# from app.models.user_models import User_Base
|
||||||
|
|
||||||
|
|
||||||
class Person_Base(BaseModel):
|
class Person_Base(BaseModel):
|
||||||
@@ -33,13 +34,16 @@ class Person_Base(BaseModel):
|
|||||||
)
|
)
|
||||||
account_id_random: Optional[str]
|
account_id_random: Optional[str]
|
||||||
account_id: Optional[int]
|
account_id: Optional[int]
|
||||||
user_id_random: Optional[str]
|
|
||||||
user_id: Optional[int]
|
|
||||||
organization_id_random: Optional[str]
|
|
||||||
organization_id: Optional[int]
|
|
||||||
contact_id_random: Optional[str]
|
contact_id_random: Optional[str]
|
||||||
contact_id: Optional[int]
|
contact_id: Optional[int]
|
||||||
|
|
||||||
|
organization_id_random: Optional[str]
|
||||||
|
organization_id: Optional[int]
|
||||||
|
|
||||||
|
user_id_random: Optional[str]
|
||||||
|
user_id: Optional[int]
|
||||||
|
|
||||||
given_name: Optional[str]
|
given_name: Optional[str]
|
||||||
family_name: Optional[str]
|
family_name: Optional[str]
|
||||||
middle_name: Optional[str]
|
middle_name: Optional[str]
|
||||||
@@ -59,9 +63,18 @@ class Person_Base(BaseModel):
|
|||||||
updated_on: Optional[datetime.datetime] = None
|
updated_on: Optional[datetime.datetime] = None
|
||||||
|
|
||||||
# Including other related objects
|
# Including other related objects
|
||||||
|
# archive_list: Optional[list] # Archive_Base()
|
||||||
|
event_list: Optional[list] # Event_Base() # Priority l1
|
||||||
|
hosted_file_list: Optional[list] # Hosted_File_Base() # Priority l2
|
||||||
|
journal_list: Optional[list] # Journal_Base() # Priority l3
|
||||||
contact: Optional[Union[Contact_Base, None]]
|
contact: Optional[Union[Contact_Base, None]]
|
||||||
|
# membership_member: Optional[Membership_Member_Base] # Priority l2
|
||||||
|
# membership_member_list: Optional[list] # Membership_Base() ????
|
||||||
|
order_list: Optional[list] # Order_Base() # Priority l2
|
||||||
|
order_cart_list: Optional[list] # Order_Base() # Priority l2
|
||||||
organization: Optional[Union[Organization_Base, None]]
|
organization: Optional[Union[Organization_Base, None]]
|
||||||
user: Optional[Union[User_Base, None]]
|
post_list: Optional[list] # Post_Base() # Priority l1
|
||||||
|
# user: Optional[Union[User_Base, None]]
|
||||||
|
|
||||||
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
||||||
|
|
||||||
@@ -93,13 +106,14 @@ class Person_Base(BaseModel):
|
|||||||
return redis_lookup_id_random(record_id_random=values['account_id_random'], table_name='account')
|
return redis_lookup_id_random(record_id_random=values['account_id_random'], table_name='account')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@validator('user_id', always=True)
|
|
||||||
def user_id_lookup(cls, v, values, **kwargs):
|
@validator('contact_id', always=True)
|
||||||
|
def contact_id_lookup(cls, v, values, **kwargs):
|
||||||
log.setLevel(logging.WARNING)
|
log.setLevel(logging.WARNING)
|
||||||
log.debug(locals())
|
log.debug(locals())
|
||||||
|
|
||||||
if values['user_id_random']:
|
if values['contact_id_random']:
|
||||||
return redis_lookup_id_random(record_id_random=values['user_id_random'], table_name='user')
|
return redis_lookup_id_random(record_id_random=values['contact_id_random'], table_name='contact')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@validator('organization_id', always=True)
|
@validator('organization_id', always=True)
|
||||||
@@ -111,13 +125,13 @@ class Person_Base(BaseModel):
|
|||||||
return redis_lookup_id_random(record_id_random=values['organization_id_random'], table_name='organization')
|
return redis_lookup_id_random(record_id_random=values['organization_id_random'], table_name='organization')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@validator('contact_id', always=True)
|
@validator('user_id', always=True)
|
||||||
def contact_id_lookup(cls, v, values, **kwargs):
|
def user_id_lookup(cls, v, values, **kwargs):
|
||||||
log.setLevel(logging.WARNING)
|
log.setLevel(logging.WARNING)
|
||||||
log.debug(locals())
|
log.debug(locals())
|
||||||
|
|
||||||
if values['contact_id_random']:
|
if values['user_id_random']:
|
||||||
return redis_lookup_id_random(record_id_random=values['contact_id_random'], table_name='contact')
|
return redis_lookup_id_random(record_id_random=values['user_id_random'], table_name='user')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ def mk_resp(
|
|||||||
exclude_unset: bool = True,
|
exclude_unset: bool = True,
|
||||||
response = None
|
response = None
|
||||||
):
|
):
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(locals())
|
log.debug(locals())
|
||||||
|
|
||||||
if data is None: data_out = { 'result': data }
|
if data is None: data_out = { 'result': data }
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ from app.db_sql import redis_lookup_id_random
|
|||||||
from app.lib_general import log, logging, secure_hash_string
|
from app.lib_general import log, logging, secure_hash_string
|
||||||
|
|
||||||
from app.models.common_field_schema import base_fields, default_num_bytes
|
from app.models.common_field_schema import base_fields, default_num_bytes
|
||||||
from app.models.contact_models import Contact_Base
|
# from app.models.contact_models import Contact_Base
|
||||||
# from app.models.membership_models import Membership_Base
|
# from app.models.membership_member_models import Membership_Member_Base
|
||||||
from app.models.organization_models import Organization_Base
|
from app.models.organization_models import Organization_Base
|
||||||
# from app.models.person_models import Person_Base # Causes circular import
|
from app.models.person_models import Person_Base # Causes circular import
|
||||||
from app.models.user_role_models import User_Role_Base
|
# from app.models.user_role_models import User_Role_Base
|
||||||
|
|
||||||
|
|
||||||
# ### BEGIN ### API User Models ### User_New_Base() ###
|
# ### BEGIN ### API User Models ### User_New_Base() ###
|
||||||
@@ -142,10 +142,13 @@ class User_Out_Base(BaseModel):
|
|||||||
)
|
)
|
||||||
account_id_random: Optional[str]
|
account_id_random: Optional[str]
|
||||||
#account_id: Optional[int]
|
#account_id: Optional[int]
|
||||||
|
|
||||||
contact_id_random: Optional[str]
|
contact_id_random: Optional[str]
|
||||||
#contact_id: Optional[int]
|
#contact_id: Optional[int]
|
||||||
|
|
||||||
organization_id_random: Optional[str]
|
organization_id_random: Optional[str]
|
||||||
#organization_id: Optional[int]
|
#organization_id: Optional[int]
|
||||||
|
|
||||||
person_id_random: Optional[str]
|
person_id_random: Optional[str]
|
||||||
#person_id: Optional[int]
|
#person_id: Optional[int]
|
||||||
|
|
||||||
@@ -182,20 +185,20 @@ class User_Out_Base(BaseModel):
|
|||||||
|
|
||||||
# Including other related objects
|
# Including other related objects
|
||||||
# from app.models.person_models import Person_Base # Causes circular import
|
# from app.models.person_models import Person_Base # Causes circular import
|
||||||
|
# archive_list: Optional[list] # Archive_Base()
|
||||||
archive_list: Optional[list] # Archive_Base()
|
# contact: Optional[Contact_Base]
|
||||||
contact: Optional[Contact_Base]
|
event_list: Optional[list] # Event_Base() # Priority complete
|
||||||
event_list: Optional[list] # Event_Base() # Priority l1
|
hosted_file_list: Optional[list] # Hosted_File_Base() # Priority l3
|
||||||
hosted_file_list: Optional[list] # Hosted_File_Base() # Priority l2
|
|
||||||
journal_list: Optional[list] # Journal_Base() # Priority l3
|
journal_list: Optional[list] # Journal_Base() # Priority l3
|
||||||
# membership: Optional[Membership_Base] # Priority l2
|
# membership_member: Optional[Membership_Member_Base] # Priority l2
|
||||||
|
# membership_member_list: Optional[list] # Membership_Base() ???
|
||||||
order_list: Optional[list] # Order_Base() # Priority l2
|
order_list: Optional[list] # Order_Base() # Priority l2
|
||||||
order_cart_list: Optional[list] # Order_Base() # Priority l2
|
order_cart_list: Optional[list] # Order_Base() # Priority l2
|
||||||
organization: Optional[Organization_Base] # Organization_Base() # Priority l3
|
organization: Optional[Union[Organization_Base, None]] # Organization_Base() # Priority l3
|
||||||
person: Optional[dict] # Person_Base() # Priority l2
|
# person: Optional[dict] # Person_Base() # Priority l2
|
||||||
|
person: Optional[Union[Person_Base, None]]
|
||||||
post_list: Optional[list] # Post_Base() # Priority l1
|
post_list: Optional[list] # Post_Base() # Priority l1
|
||||||
user_role_list: Optional[list] # User_Role_Base()
|
user_role_list: Optional[list] # User_Role_Base()
|
||||||
role_list: Optional[list] = [] # User_Role_Base() # NOTE <- This is a duplicate of above!
|
|
||||||
|
|
||||||
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
||||||
|
|
||||||
@@ -223,10 +226,13 @@ class User_Base(BaseModel):
|
|||||||
)
|
)
|
||||||
account_id_random: Optional[str]
|
account_id_random: Optional[str]
|
||||||
account_id: Optional[int]
|
account_id: Optional[int]
|
||||||
contact_id_random: Optional[str]
|
|
||||||
contact_id: Optional[int]
|
# contact_id_random: Optional[str]
|
||||||
|
# contact_id: Optional[int]
|
||||||
|
|
||||||
organization_id_random: Optional[str]
|
organization_id_random: Optional[str]
|
||||||
organization_id: Optional[int]
|
organization_id: Optional[int]
|
||||||
|
|
||||||
person_id_random: Optional[str]
|
person_id_random: Optional[str]
|
||||||
person_id: Optional[int]
|
person_id: Optional[int]
|
||||||
|
|
||||||
@@ -263,19 +269,22 @@ class User_Base(BaseModel):
|
|||||||
updated_on: Optional[datetime.datetime] = None
|
updated_on: Optional[datetime.datetime] = None
|
||||||
|
|
||||||
# Including other related objects
|
# Including other related objects
|
||||||
archive_list: Optional[list] # Archive_Base()
|
# from app.models.person_models import Person_Base # Causes circular import
|
||||||
contact: Optional[Contact_Base]
|
# archive_list: Optional[list] # Archive_Base()
|
||||||
|
# contact: Optional[Contact_Base]
|
||||||
event_list: Optional[list] # Event_Base() # Priority l1
|
event_list: Optional[list] # Event_Base() # Priority l1
|
||||||
hosted_file_list: Optional[list] # Hosted_File_Base() # Priority l2
|
hosted_file_list: Optional[list] # Hosted_File_Base() # Priority l2
|
||||||
journal_list: Optional[list] # Journal_Base() # Priority l3
|
journal_list: Optional[list] # Journal_Base() # Priority l3
|
||||||
# membership: Optional[Membership_Base] # Priority l2
|
# membership_member: Optional[Membership_Member_Base] # Priority l2
|
||||||
|
# membership_member_list: Optional[list] # Membership_Base() ???
|
||||||
order_list: Optional[list] # Order_Base() # Priority l2
|
order_list: Optional[list] # Order_Base() # Priority l2
|
||||||
order_cart_list: Optional[list] # Order_Base() # Priority l2
|
order_cart_list: Optional[list] # Order_Base() # Priority l2
|
||||||
organization: Optional[Organization_Base] # Organization_Base() # Priority l3
|
organization: Optional[Union[Organization_Base, None]] # Organization_Base() # Priority l3
|
||||||
person: Optional[dict] # Person_Base() # Priority l2
|
# person: Optional[dict] # Person_Base() # Priority l2
|
||||||
|
person: Optional[Union[Person_Base, None]]
|
||||||
post_list: Optional[list] # Post_Base() # Priority l1
|
post_list: Optional[list] # Post_Base() # Priority l1
|
||||||
user_role_list: Optional[list] # User_Role_Base()
|
user_role_list: Optional[list] # User_Role_Base()
|
||||||
role_list: Optional[list] = [] # User_Role_Base() # NOTE <- This is a duplicate of above!
|
# role_list: Optional[list] = [] # User_Role_Base() # NOTE <- This is a duplicate of above!
|
||||||
|
|
||||||
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
||||||
|
|
||||||
@@ -307,14 +316,14 @@ class User_Base(BaseModel):
|
|||||||
return redis_lookup_id_random(record_id_random=values['account_id_random'], table_name='account')
|
return redis_lookup_id_random(record_id_random=values['account_id_random'], table_name='account')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@validator('contact_id', always=True)
|
# @validator('contact_id', always=True)
|
||||||
def contact_id_lookup(cls, v, values, **kwargs):
|
# def contact_id_lookup(cls, v, values, **kwargs):
|
||||||
log.setLevel(logging.WARNING)
|
# log.setLevel(logging.WARNING)
|
||||||
log.debug(locals())
|
# log.debug(locals())
|
||||||
|
|
||||||
if values['contact_id_random']:
|
# if values['contact_id_random']:
|
||||||
return redis_lookup_id_random(record_id_random=values['contact_id_random'], table_name='contact')
|
# return redis_lookup_id_random(record_id_random=values['contact_id_random'], table_name='contact')
|
||||||
return None
|
# return None
|
||||||
|
|
||||||
@validator('organization_id', always=True)
|
@validator('organization_id', always=True)
|
||||||
def organization_id_lookup(cls, v, values, **kwargs):
|
def organization_id_lookup(cls, v, values, **kwargs):
|
||||||
|
|||||||
@@ -181,8 +181,8 @@ async def lookup_membership_type_obj(
|
|||||||
|
|
||||||
# ### BEGIN ### API Membership Type ### get_membership_type_obj() ###
|
# ### BEGIN ### API Membership Type ### get_membership_type_obj() ###
|
||||||
# Working well as of 2021-06-21. Using as a template for other routes.
|
# Working well as of 2021-06-21. Using as a template for other routes.
|
||||||
@router.get('/{membership_type_id}', response_model=Resp_Body_Base)
|
@router.get('/{membership_type_id}/v5', response_model=Resp_Body_Base)
|
||||||
async def get_membership_type_obj(
|
async def get_membership_type_obj_v5(
|
||||||
membership_type_id: str = Query(..., min_length=1, max_length=22),
|
membership_type_id: str = Query(..., min_length=1, max_length=22),
|
||||||
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
|
||||||
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
|
||||||
|
|||||||
@@ -129,27 +129,74 @@ async def get_person_obj_li(
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@router.get('/{person_id}', response_model=Resp_Body_Base)
|
|
||||||
async def get_person_obj(
|
# ### BEGIN ### API Person ### get_person_obj_v5() ###
|
||||||
|
# Working well as of 2021-06-11. Using as a template for other routes.
|
||||||
|
@router.get('/{person_id}/v5', response_model=Resp_Body_Base)
|
||||||
|
async def get_person_obj_v5(
|
||||||
person_id: str = Query(..., min_length=1, max_length=22),
|
person_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_address: bool = False, # Priority l1
|
||||||
|
# inc_archive_list: bool = False, # Priority l3
|
||||||
|
inc_contact: bool = False, # Priority l1
|
||||||
|
inc_event_list: bool = False, # Priority l1
|
||||||
|
# inc_hosted_file_list: bool = False, # Priority l3
|
||||||
|
inc_journal_list: bool = False, # Priority l2
|
||||||
|
# inc_journal_entry_list: bool = False, # Priority l3
|
||||||
|
inc_membership_member: bool = False, # Priority l2
|
||||||
|
# inc_membership_list: bool = False, # ???
|
||||||
|
inc_order_line_list: bool = False, # Priority l1
|
||||||
|
inc_order_list: bool = False, # Priority l1
|
||||||
|
inc_order_cart_list: bool = False, # Priority l1
|
||||||
|
inc_organization: bool = False, # Priority l1
|
||||||
|
# inc_organization_list: bool = False,
|
||||||
|
inc_post_list: bool = False, # Priority l2
|
||||||
|
inc_post_comment_list: bool = False, # Priority l3
|
||||||
|
inc_user: bool = False, # Priority l1
|
||||||
x_account_id: str = Header(...),
|
x_account_id: str = Header(...),
|
||||||
inc_address: bool = False,
|
|
||||||
inc_contact: bool = False,
|
|
||||||
inc_organization: bool = False,
|
|
||||||
by_alias: Optional[bool] = True,
|
by_alias: Optional[bool] = True,
|
||||||
exclude_unset: Optional[bool] = True,
|
exclude_unset: Optional[bool] = True,
|
||||||
):
|
):
|
||||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(locals())
|
log.debug(locals())
|
||||||
|
|
||||||
person_obj = load_person_obj(
|
if person_id := redis_lookup_id_random(record_id_random=person_id, table_name='person'): pass
|
||||||
person_id=person_id,
|
else:
|
||||||
inc_contact=inc_contact,
|
return mk_resp(data=None, status_code=404)
|
||||||
inc_address=inc_address,
|
|
||||||
inc_organization=inc_organization,
|
if person_dict := load_person_obj(
|
||||||
).dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
person_id = person_id,
|
||||||
data = person_obj
|
limit = limit,
|
||||||
return mk_resp(data=person_obj)
|
model_as_dict = True, # NOTE: returning model as a dict
|
||||||
|
enabled = enabled,
|
||||||
|
inc_address = inc_address,
|
||||||
|
# inc_archive_list = inc_archive_list,
|
||||||
|
inc_contact = inc_contact,
|
||||||
|
inc_event_list = inc_event_list,
|
||||||
|
# inc_hosted_file_list = inc_hosted_file_list,
|
||||||
|
inc_journal_list = inc_journal_list,
|
||||||
|
# inc_journal_entry_list = inc_journal_entry_list,
|
||||||
|
inc_membership_member = inc_membership_member,
|
||||||
|
# inc_membership_list = inc_membership_list, # ???
|
||||||
|
inc_order_line_list = inc_order_line_list,
|
||||||
|
inc_order_list = inc_order_list,
|
||||||
|
inc_order_cart_list = inc_order_cart_list,
|
||||||
|
inc_organization = inc_organization,
|
||||||
|
# inc_organization_list = inc_organization_list,
|
||||||
|
inc_post_list = inc_post_list,
|
||||||
|
inc_post_comment_list = inc_post_comment_list,
|
||||||
|
inc_user = inc_user,
|
||||||
|
):
|
||||||
|
if isinstance(person_dict, dict):
|
||||||
|
response_data = person_dict
|
||||||
|
else:
|
||||||
|
response_data = person_dict
|
||||||
|
else:
|
||||||
|
return mk_resp(data=False, status_code=400) # Bad Request
|
||||||
|
|
||||||
|
return mk_resp(data=response_data)
|
||||||
|
# ### END ### API Person ### get_person_obj_v5() ###
|
||||||
|
|
||||||
|
|
||||||
@router.delete('/{obj_id}', response_model=Resp_Body_Base)
|
@router.delete('/{obj_id}', response_model=Resp_Body_Base)
|
||||||
|
|||||||
@@ -559,10 +559,10 @@ async def lookup_username(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ### BEGIN ### API User ### get_user_obj_new() ###
|
# ### BEGIN ### API User ### get_user_obj_v5() ###
|
||||||
# Working well as of 2021-06-11. Using as a template for other routes.
|
# Working well as of 2021-06-11. Using as a template for other routes.
|
||||||
@router.get('/{user_id}/json', response_model=Resp_Body_Base)
|
@router.get('/{user_id}/v5', response_model=Resp_Body_Base)
|
||||||
async def get_user_obj_new(
|
async def get_user_obj_v5(
|
||||||
user_id: str = Query(..., min_length=1, max_length=22),
|
user_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
|
||||||
@@ -573,8 +573,9 @@ async def get_user_obj_new(
|
|||||||
# inc_hosted_file_list: bool = False, # Priority l3
|
# inc_hosted_file_list: bool = False, # Priority l3
|
||||||
inc_journal_list: bool = False, # Priority l2
|
inc_journal_list: bool = False, # Priority l2
|
||||||
# inc_journal_entry_list: bool = False, # Priority l3
|
# inc_journal_entry_list: bool = False, # Priority l3
|
||||||
inc_membership: bool = False, # Priority l2
|
inc_membership_member: bool = False, # Priority l2
|
||||||
# inc_membership_list: bool = False, # ???
|
# inc_membership_list: bool = False, # ???
|
||||||
|
inc_order_line_list: bool = False, # Priority l1
|
||||||
inc_order_list: bool = False, # Priority l1
|
inc_order_list: bool = False, # Priority l1
|
||||||
inc_order_cart_list: bool = False, # Priority l1
|
inc_order_cart_list: bool = False, # Priority l1
|
||||||
inc_organization: bool = False, # Priority l1
|
inc_organization: bool = False, # Priority l1
|
||||||
@@ -582,7 +583,7 @@ async def get_user_obj_new(
|
|||||||
inc_person: bool = False, # Priority l1
|
inc_person: bool = False, # Priority l1
|
||||||
# inc_person_list: bool = False,
|
# inc_person_list: bool = False,
|
||||||
inc_post_list: bool = False, # Priority l2
|
inc_post_list: bool = False, # Priority l2
|
||||||
# inc_post_comment_list: bool = False, # Priority l3
|
inc_post_comment_list: bool = False, # Priority l3
|
||||||
inc_user_role_list: bool = False, # Priority l1
|
inc_user_role_list: bool = False, # Priority l1
|
||||||
x_account_id: str = Header(...),
|
x_account_id: str = Header(...),
|
||||||
by_alias: Optional[bool] = True,
|
by_alias: Optional[bool] = True,
|
||||||
@@ -607,8 +608,9 @@ async def get_user_obj_new(
|
|||||||
# inc_hosted_file_list = inc_hosted_file_list,
|
# inc_hosted_file_list = inc_hosted_file_list,
|
||||||
inc_journal_list = inc_journal_list,
|
inc_journal_list = inc_journal_list,
|
||||||
# inc_journal_entry_list = inc_journal_entry_list,
|
# inc_journal_entry_list = inc_journal_entry_list,
|
||||||
inc_membership = inc_membership,
|
inc_membership_member = inc_membership_member,
|
||||||
# inc_membership_list = inc_membership_list, # ???
|
# inc_membership_list = inc_membership_list, # ???
|
||||||
|
inc_order_line_list = inc_order_line_list,
|
||||||
inc_order_list = inc_order_list,
|
inc_order_list = inc_order_list,
|
||||||
inc_order_cart_list = inc_order_cart_list,
|
inc_order_cart_list = inc_order_cart_list,
|
||||||
inc_organization = inc_organization,
|
inc_organization = inc_organization,
|
||||||
@@ -627,8 +629,7 @@ async def get_user_obj_new(
|
|||||||
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 User ### get_user_obj_new() ###
|
# ### END ### API User ### get_user_obj_v5() ###
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@router.get('/{user_id}', response_model=Resp_Body_Base)
|
@router.get('/{user_id}', response_model=Resp_Body_Base)
|
||||||
|
|||||||
Reference in New Issue
Block a user