Moving stuff around to make it more easy to manage. Adding models, methods, and routes.
This commit is contained in:
@@ -7,65 +7,56 @@ from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, v
|
||||
from app.db_sql import redis_lookup_id_random, sql_select
|
||||
from app.lib_general import log, logging
|
||||
|
||||
from app.methods.event_methods import load_event_obj
|
||||
from app.methods.membership_cfg_methods import load_membership_cfg_obj
|
||||
|
||||
from app.models.account_cfg_models import Account_Cfg_Base
|
||||
# from app.models.membership_cfg_models import Membership_Cfg_Base
|
||||
|
||||
|
||||
# ### BEGIN ### API Account Methods ### load_account_cfg_obj() ###
|
||||
def load_account_cfg_obj(account_id:int|str) -> Account_Cfg_Base|bool:
|
||||
# ### BEGIN ### API Account Cfg Methods ### load_account_cfg_obj() ###
|
||||
def load_account_cfg_obj(
|
||||
account_id: int|str,
|
||||
model_as_dict: bool = False,
|
||||
# inc_event_cfg: bool = False,
|
||||
inc_fundraising_cfg: bool = False,
|
||||
inc_membership_cfg: bool = False,
|
||||
) -> Account_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 account_cfg_rec := sql_select(table_name='v_account_cfg', field_name='account_id', field_value=account_id):
|
||||
log.debug(account_cfg_rec)
|
||||
|
||||
try:
|
||||
account_cfg_obj = Account_Cfg_Base(**account_cfg_rec)
|
||||
log.debug(account_cfg_obj)
|
||||
except ValidationError as e:
|
||||
log.error(e.json())
|
||||
|
||||
return account_cfg_obj
|
||||
if account_cfg_rec := sql_select(
|
||||
table_name = 'v_account_cfg_detail', # This view should probably be cleaned up
|
||||
field_name = 'account_id',
|
||||
field_value = account_id
|
||||
): pass
|
||||
else: return False
|
||||
# ### END ### API Account Methods ### load_account_cfg_obj() ###
|
||||
log.debug(account_cfg_rec)
|
||||
try:
|
||||
account_cfg_obj = Account_Cfg_Base(**account_cfg_rec)
|
||||
log.debug(account_cfg_obj)
|
||||
except ValidationError as e:
|
||||
log.error(e.json())
|
||||
|
||||
if inc_fundraising_cfg:
|
||||
if fundraising_cfg_dict := load_fundraising_cfg_obj(
|
||||
account_id = account_id,
|
||||
model_as_dict = model_as_dict,
|
||||
):
|
||||
account_cfg_obj.fundraising_cfg = fundraising_cfg_dict
|
||||
else: account_cfg_obj.fundraising_cfg = None
|
||||
|
||||
# ### BEGIN ### API Account Methods ### load_account_cfg_obj() ###
|
||||
# def load_account_cfg_obj(account_id:int|str, inc_event_cfg:bool=False, inc_fundraising_cfg:bool=False, inc_membership_cfg:bool=False):
|
||||
# log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
# log.debug(locals())
|
||||
if inc_membership_cfg:
|
||||
if membership_cfg_dict := load_membership_cfg_obj(
|
||||
account_id = account_id,
|
||||
model_as_dict = model_as_dict,
|
||||
):
|
||||
account_cfg_obj.membership_cfg = membership_cfg_dict
|
||||
else: account_cfg_obj.membership_cfg = None
|
||||
|
||||
# if account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'): pass
|
||||
# else: return False
|
||||
|
||||
# if account_cfg_rec := sql_select(table_name='v_account_cfg', field_name='account_id', field_value=account_id):
|
||||
# log.debug(account_cfg_rec)
|
||||
|
||||
# try:
|
||||
# account_cfg_obj = Account_Cfg_Base(**account_cfg_rec)
|
||||
# log.debug(account_cfg_obj)
|
||||
# except ValidationError as e:
|
||||
# log.error(e.json())
|
||||
|
||||
# return account_cfg_obj
|
||||
# else: return False
|
||||
|
||||
# if inc_membership_cfg:
|
||||
# if membership_cfg_rec := sql_select(table_name='v_membership_cfg', field_name='account_id', field_value=account_id):
|
||||
# #log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
# log.debug(membership_cfg_rec)
|
||||
|
||||
# #account_rec['membership_cfg'] = membership_cfg_rec
|
||||
# try:
|
||||
# membership_cfg_obj = Membership_Cfg_Base(**membership_cfg_rec)
|
||||
# log.debug(membership_cfg_obj)
|
||||
# except ValidationError as e:
|
||||
# log.error(e.json())
|
||||
|
||||
# return membership_cfg_obj
|
||||
# ### END ### API Account Methods ### load_account_cfg_obj() ###
|
||||
if model_as_dict:
|
||||
return account_cfg_obj.dict(by_alias=True, exclude_unset=True) # pylint: disable=no-member
|
||||
else:
|
||||
return account_cfg_obj
|
||||
# ### END ### API Account Cfg Methods ### load_account_cfg_obj() ###
|
||||
|
||||
@@ -8,6 +8,7 @@ from app.db_sql import redis_lookup_id_random, sql_select
|
||||
from app.lib_general import log, logging
|
||||
|
||||
from app.methods.account_cfg_methods import load_account_cfg_obj
|
||||
from app.methods.archive_methods import load_archive_obj, load_archive_obj_list
|
||||
from app.methods.event_methods import load_event_obj
|
||||
|
||||
from app.models.account_models import Account_Base
|
||||
@@ -16,15 +17,19 @@ from app.models.account_cfg_models import Account_Cfg_Base
|
||||
|
||||
|
||||
# ### BEGIN ### API Account Methods ### load_account_obj() ###
|
||||
# Working well as of 2021-06-11. Using as a template for other load objects.
|
||||
def load_account_obj(
|
||||
account_id: int|str,
|
||||
enabled: str = 'enabled', # enabled, disabled, all
|
||||
limit: int = 1000,
|
||||
model_as_dict: bool = False,
|
||||
enabled: str = 'enabled', # enabled, disabled, all
|
||||
inc_account_cfg: bool = False, # Priority l1
|
||||
inc_address: bool = False, # Under contact
|
||||
inc_address_list: bool = False, # Priority l3
|
||||
inc_archive: bool = False,
|
||||
inc_archive_list: bool = False, # Priority l1
|
||||
inc_archive_content: bool = False,
|
||||
inc_archive_content_list: bool = False, # Priority l2
|
||||
inc_contact: bool = False,
|
||||
inc_contact_list: bool = False, # Priority l3
|
||||
inc_event: bool = False,
|
||||
@@ -80,7 +85,7 @@ def load_account_obj(
|
||||
inc_site_list: bool = False, # Priority l3
|
||||
inc_user: bool = False,
|
||||
inc_user_list: bool = False, # Priority l2
|
||||
) -> Account_Base|bool:
|
||||
) -> Account_Base|dict|bool:
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
@@ -100,13 +105,28 @@ def load_account_obj(
|
||||
log.error(e.json())
|
||||
|
||||
if inc_account_cfg:
|
||||
organization_id = account_rec.get('organization_id', None)
|
||||
if account_cfg_obj_result := load_account_cfg_obj(account_id=account_id):
|
||||
account_cfg_obj = account_cfg_obj_result
|
||||
account_cfg_dict = account_cfg_obj.dict(by_alias=True, exclude_unset=True)
|
||||
if account_cfg_dict := load_account_cfg_obj(
|
||||
account_id = account_id,
|
||||
model_as_dict = True,
|
||||
# inc_event_cfg = inc_event_cfg,
|
||||
inc_fundraising_cfg = inc_fundraising_cfg,
|
||||
inc_membership_cfg = inc_membership_cfg,
|
||||
):
|
||||
account_obj.account_cfg = account_cfg_dict
|
||||
else: account_obj.account_cfg = None
|
||||
|
||||
if inc_archive_list:
|
||||
if archive_dict_list := load_archive_obj_list(
|
||||
account_id = account_id,
|
||||
limit = limit,
|
||||
model_as_dict = True,
|
||||
enabled = enabled,
|
||||
inc_archive_content_list = inc_archive_content_list
|
||||
):
|
||||
account_obj.archive_list = archive_dict_list
|
||||
else: account_obj.archive_list = None
|
||||
|
||||
|
||||
# if inc_contact:
|
||||
# contact_id = account_rec.get('contact_id', None)
|
||||
# if contact_obj_result := load_contact_obj(contact_id=contact_id):
|
||||
@@ -206,5 +226,8 @@ def load_account_obj(
|
||||
account_obj.event_list = []
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
|
||||
return account_obj
|
||||
if model_as_dict:
|
||||
return account_obj.dict(by_alias=True, exclude_unset=True) # pylint: disable=no-member
|
||||
else:
|
||||
return account_obj
|
||||
# ### END ### API Account Methods ### load_account_obj() ###
|
||||
|
||||
114
app/methods/archive_content_methods.py
Normal file
114
app/methods/archive_content_methods.py
Normal file
@@ -0,0 +1,114 @@
|
||||
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.archive_content_models import Archive_Content_Base
|
||||
|
||||
|
||||
# ### BEGIN ### API Archive Content Methods ### load_archive_content_obj() ###
|
||||
def load_archive_content_obj(
|
||||
archive_content_id: int|str,
|
||||
# limit: int = 1000,
|
||||
model_as_dict: bool = False,
|
||||
# enabled: str = 'enabled', # enabled, disabled, all
|
||||
# inc_archive_content_content_list: bool = False,
|
||||
) -> Archive_Content_Base|dict|bool:
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if archive_content_id := redis_lookup_id_random(record_id_random=archive_content_id, table_name='archive_content'): pass
|
||||
else: return False
|
||||
|
||||
if archive_content_rec := sql_select(
|
||||
table_name='v_archive_content',
|
||||
record_id=archive_content_id,
|
||||
): pass
|
||||
else: return False
|
||||
log.debug(archive_content_rec)
|
||||
try:
|
||||
archive_content_obj = Archive_Content_Base(**archive_content_rec)
|
||||
log.debug(archive_content_obj)
|
||||
except ValidationError as e:
|
||||
log.error(e.json())
|
||||
|
||||
if model_as_dict:
|
||||
return archive_content_obj.dict(by_alias=True, exclude_unset=True) # pylint: disable=no-member
|
||||
else:
|
||||
return archive_content_obj
|
||||
# ### END ### API Archive Content Methods ### load_archive_content_obj() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Archive Content Methods ### load_archive_content_obj_list() ###
|
||||
def load_archive_content_obj_list(
|
||||
archive_id: int|str,
|
||||
limit: int = 1000,
|
||||
model_as_dict: bool = False,
|
||||
enabled: str = 'enabled', # enabled, disabled, all
|
||||
# inc_archive_content_content_list: bool = False,
|
||||
) -> list|bool:
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if archive_id := redis_lookup_id_random(record_id_random=archive_id, table_name='archive'): pass
|
||||
else: return False
|
||||
|
||||
data = {}
|
||||
data['archive_id'] = archive_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['archive'] = None
|
||||
|
||||
if limit:
|
||||
data['limit'] = limit
|
||||
sql_limit = f'LIMIT :limit'
|
||||
else:
|
||||
sql_limit = ''
|
||||
|
||||
sql = f"""
|
||||
SELECT `tbl`.id AS 'archive_content_id', `tbl`.id_random AS 'archive_content_id_random'
|
||||
FROM `archive_content` AS `tbl`
|
||||
WHERE `tbl`.archive_id = :archive_id
|
||||
{sql_enabled}
|
||||
ORDER BY `tbl`.created_on DESC, `tbl`.updated_on DESC
|
||||
{sql_limit};
|
||||
"""
|
||||
|
||||
if archive_content_rec_li_result := sql_select(data=data, sql=sql, as_list=True):
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(archive_content_rec_li_result)
|
||||
archive_content_result_li = []
|
||||
for archive_content_rec in archive_content_rec_li_result:
|
||||
archive_content_id = archive_content_rec.get('archive_content_id', None)
|
||||
if archive_content_result := load_archive_content_obj(
|
||||
archive_content_id=archive_content_id,
|
||||
model_as_dict=model_as_dict,
|
||||
# enabled=enabled,
|
||||
# inc_archive_content_content_list=inc_archive_content_content_list,
|
||||
):
|
||||
log.debug(archive_content_result)
|
||||
archive_content_result_li.append(archive_content_result)
|
||||
else:
|
||||
log.debug(archive_content_result)
|
||||
archive_content_result_li.append(None)
|
||||
log.debug(archive_content_result_li)
|
||||
else:
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(archive_content_rec_li_result)
|
||||
archive_content_result_li = []
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
|
||||
return archive_content_result_li
|
||||
# ### END ### API Archive Content Methods ### load_archive_content_obj_list() ###
|
||||
127
app/methods/archive_methods.py
Normal file
127
app/methods/archive_methods.py
Normal file
@@ -0,0 +1,127 @@
|
||||
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.methods.archive_content_methods import load_archive_content_obj, load_archive_content_obj_list
|
||||
|
||||
from app.models.archive_models import Archive_Base
|
||||
|
||||
|
||||
# ### BEGIN ### API Archive Methods ### load_archive_obj() ###
|
||||
def load_archive_obj(
|
||||
archive_id: int|str,
|
||||
limit: int = 1000,
|
||||
model_as_dict: bool = False,
|
||||
enabled: str = 'enabled', # enabled, disabled, all
|
||||
inc_archive_content_list: bool = False,
|
||||
) -> Archive_Base|dict|bool:
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if archive_id := redis_lookup_id_random(record_id_random=archive_id, table_name='archive'): pass
|
||||
else: return False
|
||||
|
||||
if archive_rec := sql_select(
|
||||
table_name='v_archive',
|
||||
record_id=archive_id,
|
||||
): pass
|
||||
else: return False
|
||||
log.debug(archive_rec)
|
||||
try:
|
||||
archive_obj = Archive_Base(**archive_rec)
|
||||
log.debug(archive_obj)
|
||||
except ValidationError as e:
|
||||
log.error(e.json())
|
||||
|
||||
if inc_archive_content_list:
|
||||
if archive_content_dict_list := load_archive_content_obj_list(
|
||||
archive_id = archive_id,
|
||||
limit=limit,
|
||||
model_as_dict = True,
|
||||
enabled=enabled,
|
||||
# inc_archive_content_content_list=inc_archive_content_content_list
|
||||
):
|
||||
archive_obj.archive_content_list = archive_content_dict_list
|
||||
else: archive_obj.archive_content_list = None
|
||||
|
||||
if model_as_dict:
|
||||
return archive_obj.dict(by_alias=True, exclude_unset=True) # pylint: disable=no-member
|
||||
else:
|
||||
return archive_obj
|
||||
# ### END ### API Archive Methods ### load_archive_obj() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Archive Methods ### load_archive_obj_list() ###
|
||||
def load_archive_obj_list(
|
||||
account_id: int|str,
|
||||
limit: int = 1000,
|
||||
model_as_dict: bool = False,
|
||||
enabled: str = 'enabled', # enabled, disabled, all
|
||||
inc_archive_content_list: bool = False,
|
||||
) -> list|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
|
||||
|
||||
data = {}
|
||||
data['account_id'] = account_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 'archive_id', `tbl`.id_random AS 'archive_id_random'
|
||||
FROM `archive` AS `tbl`
|
||||
WHERE `tbl`.account_id = :account_id
|
||||
{sql_enabled}
|
||||
ORDER BY `tbl`.created_on DESC, `tbl`.updated_on DESC
|
||||
{sql_limit};
|
||||
"""
|
||||
|
||||
if archive_rec_li_result := sql_select(data=data, sql=sql, as_list=True):
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(archive_rec_li_result)
|
||||
archive_result_li = []
|
||||
for archive_rec in archive_rec_li_result:
|
||||
archive_id = archive_rec.get('archive_id', None)
|
||||
if archive_result := load_archive_obj(
|
||||
archive_id=archive_id,
|
||||
model_as_dict=model_as_dict,
|
||||
enabled=enabled,
|
||||
inc_archive_content_list=inc_archive_content_list,
|
||||
):
|
||||
log.debug(archive_result)
|
||||
archive_result_li.append(archive_result)
|
||||
else:
|
||||
log.debug(archive_result)
|
||||
archive_result_li.append(None)
|
||||
log.debug(archive_result_li)
|
||||
else:
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(archive_rec_li_result)
|
||||
archive_result_li = []
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
|
||||
return archive_result_li
|
||||
# ### END ### API Archive Methods ### load_archive_obj_list() ###
|
||||
41
app/methods/fundraising_cfg_methods.py
Normal file
41
app/methods/fundraising_cfg_methods.py
Normal file
@@ -0,0 +1,41 @@
|
||||
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.fundraising_cfg_models import Fundraising_Cfg_Base
|
||||
|
||||
|
||||
# ### BEGIN ### API Fundraising Cfg Methods ### load_fundraising_cfg_obj() ###
|
||||
def load_fundraising_cfg_obj(
|
||||
account_id: int|str,
|
||||
model_as_dict: bool = False,
|
||||
) -> Fundraising_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 fundraising_cfg_rec := sql_select(
|
||||
table_name = 'v_fundraising_cfg',
|
||||
field_name = 'account_id',
|
||||
field_value = account_id
|
||||
): pass
|
||||
else: return False
|
||||
log.debug(fundraising_cfg_rec)
|
||||
try:
|
||||
fundraising_cfg_obj = Fundraising_Cfg_Base(**fundraising_cfg_rec)
|
||||
log.debug(fundraising_cfg_obj)
|
||||
except ValidationError as e:
|
||||
log.error(e.json())
|
||||
|
||||
if model_as_dict:
|
||||
return fundraising_cfg_obj.dict(by_alias=True, exclude_unset=True) # pylint: disable=no-member
|
||||
else:
|
||||
return fundraising_cfg_obj
|
||||
# ### END ### API Fundraising Cfg Methods ### load_fundraising_cfg_obj() ###
|
||||
41
app/methods/membership_cfg_methods.py
Normal file
41
app/methods/membership_cfg_methods.py
Normal file
@@ -0,0 +1,41 @@
|
||||
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.membership_cfg_models import Membership_Cfg_Base
|
||||
|
||||
|
||||
# ### BEGIN ### API Membership Cfg Methods ### load_membership_cfg_obj() ###
|
||||
def load_membership_cfg_obj(
|
||||
account_id: int|str,
|
||||
model_as_dict: bool = False,
|
||||
) -> Membership_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 membership_cfg_rec := sql_select(
|
||||
table_name = 'v_membership_cfg',
|
||||
field_name = 'account_id',
|
||||
field_value = account_id
|
||||
): pass
|
||||
else: return False
|
||||
log.debug(membership_cfg_rec)
|
||||
try:
|
||||
membership_cfg_obj = Membership_Cfg_Base(**membership_cfg_rec)
|
||||
log.debug(membership_cfg_obj)
|
||||
except ValidationError as e:
|
||||
log.error(e.json())
|
||||
|
||||
if model_as_dict:
|
||||
return membership_cfg_obj.dict(by_alias=True, exclude_unset=True) # pylint: disable=no-member
|
||||
else:
|
||||
return membership_cfg_obj
|
||||
# ### END ### API Membership Cfg Methods ### load_membership_cfg_obj() ###
|
||||
@@ -8,6 +8,8 @@ from app.db_sql import redis_lookup_id_random
|
||||
from app.lib_general import *
|
||||
|
||||
from app.models.common_field_schema import base_fields, default_num_bytes
|
||||
from app.models.fundraising_cfg_models import Fundraising_Cfg_Base
|
||||
from app.models.membership_models import Membership_Cfg_Base
|
||||
|
||||
|
||||
class Account_Cfg_Base(BaseModel):
|
||||
@@ -87,6 +89,10 @@ class Account_Cfg_Base(BaseModel):
|
||||
created_on: Optional[datetime.datetime] = None
|
||||
updated_on: Optional[datetime.datetime] = None
|
||||
|
||||
# Including other related objects
|
||||
fundraising_cfg: Optional[Fundraising_Cfg_Base] # Priority l2
|
||||
membership_cfg: Optional[Membership_Cfg_Base] # Priority l2
|
||||
|
||||
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
||||
|
||||
#@validator('account_cfg_id_random', always=True)
|
||||
|
||||
@@ -47,7 +47,7 @@ class Archive_Content_Base(BaseModel):
|
||||
file_extension: Optional[str]
|
||||
|
||||
original_datetime: Optional[datetime.datetime] = None
|
||||
original_datetime_timezone: Optional[datetime.datetime] = None
|
||||
original_datetime_timezone: Optional[str] = None
|
||||
original_location: Optional[str] = None
|
||||
original_address_id: Optional[int] = None
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class Archive_Base(BaseModel):
|
||||
content_url_text: Optional[str]
|
||||
|
||||
original_datetime: Optional[datetime.datetime] = None
|
||||
original_datetime_timezone: Optional[datetime.datetime] = None
|
||||
original_datetime_timezone: Optional[str] = None
|
||||
original_location: Optional[str] = None
|
||||
original_address_id: Optional[int] = None
|
||||
|
||||
@@ -58,6 +58,9 @@ class Archive_Base(BaseModel):
|
||||
created_on: Optional[datetime.datetime] = None
|
||||
updated_on: Optional[datetime.datetime] = None
|
||||
|
||||
# Including other related objects
|
||||
archive_content_list: Optional[list] # Archive_Content_Base()
|
||||
|
||||
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
||||
|
||||
#@validator('archive_id_random', always=True)
|
||||
|
||||
@@ -99,6 +99,9 @@ class Event_Base(BaseModel):
|
||||
created_on: Optional[datetime.datetime] = None
|
||||
updated_on: Optional[datetime.datetime] = None
|
||||
|
||||
# Including JSON data
|
||||
event_session_proposal_questions: Optional[Json] # list of dicts (custom for client) for event_session proposals
|
||||
|
||||
# Including other related objects
|
||||
address_location: Optional[Address_Base]
|
||||
contact_1: Optional[Contact_Base]
|
||||
|
||||
@@ -33,12 +33,14 @@ class Membership_Cfg_Base(BaseModel):
|
||||
reject_message: Optional[str]
|
||||
renew_message: Optional[str]
|
||||
|
||||
#extended_membership_profile: Optional[str] # list of dicts outlining extended (custom) membership profile fields for client
|
||||
extended_membership_profile: Optional[Json] = '[]' # list of dicts outlining extended (custom) membership profile fields for client
|
||||
|
||||
default_no_reply_email: Optional[str]
|
||||
default_no_reply_name: Optional[str]
|
||||
confirm_email: Optional[str]
|
||||
confirm_name: Optional[str]
|
||||
|
||||
# Including JSON data
|
||||
# extended_membership_profile: Optional[str] # list of dicts outlining extended (custom) membership profile fields for client
|
||||
# extended_membership_profile: Optional[Json] = '[]' # list of dicts outlining extended (custom) membership profile fields for client
|
||||
extended_membership_profile: Optional[Json] # list of dicts outlining extended (custom) membership profile fields for client
|
||||
|
||||
Membership_Cfg_Base.update_forward_refs()
|
||||
|
||||
@@ -9,7 +9,8 @@ from app.db_sql import *
|
||||
|
||||
from app.routers.api_crud import delete_obj_template, get_obj_template, get_obj_li_template, patch_obj_template, post_obj_template
|
||||
|
||||
from app.methods.account_methods import load_account_obj, load_account_cfg_obj
|
||||
from app.methods.account_methods import load_account_obj
|
||||
from app.methods.account_cfg_methods import load_account_cfg_obj
|
||||
|
||||
from app.models.account_models import Account_Base
|
||||
from app.models.response_models import *
|
||||
@@ -91,17 +92,19 @@ async def get_account_obj_li(
|
||||
|
||||
|
||||
# ### BEGIN ### API Account ### get_account_obj() ###
|
||||
# Working well as of 2021-06-04. Using as a template for other routes.
|
||||
# Working well as of 2021-06-11. Using as a template for other routes.
|
||||
@router.get('/{account_id}', response_model=Resp_Body_Base)
|
||||
async def get_account_obj_new(
|
||||
account_id: str = Query(..., min_length=1, max_length=22),
|
||||
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
|
||||
enabled: str = 'enabled', # For now this covers any included objects or object lists
|
||||
inc_account_cfg: bool = False, # Priority l1
|
||||
inc_address: bool = False, # Under contact
|
||||
inc_address_list: bool = False,
|
||||
inc_archive: bool = False,
|
||||
# inc_archive: bool = False,
|
||||
inc_archive_list: bool = False, # Priority l1
|
||||
# inc_archive_content: bool = False,
|
||||
inc_archive_content_list: bool = False, # Priority l2
|
||||
inc_contact: bool = False,
|
||||
inc_contact_list: bool = False,
|
||||
inc_event: bool = False,
|
||||
@@ -166,64 +169,67 @@ async def get_account_obj_new(
|
||||
else:
|
||||
return mk_resp(data=None, status_code=404)
|
||||
|
||||
if account_obj := load_account_obj(
|
||||
account_id=account_id,
|
||||
enabled=enabled,
|
||||
limit=limit,
|
||||
inc_address=inc_address,
|
||||
inc_address_list=inc_address_list,
|
||||
inc_archive=inc_archive,
|
||||
inc_archive_list=inc_archive_list,
|
||||
inc_contact=inc_contact,
|
||||
inc_contact_list=inc_contact_list,
|
||||
inc_event=inc_event,
|
||||
inc_event_list=inc_event_list,
|
||||
# inc_event_abstract_list=inc_event_abstract_list,
|
||||
# inc_event_badge_list=inc_event_badge_list,
|
||||
# inc_event_device_list=inc_event_device_list,
|
||||
inc_event_file_list=inc_event_file_list,
|
||||
# inc_event_location=inc_event_location,
|
||||
# inc_event_person=inc_event_person,
|
||||
inc_event_person_list=inc_event_person_list,
|
||||
inc_event_presentation_list=inc_event_presentation_list,
|
||||
# inc_event_presenter_cat=inc_event_presenter_cat,
|
||||
inc_event_presenter_list=inc_event_presenter_list,
|
||||
inc_event_registration_list=inc_event_registration_list,
|
||||
inc_event_session_list=inc_event_session_list,
|
||||
# inc_event_track=inc_event_track,
|
||||
inc_event_track_list=inc_event_track_list,
|
||||
inc_fundraising_cfg=inc_fundraising_cfg,
|
||||
inc_hosted_file_list=inc_hosted_file_list,
|
||||
inc_journal_list=inc_journal_list,
|
||||
# inc_membership=inc_membership,
|
||||
inc_membership_cfg=inc_membership_cfg,
|
||||
inc_membership_list=inc_membership_list,
|
||||
# inc_order=inc_order,
|
||||
inc_order_list=inc_order_list,
|
||||
# inc_order_cart=inc_order_cart,
|
||||
inc_order_cart_list=inc_order_cart_list,
|
||||
inc_organization=inc_organization,
|
||||
inc_organization_list=inc_organization_list,
|
||||
inc_person=inc_person,
|
||||
inc_person_list=inc_person_list,
|
||||
# inc_post=inc_post,
|
||||
inc_post_list=inc_post_list,
|
||||
# inc_product=inc_product,
|
||||
inc_product_list=inc_product_list,
|
||||
# inc_site=inc_site,
|
||||
inc_site_list=inc_site_list,
|
||||
inc_user=inc_user,
|
||||
inc_user_list=inc_user_list,
|
||||
if account_dict := load_account_obj(
|
||||
account_id = account_id,
|
||||
enabled = enabled,
|
||||
limit = limit,
|
||||
model_as_dict = True, # NOTE: returning model as a dict
|
||||
inc_account_cfg = inc_account_cfg,
|
||||
inc_address = inc_address,
|
||||
inc_address_list = inc_address_list,
|
||||
# inc_archive = inc_archive,
|
||||
inc_archive_list = inc_archive_list,
|
||||
# inc_archive_content = inc_archive_content,
|
||||
inc_archive_content_list = inc_archive_content_list,
|
||||
inc_contact = inc_contact,
|
||||
inc_contact_list = inc_contact_list,
|
||||
inc_event = inc_event,
|
||||
inc_event_list = inc_event_list,
|
||||
# inc_event_abstract_list = inc_event_abstract_list,
|
||||
# inc_event_badge_list = inc_event_badge_list,
|
||||
# inc_event_device_list = inc_event_device_list,
|
||||
inc_event_file_list = inc_event_file_list,
|
||||
# inc_event_location = inc_event_location,
|
||||
# inc_event_person = inc_event_person,
|
||||
inc_event_person_list = inc_event_person_list,
|
||||
inc_event_presentation_list = inc_event_presentation_list,
|
||||
# inc_event_presenter_cat = inc_event_presenter_cat,
|
||||
inc_event_presenter_list = inc_event_presenter_list,
|
||||
inc_event_registration_list = inc_event_registration_list,
|
||||
inc_event_session_list = inc_event_session_list,
|
||||
# inc_event_track = inc_event_track,
|
||||
inc_event_track_list = inc_event_track_list,
|
||||
inc_fundraising_cfg = inc_fundraising_cfg,
|
||||
inc_hosted_file_list = inc_hosted_file_list,
|
||||
inc_journal_list = inc_journal_list,
|
||||
# inc_membership = inc_membership,
|
||||
inc_membership_cfg = inc_membership_cfg,
|
||||
inc_membership_list = inc_membership_list,
|
||||
# inc_order = inc_order,
|
||||
inc_order_list = inc_order_list,
|
||||
# inc_order_cart = inc_order_cart,
|
||||
inc_order_cart_list = inc_order_cart_list,
|
||||
inc_organization = inc_organization,
|
||||
inc_organization_list = inc_organization_list,
|
||||
inc_person = inc_person,
|
||||
inc_person_list = inc_person_list,
|
||||
# inc_post = inc_post,
|
||||
inc_post_list = inc_post_list,
|
||||
# inc_product = inc_product,
|
||||
inc_product_list = inc_product_list,
|
||||
# inc_site = inc_site,
|
||||
inc_site_list = inc_site_list,
|
||||
inc_user = inc_user,
|
||||
inc_user_list = inc_user_list,
|
||||
):
|
||||
if isinstance(account_obj, Account_Base):
|
||||
response_data = account_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset) # pylint: disable=no-member
|
||||
if isinstance(account_dict, dict):
|
||||
response_data = account_dict
|
||||
else:
|
||||
response_data = account_obj
|
||||
response_data = account_dict
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400) # Bad Request
|
||||
|
||||
return mk_resp(data=response_data)
|
||||
#return mk_resp(data=account_obj)
|
||||
# ### END ### API Account ### get_account_obj() ###
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user