Work on better way to update objects. A lot of work! Also a lot of clean up.
This commit is contained in:
@@ -19,6 +19,7 @@ def load_account_obj(
|
|||||||
account_id: int|str,
|
account_id: int|str,
|
||||||
enabled: str = 'enabled', # enabled, disabled, all
|
enabled: str = 'enabled', # enabled, disabled, all
|
||||||
limit: int = 1000,
|
limit: int = 1000,
|
||||||
|
inc_account_cfg: bool = False,
|
||||||
inc_address: bool = False, # Under contact
|
inc_address: bool = False, # Under contact
|
||||||
inc_address_list: bool = False,
|
inc_address_list: bool = False,
|
||||||
inc_archive: bool = False,
|
inc_archive: bool = False,
|
||||||
@@ -54,13 +55,27 @@ def load_account_obj(
|
|||||||
inc_event_session_list: bool = False,
|
inc_event_session_list: bool = False,
|
||||||
inc_event_track: bool = False, # For event_session child object
|
inc_event_track: bool = False, # For event_session child object
|
||||||
inc_event_track_list: bool = False,
|
inc_event_track_list: bool = False,
|
||||||
|
inc_fundraising_cfg: bool = False,
|
||||||
|
inc_hosted_file_list: bool = False,
|
||||||
|
inc_journal_list: bool = False,
|
||||||
|
inc_membership: bool = False,
|
||||||
|
inc_membership_list: bool = False,
|
||||||
inc_order: bool = False,
|
inc_order: bool = False,
|
||||||
inc_order_list: bool = False,
|
inc_order_list: bool = False,
|
||||||
inc_order_cart: bool = False,
|
inc_order_cart: bool = False,
|
||||||
inc_order_cart_list: bool = False,
|
inc_order_cart_list: bool = False,
|
||||||
inc_organization: bool = False,
|
inc_organization: bool = False,
|
||||||
|
inc_organization_list: bool = False,
|
||||||
inc_person: bool = False,
|
inc_person: bool = False,
|
||||||
inc_user: bool = False
|
inc_person_list: bool = False,
|
||||||
|
inc_post: bool = False,
|
||||||
|
inc_post_list: bool = False,
|
||||||
|
inc_product: bool = False,
|
||||||
|
inc_product_list: bool = False,
|
||||||
|
inc_site: bool = False,
|
||||||
|
inc_site_list: bool = False,
|
||||||
|
inc_user: bool = False,
|
||||||
|
inc_user_list: bool = False,
|
||||||
) -> Account_Base|bool:
|
) -> Account_Base|bool:
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(locals())
|
log.debug(locals())
|
||||||
@@ -68,7 +83,7 @@ def load_account_obj(
|
|||||||
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
|
||||||
else: return False
|
else: return False
|
||||||
|
|
||||||
if account_rec := sql_select(table_name='v_account', record_id=account_id): pass
|
if account_rec := sql_select(table_name='account', record_id=account_id): pass
|
||||||
else: return False
|
else: return False
|
||||||
|
|
||||||
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
@@ -150,15 +165,16 @@ def load_account_obj(
|
|||||||
if event_obj := load_event_obj(
|
if event_obj := load_event_obj(
|
||||||
event_id=event_id,
|
event_id=event_id,
|
||||||
enabled=enabled,
|
enabled=enabled,
|
||||||
inc_address=inc_address,
|
inc_location_address=inc_address,
|
||||||
inc_contact=inc_contact,
|
inc_contact_1=inc_contact,
|
||||||
|
inc_contact_2=inc_contact,
|
||||||
|
inc_contact_3=inc_contact,
|
||||||
inc_event_abstract_list=inc_event_abstract_list,
|
inc_event_abstract_list=inc_event_abstract_list,
|
||||||
inc_event_badge_list=inc_event_badge_list,
|
inc_event_badge_list=inc_event_badge_list,
|
||||||
inc_event_device_list=inc_event_device_list,
|
inc_event_device_list=inc_event_device_list,
|
||||||
inc_event_exhibit_list=inc_event_exhibit_list,
|
inc_event_exhibit_list=inc_event_exhibit_list,
|
||||||
inc_event_file_list=inc_event_file_list,
|
inc_event_file_list=inc_event_file_list,
|
||||||
inc_event_location_list=inc_event_location_list,
|
inc_event_location_list=inc_event_location_list,
|
||||||
inc_event_person=inc_event_person,
|
|
||||||
inc_event_person_list=inc_event_person_list,
|
inc_event_person_list=inc_event_person_list,
|
||||||
inc_event_presentation_list=inc_event_presentation_list,
|
inc_event_presentation_list=inc_event_presentation_list,
|
||||||
inc_event_presenter_list=inc_event_presenter_list,
|
inc_event_presenter_list=inc_event_presenter_list,
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ def load_event_obj(
|
|||||||
inc_event_track_list: bool = False,
|
inc_event_track_list: bool = False,
|
||||||
inc_location_address: bool = False,
|
inc_location_address: bool = False,
|
||||||
inc_poc_event_person: bool = False,
|
inc_poc_event_person: bool = False,
|
||||||
|
inc_person: bool = False,
|
||||||
|
inc_user: bool = False,
|
||||||
) -> Event_Base|bool:
|
) -> Event_Base|bool:
|
||||||
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(locals())
|
log.debug(locals())
|
||||||
@@ -144,6 +146,8 @@ def load_event_obj(
|
|||||||
inc_event_presenter_cat=inc_event_presenter_cat,
|
inc_event_presenter_cat=inc_event_presenter_cat,
|
||||||
inc_event_presenter_list=inc_event_presenter_list,
|
inc_event_presenter_list=inc_event_presenter_list,
|
||||||
#inc_event_track=inc_event_track,
|
#inc_event_track=inc_event_track,
|
||||||
|
inc_person=inc_person,
|
||||||
|
inc_user=inc_user,
|
||||||
):
|
):
|
||||||
data = event_session_obj.dict(by_alias=True, exclude_unset=True)
|
data = event_session_obj.dict(by_alias=True, exclude_unset=True)
|
||||||
event_session_obj_li.append(data)
|
event_session_obj_li.append(data)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from app.models.account_cfg_models import Account_Cfg_Base
|
|||||||
# from app.models.address_models import Address_Base
|
# from app.models.address_models import Address_Base
|
||||||
# from app.models.contact_models import Contact_Base
|
# from app.models.contact_models import Contact_Base
|
||||||
# from app.models.event_models import Event_Base
|
# from app.models.event_models import Event_Base
|
||||||
|
from app.models.fundraising_cfg_models import Fundraising_Cfg_Base
|
||||||
# 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
|
||||||
|
|
||||||
@@ -48,15 +49,16 @@ class Account_Base(BaseModel):
|
|||||||
archive_list: Optional[list] # Archive_Base()
|
archive_list: Optional[list] # Archive_Base()
|
||||||
contact_list: Optional[list] # Contact_Base()
|
contact_list: Optional[list] # Contact_Base()
|
||||||
event_list: Optional[list] # Event_Base()
|
event_list: Optional[list] # Event_Base()
|
||||||
|
fundraising_cfg: Optional[Fundraising_Cfg_Base]
|
||||||
journal_list: Optional[list] # Journal_Base()
|
journal_list: Optional[list] # Journal_Base()
|
||||||
order_list: Optional[list] # Order_Base()
|
order_list: Optional[list] # Order_Base()
|
||||||
organization_list: Optional[list] # Organization_Base()
|
organization_list: Optional[list] # Organization_Base()
|
||||||
page: Optional[list] # Page_Base()
|
page_list: Optional[list] # Page_Base()
|
||||||
person: Optional[list] # Person_Base()
|
person_list: Optional[list] # Person_Base()
|
||||||
post: Optional[list] # Post_Base()
|
post_list: Optional[list] # Post_Base()
|
||||||
product: Optional[list] # Product_Base()
|
product_list: Optional[list] # Product_Base()
|
||||||
site: Optional[list] # Site_Base()
|
site_list: Optional[list] # Site_Base()
|
||||||
user: Optional[list] # User_Base()
|
user_list: Optional[list] # User_Base()
|
||||||
|
|
||||||
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ base_fields['event_session_id_random'] = xxx_id_random_field_schema
|
|||||||
base_fields['event_track_id_random'] = xxx_id_random_field_schema
|
base_fields['event_track_id_random'] = xxx_id_random_field_schema
|
||||||
base_fields['flask_cfg_id_random'] = xxx_id_random_field_schema
|
base_fields['flask_cfg_id_random'] = xxx_id_random_field_schema
|
||||||
base_fields['fundraising_id_random'] = xxx_id_random_field_schema
|
base_fields['fundraising_id_random'] = xxx_id_random_field_schema
|
||||||
|
base_fields['fundraising_cfg_id_random'] = xxx_id_random_field_schema
|
||||||
base_fields['hosted_file_id_random'] = xxx_id_random_field_schema
|
base_fields['hosted_file_id_random'] = xxx_id_random_field_schema
|
||||||
base_fields['journal_id_random'] = xxx_id_random_field_schema
|
base_fields['journal_id_random'] = xxx_id_random_field_schema
|
||||||
base_fields['journal_entry_id_random'] = xxx_id_random_field_schema
|
base_fields['journal_entry_id_random'] = xxx_id_random_field_schema
|
||||||
|
|||||||
66
app/models/fundraising_cfg_models.py
Normal file
66
app/models/fundraising_cfg_models.py
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
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 *
|
||||||
|
|
||||||
|
from app.models.common_field_schema import base_fields, default_num_bytes
|
||||||
|
|
||||||
|
|
||||||
|
class Fundraising_Cfg_Base(BaseModel):
|
||||||
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
log.debug(locals())
|
||||||
|
|
||||||
|
id_random: Optional[str] = Field(
|
||||||
|
**base_fields['fundraising_cfg_id_random'],
|
||||||
|
alias='fundraising_cfg_id_random',
|
||||||
|
default_factory=lambda:secrets.token_urlsafe(default_num_bytes),
|
||||||
|
)
|
||||||
|
id: Optional[int] = Field(
|
||||||
|
#alias='fundraising_cfg_id'
|
||||||
|
)
|
||||||
|
account_id_random: Optional[str]
|
||||||
|
account_id: Optional[int]
|
||||||
|
|
||||||
|
order_thanks: Optional[str]
|
||||||
|
order_message: Optional[str]
|
||||||
|
message: Optional[str]
|
||||||
|
|
||||||
|
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
||||||
|
|
||||||
|
#@validator('fundraising_cfg_id_random', always=True)
|
||||||
|
def fundraising_cfg_id_random_copy(cls, v, values, **kwargs):
|
||||||
|
log.setLevel(logging.WARNING)
|
||||||
|
log.debug(locals())
|
||||||
|
|
||||||
|
if values['id_random']:
|
||||||
|
return values['id_random']
|
||||||
|
return None
|
||||||
|
|
||||||
|
@validator('id', always=True)
|
||||||
|
def fundraising_cfg_id_lookup(cls, v, values, **kwargs):
|
||||||
|
log.setLevel(logging.WARNING)
|
||||||
|
log.debug(locals())
|
||||||
|
|
||||||
|
if values['id_random']:
|
||||||
|
log.debug(values['id_random'])
|
||||||
|
return redis_lookup_id_random(record_id_random=values['id_random'], table_name='fundraising_cfg')
|
||||||
|
return None
|
||||||
|
|
||||||
|
@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
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
underscore_attrs_are_private = True
|
||||||
|
fields = base_fields
|
||||||
|
|
||||||
|
#Fundraising_Cfg_Base.update_forward_refs()
|
||||||
@@ -9,7 +9,7 @@ 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.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_cfg_obj
|
from app.methods.account_methods import load_account_obj, load_account_cfg_obj
|
||||||
|
|
||||||
from app.models.account_models import Account_Base
|
from app.models.account_models import Account_Base
|
||||||
from app.models.response_models import *
|
from app.models.response_models import *
|
||||||
@@ -90,6 +90,138 @@ async def get_account_obj_li(
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
# ### BEGIN ### API Account ### get_account_obj() ###
|
||||||
|
# Working well as of 2021-06-04. 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
|
||||||
|
inc_account_cfg: bool = False,
|
||||||
|
inc_address: bool = False, # Under contact
|
||||||
|
inc_address_list: bool = False,
|
||||||
|
inc_archive: bool = False,
|
||||||
|
inc_archive_list: bool = False,
|
||||||
|
inc_contact: bool = False,
|
||||||
|
inc_contact_list: bool = False,
|
||||||
|
inc_event: bool = False,
|
||||||
|
inc_event_list: bool = False,
|
||||||
|
inc_event_abstract: bool = False,
|
||||||
|
inc_event_abstract_list: bool = False,
|
||||||
|
inc_event_badge: bool = False,
|
||||||
|
inc_event_badge_list: bool = False,
|
||||||
|
inc_event_cfg: bool = False,
|
||||||
|
inc_event_device: bool = False,
|
||||||
|
inc_event_device_list: bool = False,
|
||||||
|
inc_event_exhibit: bool = False,
|
||||||
|
inc_event_exhibit_list: bool = False,
|
||||||
|
inc_event_file: bool = False,
|
||||||
|
inc_event_file_list: bool = False,
|
||||||
|
inc_event_location: bool = False, # For event_session child object
|
||||||
|
inc_event_location_list: bool = False,
|
||||||
|
inc_event_person: bool = False,
|
||||||
|
inc_event_person_list: bool = False,
|
||||||
|
inc_event_presentation: bool = False,
|
||||||
|
inc_event_presentation_list: bool = False,
|
||||||
|
inc_event_presenter_cat: bool = False, # For event_session child object
|
||||||
|
inc_event_presenter: bool = False,
|
||||||
|
inc_event_presenter_list: bool = False,
|
||||||
|
inc_event_registration: bool = False,
|
||||||
|
inc_event_registration_cfg: bool = False,
|
||||||
|
inc_event_registration_list: bool = False,
|
||||||
|
inc_event_session: bool = False,
|
||||||
|
inc_event_session_list: bool = False,
|
||||||
|
inc_event_track: bool = False, # For event_session child object
|
||||||
|
inc_event_track_list: bool = False,
|
||||||
|
inc_fundraising_cfg: bool = False,
|
||||||
|
inc_hosted_file_list: bool = False,
|
||||||
|
inc_journal_list: bool = False,
|
||||||
|
inc_membership: bool = False,
|
||||||
|
inc_membership_list: bool = False,
|
||||||
|
inc_order: bool = False,
|
||||||
|
inc_order_list: bool = False,
|
||||||
|
inc_order_cart: bool = False,
|
||||||
|
inc_order_cart_list: bool = False,
|
||||||
|
inc_organization: bool = False,
|
||||||
|
inc_organization_list: bool = False,
|
||||||
|
inc_person: bool = False,
|
||||||
|
inc_person_list: bool = False,
|
||||||
|
inc_post: bool = False,
|
||||||
|
inc_post_list: bool = False,
|
||||||
|
inc_product: bool = False,
|
||||||
|
inc_product_list: bool = False,
|
||||||
|
inc_site: bool = False,
|
||||||
|
inc_site_list: bool = False,
|
||||||
|
inc_user: bool = False,
|
||||||
|
inc_user_list: bool = False,
|
||||||
|
x_account_id: str = Header(...),
|
||||||
|
by_alias: Optional[bool] = True,
|
||||||
|
exclude_unset: Optional[bool] = True,
|
||||||
|
):
|
||||||
|
log.setLevel(logging.DEBUG) # 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 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_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_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,
|
||||||
|
):
|
||||||
|
account_dict = account_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
return mk_resp(data=False, status_code=400) # Bad Request
|
||||||
|
|
||||||
|
return mk_resp(data=account_dict)
|
||||||
|
#return mk_resp(data=account_obj)
|
||||||
|
# ### END ### API Account ### get_account_obj() ###
|
||||||
|
|
||||||
|
|
||||||
@router.get('/{obj_id}', response_model=Resp_Body_Base)
|
@router.get('/{obj_id}', response_model=Resp_Body_Base)
|
||||||
async def get_account_obj(
|
async def get_account_obj(
|
||||||
obj_id: str = Query(..., min_length=1, max_length=22),
|
obj_id: str = Query(..., min_length=1, max_length=22),
|
||||||
|
|||||||
Reference in New Issue
Block a user