Working on event_person and session proposals. Also general clean up of models and methods.
This commit is contained in:
@@ -7,12 +7,14 @@ from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, v
|
|||||||
from ..lib_general import *
|
from ..lib_general import *
|
||||||
from ..db_sql import redis_lookup_id_random, sql_insert, sql_select, sql_update
|
from ..db_sql import redis_lookup_id_random, sql_insert, sql_select, sql_update
|
||||||
|
|
||||||
|
from ..models.person_methods import load_person_obj
|
||||||
|
from ..models.user_methods import load_user_obj
|
||||||
from ..models.event_person_models import Event_Person_New_Base, Event_Person_Base
|
from ..models.event_person_models import Event_Person_New_Base, Event_Person_Base
|
||||||
|
|
||||||
|
|
||||||
# ### BEGIN ### API Event Person Methods ### create_event_person_obj() ###
|
# ### BEGIN ### API Event Person Methods ### create_event_person_obj() ###
|
||||||
def create_event_person_obj(event_person_obj_new:Event_Person_Base) -> int|bool:
|
def create_event_person_obj(event_person_obj_new:Event_Person_Base) -> int|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 not event_person_obj_new:
|
if not event_person_obj_new:
|
||||||
@@ -45,7 +47,7 @@ def load_event_person_obj(
|
|||||||
inc_person:bool=False,
|
inc_person:bool=False,
|
||||||
inc_user:bool=False
|
inc_user:bool=False
|
||||||
) -> Event_Person_Base|bool:
|
) -> Event_Person_Base|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 event_person_id := redis_lookup_id_random(record_id_random=event_person_id, table_name='event_person'): pass
|
if event_person_id := redis_lookup_id_random(record_id_random=event_person_id, table_name='event_person'): pass
|
||||||
@@ -55,9 +57,12 @@ def load_event_person_obj(
|
|||||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(event_person_rec)
|
log.debug(event_person_rec)
|
||||||
|
|
||||||
event_person_obj = Event_Person_Base(**event_person_rec)
|
person_id = event_person_rec.get('person_id', None)
|
||||||
person_id = event_person_obj.person_id
|
user_id = event_person_rec.get('user_id', None)
|
||||||
user_id = event_person_obj.user_id
|
|
||||||
|
# event_person_obj = Event_Person_Base(**event_person_rec)
|
||||||
|
# person_id = event_person_obj.person_id
|
||||||
|
# user_id = event_person_obj.user_id
|
||||||
|
|
||||||
if inc_event: pass
|
if inc_event: pass
|
||||||
if inc_event_badge: pass
|
if inc_event_badge: pass
|
||||||
@@ -65,22 +70,15 @@ def load_event_person_obj(
|
|||||||
if inc_event_registration: pass
|
if inc_event_registration: pass
|
||||||
|
|
||||||
if inc_person:
|
if inc_person:
|
||||||
if person_rec := sql_select(table_name='v_person', field_name='person_id', field_value=person_id):
|
person_obj = load_person_obj(person_id=person_id)
|
||||||
event_person_rec['person'] = person_rec
|
log.debug(person_obj)
|
||||||
event_person_obj.person = person_rec
|
event_person_rec['person'] = person_obj
|
||||||
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
||||||
log.debug(event_person_rec)
|
log.debug(event_person_rec)
|
||||||
|
|
||||||
if inc_user:
|
if inc_user:
|
||||||
user_obj = load_user_obj(user_id=user_id) # Not including roles, contact, or organization
|
user_obj = load_user_obj(user_id=user_id)
|
||||||
log.debug(user_obj)
|
log.debug(user_obj)
|
||||||
event_person_obj.user = user_obj
|
event_person_rec['user'] = user_obj
|
||||||
|
log.debug(event_person_rec)
|
||||||
#if user_rec := sql_select(table_name='v_user', field_name='user_id', field_value=user_id):
|
|
||||||
# event_person_rec['user'] = user_rec
|
|
||||||
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
||||||
#log.debug(event_person_rec)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@@ -31,3 +31,28 @@ def create_address_obj(address_obj_new:Address_Base):
|
|||||||
log.debug(f'Returning the new address_id: {address_id}')
|
log.debug(f'Returning the new address_id: {address_id}')
|
||||||
return address_id
|
return address_id
|
||||||
# ### END ### API Address Methods ### create_address_obj() ###
|
# ### END ### API Address Methods ### create_address_obj() ###
|
||||||
|
|
||||||
|
|
||||||
|
# ### BEGIN ### API Address Methods ### load_address_obj() ###
|
||||||
|
def load_address_obj(address_id:int|str) -> Address_Base|bool:
|
||||||
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
log.debug(locals())
|
||||||
|
|
||||||
|
if address_id := redis_lookup_id_random(record_id_random=address_id, table_name='address'): pass
|
||||||
|
else: return False
|
||||||
|
|
||||||
|
if address_rec := sql_select(table_name='v_address', record_id=address_id):
|
||||||
|
#log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
log.debug(address_rec)
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
try:
|
||||||
|
address_obj = Address_Base(**address_rec)
|
||||||
|
log.debug(address_obj)
|
||||||
|
except ValidationError as e:
|
||||||
|
log.error(e.json())
|
||||||
|
return False
|
||||||
|
|
||||||
|
return address_obj
|
||||||
|
# ### END ### API Address Methods ### load_address_obj() ###
|
||||||
|
|||||||
@@ -51,3 +51,34 @@ def create_contact_obj(contact_obj_new:Contact_Base):
|
|||||||
log.debug(f'Returning the new contact_id: {contact_id}')
|
log.debug(f'Returning the new contact_id: {contact_id}')
|
||||||
return contact_id
|
return contact_id
|
||||||
# ### END ### API Contact Methods ### create_contact_obj() ###
|
# ### END ### API Contact Methods ### create_contact_obj() ###
|
||||||
|
|
||||||
|
|
||||||
|
# ### BEGIN ### API Contact Methods ### load_contact_obj() ###
|
||||||
|
def load_contact_obj(contact_id:int|str, inc_address:bool=False) -> Contact_Base|bool:
|
||||||
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
log.debug(locals())
|
||||||
|
|
||||||
|
if contact_id := redis_lookup_id_random(record_id_random=contact_id, table_name='contact'): pass
|
||||||
|
else: return False
|
||||||
|
|
||||||
|
if contact_rec := sql_select(table_name='v_contact', record_id=contact_id):
|
||||||
|
#log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
log.debug(contact_rec)
|
||||||
|
|
||||||
|
if inc_address:
|
||||||
|
if address_rec := sql_select(table_name='v_address', field_name='address_id', field_value=contact_rec.get('address_id', None)):
|
||||||
|
contact_rec['address'] = address_rec
|
||||||
|
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
log.debug(address_rec)
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
try:
|
||||||
|
contact_obj = Contact_Base(**contact_rec)
|
||||||
|
log.debug(contact_obj)
|
||||||
|
except ValidationError as e:
|
||||||
|
log.error(e.json())
|
||||||
|
return False
|
||||||
|
|
||||||
|
return contact_obj
|
||||||
|
# ### END ### API Contact Methods ### load_contact_obj() ###
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ from .event_badge_models import Event_Badge_Base
|
|||||||
from .event_person_detail_models import Event_Person_Detail_Base
|
from .event_person_detail_models import Event_Person_Detail_Base
|
||||||
from .event_registration_models import Event_Registration_Base
|
from .event_registration_models import Event_Registration_Base
|
||||||
from .person_model import Person_Base
|
from .person_model import Person_Base
|
||||||
from .user_model import User_Base
|
from .user_model import User_Base, User_Out_Base
|
||||||
|
|
||||||
|
|
||||||
class Event_Person_New_Base(BaseModel):
|
class Event_Person_New_Base(BaseModel):
|
||||||
@@ -141,7 +141,7 @@ class Event_Person_Base(BaseModel):
|
|||||||
event_person_detail: Optional[Event_Person_Detail_Base] = Event_Person_Detail_Base()
|
event_person_detail: Optional[Event_Person_Detail_Base] = Event_Person_Detail_Base()
|
||||||
event_registration: Optional[Event_Registration_Base] = Event_Registration_Base()
|
event_registration: Optional[Event_Registration_Base] = Event_Registration_Base()
|
||||||
person: Optional[Person_Base] = Person_Base()
|
person: Optional[Person_Base] = Person_Base()
|
||||||
user: Optional[User_Base] = User_Base()
|
user: Optional[User_Out_Base] = User_Out_Base()
|
||||||
|
|
||||||
priority: Optional[bool]
|
priority: Optional[bool]
|
||||||
sort: Optional[int]
|
sort: Optional[int]
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from ..lib_general import *
|
|||||||
from ..db_sql import redis_lookup_id_random, sql_insert, sql_select, sql_update
|
from ..db_sql import redis_lookup_id_random, sql_insert, sql_select, sql_update
|
||||||
|
|
||||||
from .person_model import Person_Base
|
from .person_model import Person_Base
|
||||||
|
from ..models.address_methods import load_address_obj
|
||||||
from ..models.contact_methods import create_contact_obj
|
from ..models.contact_methods import create_contact_obj
|
||||||
|
|
||||||
|
|
||||||
@@ -56,7 +57,7 @@ def create_person_obj(person_obj_new:Person_Base):
|
|||||||
|
|
||||||
|
|
||||||
# ### BEGIN ### API Person Methods ### load_person_obj() ###
|
# ### BEGIN ### API Person Methods ### load_person_obj() ###
|
||||||
def load_person_obj(person_id:int|str, inc_contact:bool=False, inc_address:bool=False, inc_organization:bool=False) -> Person_Base:
|
def load_person_obj(person_id:int|str, inc_contact:bool=False, inc_address:bool=False, inc_organization:bool=False, inc_user:bool=False) -> Person_Base:
|
||||||
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())
|
||||||
|
|
||||||
@@ -74,10 +75,15 @@ def load_person_obj(person_id:int|str, inc_contact:bool=False, inc_address:bool=
|
|||||||
log.debug(contact_rec)
|
log.debug(contact_rec)
|
||||||
|
|
||||||
if inc_address:
|
if inc_address:
|
||||||
if address_rec := sql_select(table_name='v_address', field_name='address_id', field_value=contact_rec.get('address_id', None)):
|
address_id = contact_rec.get('address_id', None)
|
||||||
person_rec['contact']['address'] = address_rec
|
if address_obj_result := load_address_obj(address_id=address_id):
|
||||||
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
address_obj = address_obj_result
|
||||||
log.debug(address_rec)
|
person_rec['contact']['address'] = address_obj
|
||||||
|
log.debug(person_rec)
|
||||||
|
# if address_rec := sql_select(table_name='v_address', field_name='address_id', field_value=contact_rec.get('address_id', None)):
|
||||||
|
# person_rec['contact']['address'] = address_rec
|
||||||
|
# #log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
# log.debug(address_rec)
|
||||||
|
|
||||||
if inc_organization:
|
if inc_organization:
|
||||||
if organization_rec := sql_select(table_name='v_organization', field_name='organization_id', field_value=person_rec.get('organization_id', None)):
|
if organization_rec := sql_select(table_name='v_organization', field_name='organization_id', field_value=person_rec.get('organization_id', None)):
|
||||||
@@ -85,6 +91,12 @@ def load_person_obj(person_id:int|str, inc_contact:bool=False, inc_address:bool=
|
|||||||
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(organization_rec)
|
log.debug(organization_rec)
|
||||||
|
|
||||||
|
if inc_user:
|
||||||
|
if user_rec := sql_select(table_name='v_user', field_name='user_id', field_value=person_rec.get('user_id', None)):
|
||||||
|
person_rec['user'] = user_rec
|
||||||
|
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
|
log.debug(user_rec)
|
||||||
|
|
||||||
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(person_rec)
|
log.debug(person_rec)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from .common_field_schema import base_fields, default_num_bytes
|
|||||||
# from .account_model import Account_Base
|
# from .account_model import Account_Base
|
||||||
from .contact_model import Contact_Base
|
from .contact_model import Contact_Base
|
||||||
from .organization_model import Organization_Base
|
from .organization_model import Organization_Base
|
||||||
# from .user_model import User_Base
|
from .user_model import User_Base
|
||||||
|
|
||||||
|
|
||||||
class Person_Base(BaseModel):
|
class Person_Base(BaseModel):
|
||||||
@@ -63,9 +63,9 @@ class Person_Base(BaseModel):
|
|||||||
created_on: Optional[datetime.datetime] = None
|
created_on: Optional[datetime.datetime] = None
|
||||||
updated_on: Optional[datetime.datetime] = None
|
updated_on: Optional[datetime.datetime] = None
|
||||||
|
|
||||||
contact: Optional[Contact_Base] = Contact_Base()
|
contact: Contact_Base = Contact_Base()
|
||||||
organization: Optional[Organization_Base] = Organization_Base()
|
organization: Organization_Base = Organization_Base()
|
||||||
#user: Optional[User_Base] = User_Base()
|
user: User_Base = User_Base()
|
||||||
|
|
||||||
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
||||||
|
|
||||||
|
|||||||
@@ -25,13 +25,13 @@ router = APIRouter()
|
|||||||
|
|
||||||
@router.post('/new', response_model=Resp_Body_Base)
|
@router.post('/new', response_model=Resp_Body_Base)
|
||||||
async def post_event_person_new(
|
async def post_event_person_new(
|
||||||
event_person_new: Event_Person_New_Base,
|
event_person_new_init: Event_Person_New_Base,
|
||||||
x_account_id: str = Header(...),
|
x_account_id: str = Header(...),
|
||||||
return_obj: bool = True,
|
return_obj: bool = True,
|
||||||
inc_event: bool = False,
|
inc_event: bool = False, # Not ready yet. Placeholder.
|
||||||
inc_event_badge: bool = False,
|
inc_event_badge: bool = False, # Not ready yet. Placeholder.
|
||||||
inc_event_person_detail: bool = False,
|
inc_event_person_detail: bool = False, # Not ready yet. Placeholder.
|
||||||
inc_event_registration: bool = False,
|
inc_event_registration: bool = False, # Not ready yet. Placeholder.
|
||||||
inc_person: bool = False,
|
inc_person: bool = False,
|
||||||
inc_user: bool = False,
|
inc_user: bool = False,
|
||||||
by_alias: bool = True,
|
by_alias: bool = True,
|
||||||
@@ -40,25 +40,25 @@ async def post_event_person_new(
|
|||||||
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())
|
||||||
|
|
||||||
account_id_random = event_person_new.account_id_random
|
account_id_random = event_person_new_init.account_id_random
|
||||||
event_id_random = event_person_new.event_id_random
|
event_id_random = event_person_new_init.event_id_random
|
||||||
|
|
||||||
given_name = event_person_new.person_given_name
|
given_name = event_person_new_init.person_given_name
|
||||||
family_name = event_person_new.person_family_name
|
family_name = event_person_new_init.person_family_name
|
||||||
if full_name := event_person_new.person_full_name:
|
if full_name := event_person_new_init.person_full_name:
|
||||||
pass
|
pass
|
||||||
elif given_name and family_name:
|
elif given_name and family_name:
|
||||||
full_name = f'{given_name} {family_name}'
|
full_name = f'{given_name} {family_name}'
|
||||||
elif given_name:
|
elif given_name:
|
||||||
full_name = f'{given_name}'
|
full_name = f'{given_name}'
|
||||||
email = event_person_new.email
|
email = event_person_new_init.email
|
||||||
|
|
||||||
if new_password := event_person_new.new_password:
|
if new_password := event_person_new_init.new_password:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
new_password = secrets.token_urlsafe(default_num_bytes)
|
new_password = secrets.token_urlsafe(default_num_bytes)
|
||||||
|
|
||||||
organization_name = event_person_new.organization_name
|
organization_name = event_person_new_init.organization_name
|
||||||
|
|
||||||
# New person
|
# New person
|
||||||
person_new = {}
|
person_new = {}
|
||||||
@@ -67,14 +67,12 @@ async def post_event_person_new(
|
|||||||
person_new['family_name'] = family_name
|
person_new['family_name'] = family_name
|
||||||
person_new['full_name'] = full_name
|
person_new['full_name'] = full_name
|
||||||
person_new['organization_name'] = organization_name
|
person_new['organization_name'] = organization_name
|
||||||
#person_new['contact_id_random'] = ?
|
|
||||||
|
|
||||||
# New person contact
|
# New person contact
|
||||||
person_new['contact'] = {}
|
person_new['contact'] = {}
|
||||||
person_new['contact']['account_id_random'] = account_id_random
|
person_new['contact']['account_id_random'] = account_id_random
|
||||||
person_new['contact']['email'] = email
|
person_new['contact']['email'] = email
|
||||||
person_new['contact']['name'] = full_name
|
person_new['contact']['name'] = full_name
|
||||||
person_new['contact']['address'] = {}
|
|
||||||
|
|
||||||
# New person contact address
|
# New person contact address
|
||||||
person_new['contact']['address'] = {}
|
person_new['contact']['address'] = {}
|
||||||
@@ -140,24 +138,23 @@ async def post_event_person_new(
|
|||||||
event_person_id = event_person_obj_result
|
event_person_id = event_person_obj_result
|
||||||
event_person_obj = load_event_person_obj(
|
event_person_obj = load_event_person_obj(
|
||||||
event_person_id=event_person_id,
|
event_person_id=event_person_id,
|
||||||
inc_event=inc_event,
|
inc_event=inc_event, # Not ready yet. Placeholder.
|
||||||
inc_event_badge=inc_event_badge,
|
inc_event_badge=inc_event_badge, # Not ready yet. Placeholder.
|
||||||
inc_event_person_detail=inc_event_person_detail,
|
inc_event_person_detail=inc_event_person_detail, # Not ready yet. Placeholder.
|
||||||
inc_event_registration=inc_event_registration,
|
inc_event_registration=inc_event_registration, # Not ready yet. Placeholder.
|
||||||
inc_person=inc_person,
|
inc_person=False, # Already loaded above
|
||||||
inc_user=inc_user
|
inc_user=False # Already loaded above
|
||||||
)
|
)
|
||||||
log.debug(event_person_id)
|
log.debug(event_person_id)
|
||||||
log.debug(event_person_obj)
|
log.debug(event_person_obj)
|
||||||
|
|
||||||
|
event_person_obj.person = person_obj
|
||||||
|
event_person_obj.user = user_obj
|
||||||
|
|
||||||
|
log.debug(event_person_obj)
|
||||||
else:
|
else:
|
||||||
log.debug('A new event_person was not created')
|
log.debug('A new event_person was not created')
|
||||||
return mk_resp(data=False)
|
return mk_resp(data=False)
|
||||||
|
|
||||||
return_data = {}
|
log.debug(event_person_obj)
|
||||||
return_data['person'] = person_obj
|
return mk_resp(data=event_person_obj)
|
||||||
return_data['user'] = user_obj
|
|
||||||
return_data['event_person'] = event_person_obj
|
|
||||||
|
|
||||||
log.debug(return_data)
|
|
||||||
|
|
||||||
return mk_resp(data=return_data)
|
|
||||||
Reference in New Issue
Block a user