Working on membership management
This commit is contained in:
34
app/models/account_methods.py
Normal file
34
app/models/account_methods.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
from typing import Dict, List, Optional, Set, Union
|
||||||
|
from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, validator
|
||||||
|
|
||||||
|
from ..lib_general import *
|
||||||
|
from ..db_sql import sql_select
|
||||||
|
|
||||||
|
from .membership_model import Membership_Cfg_Base
|
||||||
|
|
||||||
|
|
||||||
|
# ### 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 account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'): pass
|
||||||
|
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() ###
|
||||||
@@ -32,6 +32,8 @@ class Membership_Cfg_Base(BaseModel):
|
|||||||
calendar_year_end_buffer_on: Optional[datetime.datetime] = None
|
calendar_year_end_buffer_on: Optional[datetime.datetime] = None
|
||||||
enable_privacy_view: Optional[bool] = False
|
enable_privacy_view: Optional[bool] = False
|
||||||
|
|
||||||
|
renew_warning_hours: Optional[int]
|
||||||
|
|
||||||
accept_message: Optional[str]
|
accept_message: Optional[str]
|
||||||
reject_message: Optional[str]
|
reject_message: Optional[str]
|
||||||
renew_message: Optional[str]
|
renew_message: Optional[str]
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from app.db_sql import *
|
|||||||
from .api_crud import delete_obj_template, get_obj_template, get_obj_li_template, patch_obj_template, post_obj_template
|
from .api_crud import delete_obj_template, get_obj_template, get_obj_li_template, patch_obj_template, post_obj_template
|
||||||
|
|
||||||
from ..models.account_model import Account_Base
|
from ..models.account_model import Account_Base
|
||||||
|
from ..models.account_methods import load_account_cfg_obj
|
||||||
from ..models.response_model import *
|
from ..models.response_model import *
|
||||||
|
|
||||||
|
|
||||||
@@ -126,23 +127,30 @@ async def delete_account_obj(
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@router.get('/{obj_id}/cfg', response_model=Resp_Body_Base)
|
@router.get('/{account_id}/cfg', response_model=Resp_Body_Base)
|
||||||
async def get_account_cfg_obj(
|
async def get_account_cfg_obj(
|
||||||
obj_id: str = Query(..., min_length=1, max_length=22),
|
account_id: str = Query(..., min_length=1, max_length=22),
|
||||||
|
sys_module: Optional[str] = None, # event, fundraising, membership
|
||||||
x_account_id: str = Header(...),
|
x_account_id: str = Header(...),
|
||||||
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())
|
||||||
|
|
||||||
obj_type = 'account_cfg'
|
if sys_module:
|
||||||
result = get_obj_template(
|
if sys_module == 'membership':
|
||||||
obj_type=obj_type,
|
membership_cfg_obj = load_account_cfg_obj(account_id=account_id, inc_membership_cfg=True).dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
||||||
obj_id=obj_id,
|
data = membership_cfg_obj
|
||||||
by_alias=True,
|
return mk_resp(data=data)
|
||||||
exclude_unset=True,
|
else:
|
||||||
)
|
obj_type = 'account_cfg'
|
||||||
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
result = get_obj_template(
|
||||||
log.debug(result)
|
obj_type=obj_type,
|
||||||
return result
|
obj_id=account_id,
|
||||||
|
by_alias=True,
|
||||||
|
exclude_unset=True,
|
||||||
|
)
|
||||||
|
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
log.debug(result)
|
||||||
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user