diff --git a/app/db_sql.py b/app/db_sql.py index bf9e7e9..9749be7 100644 --- a/app/db_sql.py +++ b/app/db_sql.py @@ -455,9 +455,9 @@ def sql_select( pass #log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL - log.debug(result.rowcount) - log.debug(vars(result)) - log.debug(dir(result)) + log.info(f'Row count: {result.rowcount}') + #log.debug(vars(result)) + #log.debug(dir(result)) if result.rowcount == 1: log.info(f'Found one record. as_dict={as_dict}, as_list={as_list}') if as_dict: diff --git a/app/methods/event_location_methods.py b/app/methods/event_location_methods.py index 3d6abab..91f31e1 100644 --- a/app/methods/event_location_methods.py +++ b/app/methods/event_location_methods.py @@ -22,13 +22,14 @@ from app.models.event_location_models import Event_Location_Base # ### BEGIN ### API Event Location Methods ### load_event_location_obj() ### def load_event_location_obj( - event_location_id: int|str, - enabled: str = 'enabled', # enabled, disabled, all - inc_event_device_list: bool = False, - inc_event_file_list: bool = False, - inc_event_presentation_list: bool = False, - inc_event_presenter_list: bool = False, - ) -> Event_Location_Base|bool: + event_location_id: int|str, + enabled: str = 'enabled', # enabled, disabled, all + limit: int = 1000, + inc_event_device_list: bool = False, + inc_event_file_list: bool = False, + inc_event_presentation_list: bool = False, + inc_event_presenter_list: bool = False, + ) -> Event_Location_Base|bool: log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.debug(locals()) diff --git a/app/methods/event_methods.py b/app/methods/event_methods.py index 4486279..fa1dd6a 100644 --- a/app/methods/event_methods.py +++ b/app/methods/event_methods.py @@ -16,32 +16,32 @@ from app.models.event_models import Event_Base, Event_Cfg_Base # ### BEGIN ### API Event Methods ### load_event_obj() ### def load_event_obj( - event_id: int|str, - enabled: str = 'enabled', # enabled, disabled, all - limit: int = 1000, - inc_contact_1: bool = False, - inc_contact_2: bool = False, - inc_contact_3: bool = False, - inc_event_abstract_list: bool = False, - inc_event_badge_list: bool = False, - inc_event_cfg: bool = False, - inc_event_device_list: bool = False, - inc_event_exhibit_list: 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_list: bool = False, - inc_event_presentation_list: bool = False, - inc_event_presenter_cat: bool = False, # For event_session child object - inc_event_presenter_list: bool = False, - inc_event_registration_cfg: bool = False, - inc_event_registration_list: 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_location_address: bool = False, - inc_poc_event_person: bool = False, - ) -> Event_Base|bool: + event_id: int|str, + enabled: str = 'enabled', # enabled, disabled, all + limit: int = 1000, + inc_contact_1: bool = False, + inc_contact_2: bool = False, + inc_contact_3: bool = False, + inc_event_abstract_list: bool = False, + inc_event_badge_list: bool = False, + inc_event_cfg: bool = False, + inc_event_device_list: bool = False, + inc_event_exhibit_list: 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_list: bool = False, + inc_event_presentation_list: bool = False, + inc_event_presenter_cat: bool = False, # For event_session child object + inc_event_presenter_list: bool = False, + inc_event_registration_cfg: bool = False, + inc_event_registration_list: 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_location_address: bool = False, + inc_poc_event_person: bool = False, + ) -> Event_Base|bool: #log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.debug(locals()) diff --git a/app/methods/event_person_methods.py b/app/methods/event_person_methods.py index e28adb6..e76a108 100644 --- a/app/methods/event_person_methods.py +++ b/app/methods/event_person_methods.py @@ -49,20 +49,22 @@ def create_event_person_obj(event_person_obj_new:Event_Person_Base) -> int|bool: # ### BEGIN ### API Event Person Methods ### load_event_person_obj() ### def load_event_person_obj( - event_person_id: int|str, - inc_event_abstract_list: bool = False, - inc_event_badge: bool = False, - inc_event_exhibit_list: bool = False, - inc_event_file_list: bool = False, - #inc_event_person_detail: bool = False, # Should this be done differently? - inc_event_presentation_list: bool = False, - inc_event_presenter_list: bool = False, - inc_event_registration: bool = False, - inc_event_session_list: bool = False, - inc_event_track_list: bool = False, - inc_person: bool = False, - inc_user: bool = False, - ) -> Event_Person_Base|bool: + event_person_id: int|str, + enabled: str = 'enabled', # enabled, disabled, all + limit: int = 1000, + inc_event_abstract_list: bool = False, + inc_event_badge: bool = False, + inc_event_exhibit_list: bool = False, + inc_event_file_list: bool = False, + #inc_event_person_detail: bool = False, # Should this be done differently? + inc_event_presentation_list: bool = False, + inc_event_presenter_list: bool = False, + inc_event_registration: bool = False, + inc_event_session_list: bool = False, + inc_event_track_list: bool = False, + inc_person: bool = False, + inc_user: bool = False, + ) -> Event_Person_Base|bool: log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.debug(locals()) @@ -102,16 +104,23 @@ def load_event_person_obj( if inc_event_track_list: pass if inc_person: - person_obj = load_person_obj(person_id=person_id) - log.debug(person_obj) - event_person_rec['person'] = person_obj - log.debug(event_person_rec) + log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL + if person_obj := load_person_obj(person_id=person_id): + log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL + log.debug(person_obj) + event_person_obj.person = person_obj.dict(by_alias=True, exclude_unset=True) + else: + log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL + log.debug('A person object was not returned.') + event_person_obj.person = None if inc_user: - user_obj = load_user_obj(user_id=user_id) - log.debug(user_obj) - event_person_rec['user'] = user_obj - log.debug(event_person_rec) + log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL + if user_obj := load_user_obj(user_id=user_id): + log.debug(user_obj) + event_person_obj.user = user_obj.dict(by_alias=True, exclude_unset=True) + else: + event_person_obj.user = None return event_person_obj # ### END ### API Event Person Methods ### load_event_person_obj() ### \ No newline at end of file diff --git a/app/methods/event_presentation_methods.py b/app/methods/event_presentation_methods.py index 9b3c26f..7f7e0fd 100644 --- a/app/methods/event_presentation_methods.py +++ b/app/methods/event_presentation_methods.py @@ -20,19 +20,20 @@ from app.models.event_presentation_models import Event_Presentation_Base # ### BEGIN ### API Event Presentation Methods ### load_event_presentation_obj() ### def load_event_presentation_obj( - event_presentation_id: int|str, - enabled: str = 'enabled', # enabled, disabled, all - inc_event_abstract_list: bool = False, - #inc_event_badge_list: bool = False, - inc_event_device_list: bool = False, - inc_event_file_list: bool = False, - inc_event_person_list: bool = False, - inc_event_presenter_list: bool = False, - #inc_event_cfg: bool = False, - #inc_poc_event_person: bool = False, - #inc_poc_person: bool = False, - #inc_user: bool = False, - ) -> Event_Presentation_Base|bool: + event_presentation_id: int|str, + enabled: str = 'enabled', # enabled, disabled, all + limit: int = 1000, + inc_event_abstract_list: bool = False, + #inc_event_badge_list: bool = False, + inc_event_device_list: bool = False, + inc_event_file_list: bool = False, + inc_event_person_list: bool = False, + inc_event_presenter_list: bool = False, + #inc_event_cfg: bool = False, + #inc_poc_event_person: bool = False, + #inc_poc_person: bool = False, + #inc_user: bool = False, + ) -> Event_Presentation_Base|bool: log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.debug(locals()) diff --git a/app/methods/event_presenter_methods.py b/app/methods/event_presenter_methods.py index f0df05f..4072d52 100644 --- a/app/methods/event_presenter_methods.py +++ b/app/methods/event_presenter_methods.py @@ -17,16 +17,17 @@ from app.models.event_presenter_models import Event_Presenter_Base # ### BEGIN ### API Event Presenter Methods ### load_event_presenter_obj() ### def load_event_presenter_obj( - event_presenter_id: int|str, - enabled: str = 'enabled', # enabled, disabled, all - inc_event_abstract_list: bool = False, - inc_event_badge: bool = False, - inc_event_device_list: bool = False, - inc_event_file_list: bool = False, - inc_event_person: bool = False, - inc_person: bool = False, - inc_user: bool = False, - ) -> Event_Presenter_Base|bool: + event_presenter_id: int|str, + enabled: str = 'enabled', # enabled, disabled, all + limit: int = 1000, + inc_event_abstract_list: bool = False, + inc_event_badge: bool = False, + inc_event_device_list: bool = False, + inc_event_file_list: bool = False, + inc_event_person: bool = False, + inc_person: bool = False, + inc_user: bool = False, + ) -> Event_Presenter_Base|bool: log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.debug(locals()) diff --git a/app/methods/event_session_methods.py b/app/methods/event_session_methods.py index 1266046..39b4953 100644 --- a/app/methods/event_session_methods.py +++ b/app/methods/event_session_methods.py @@ -20,23 +20,24 @@ from app.models.event_session_models import Event_Session_Base # ### BEGIN ### API Event Session Methods ### load_event_session_obj() ### def load_event_session_obj( - event_session_id: int|str, - enabled: str = 'enabled', # enabled, disabled, all - inc_event_abstract_list: bool = False, - inc_event_badge_list: bool = False, - inc_event_device_list: bool = False, - inc_event_file_list: bool = False, - inc_event_location: bool = False, - inc_event_person_list: bool = False, - inc_event_presentation_list: bool = False, - inc_event_presenter_cat: bool = False, # Concantinate presenter names - inc_event_presenter_list: bool = False, - inc_event_registration_list: bool = False, - inc_event_track: bool = False, - inc_poc_event_person: bool = False, - inc_poc_person: bool = False, - # inc_user: bool = False, - ) -> Event_Session_Base|bool: + event_session_id: int|str, + enabled: str = 'enabled', # enabled, disabled, all + limit: int = 1000, + inc_event_abstract_list: bool = False, + inc_event_badge_list: bool = False, + inc_event_device_list: bool = False, + inc_event_file_list: bool = False, + inc_event_location: bool = False, + inc_event_person_list: bool = False, + inc_event_presentation_list: bool = False, + inc_event_presenter_cat: bool = False, # Concantinate presenter names + inc_event_presenter_list: bool = False, + inc_event_registration_list: bool = False, + inc_event_track: bool = False, + inc_poc_event_person: bool = False, + inc_poc_person: bool = False, + # inc_user: bool = False, + ) -> Event_Session_Base|bool: log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.debug(locals()) diff --git a/app/methods/person_methods.py b/app/methods/person_methods.py index d7c0b1a..83d7b50 100644 --- a/app/methods/person_methods.py +++ b/app/methods/person_methods.py @@ -60,60 +60,68 @@ def create_person_obj(person_obj_new:Person_Base): # ### 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, inc_user:bool=False) -> Person_Base|bool: - log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL +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|bool: + log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.debug(locals()) if person_id := redis_lookup_id_random(record_id_random=person_id, table_name='person'): pass else: return False - if person_rec := sql_select(table_name='v_person', record_id=person_id): - #log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL - log.debug(person_rec) + if person_rec := sql_select(table_name='v_person', record_id=person_id): pass + else: return False - if inc_contact: - contact_id = person_rec.get('contact_id', None) - if contact_obj_result := load_contact_obj(contact_id=contact_id): - contact_obj = contact_obj_result - person_rec['contact'] = contact_obj - log.debug(person_rec) - #else: person_rec['contact'] = None - - if inc_address: - address_id = contact_obj.address_id - if address_obj_result := load_address_obj(address_id=address_id): - address_obj = address_obj_result - person_rec['contact'].address = address_obj - log.debug(person_rec) - #else: person_rec['contact'].address = None - - if inc_organization: - organization_id = person_rec.get('organization_id', None) - if organization_obj_result := load_organization_obj(organization_id=organization_id): - organization_obj = organization_obj_result - person_rec['organization'] = organization_obj - log.debug(person_rec) - #else: person_rec['organization'] = None - - if inc_user: - user_id = person_rec.get('user_id', None) - if user_obj_result := load_user_obj(user_id=user_id): - user_obj = user_obj_result - person_rec['user'] = user_obj - log.debug(person_rec) - #else: person_rec['user'] = None - - #log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL - log.debug(person_rec) - else: - return False + #log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL + log.debug(person_rec) try: person_obj = Person_Base(**person_rec) log.debug(person_obj) except ValidationError as e: log.error(e.json()) - return False + + if inc_contact: + contact_id = person_rec.get('contact_id', None) + if contact_obj_result := load_contact_obj(contact_id=contact_id): + contact_obj = contact_obj_result + #person_obj.contact = contact_obj.dict(by_alias=True, exclude_unset=True) + person_obj.contact = contact_obj + else: person_obj.contact = None + + if inc_address: + address_id = contact_obj.address_id + if address_obj_result := load_address_obj(address_id=address_id): + address_obj = address_obj_result + # person_rec['contact'].address = address_obj + # log.debug(person_rec) + #person_obj.contact.address = address_obj.dict(by_alias=True, exclude_unset=True) + person_obj.contact.address = address_obj + else: person_obj.contact.address = None + + if inc_organization: + organization_id = person_rec.get('organization_id', None) + if organization_obj_result := load_organization_obj(organization_id=organization_id): + organization_obj = organization_obj_result + # person_rec['organization'] = organization_obj + # log.debug(person_rec) + #person_obj.organization = organization_obj.dict(by_alias=True, exclude_unset=True) + person_obj.organization = organization_obj + else: person_obj.organization = None + + if inc_user: + user_id = person_rec.get('user_id', None) + if user_obj_result := load_user_obj(user_id=user_id): + user_obj = user_obj_result + # person_rec['user'] = user_obj + # log.debug(person_rec) + #person_obj.user = user_obj.dict(by_alias=True, exclude_unset=True) + person_obj.user = user_obj + else: person_obj.user = None return person_obj # ### END ### API Person Methods ### load_person_obj() ### diff --git a/app/methods/user_methods.py b/app/methods/user_methods.py index c25e55f..eb45d67 100644 --- a/app/methods/user_methods.py +++ b/app/methods/user_methods.py @@ -71,50 +71,17 @@ def create_user_obj(user_obj_new:User_New_Base) -> int|bool: # ### BEGIN ### API User Methods ### load_user_obj() ### def load_user_obj(user_id:int|str, inc_roles:bool=False, inc_contact:bool=False, inc_organization:bool=False, inc_person:bool=False) -> User_Out_Base|bool: - log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL + #log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.debug(locals()) if user_id := redis_lookup_id_random(record_id_random=user_id, table_name='user'): pass else: return False - if user_rec := sql_select(table_name='v_user', record_id=user_id): - #log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL - log.debug(user_rec) + if user_rec := sql_select(table_name='v_user', record_id=user_id): pass + else: return false - if inc_roles: - if role_rec_li := sql_select(table_name='v_user_role_detail', field_name='user_id', field_value=user_id, as_list=True): - user_rec['role_list'] = role_rec_li - #log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL - log.debug(role_rec_li) - - if inc_contact: - contact_id = user_rec.get('contact_id', None) - if contact_obj_result := load_contact_obj(contact_id=contact_id): - contact_obj = contact_obj_result - user_rec['contact'] = contact_obj - log.debug(user_rec) - #else: user_rec['contact'] = None - - if inc_organization: - organization_id = user_rec.get('organization_id', None) - if organization_obj_result := load_organization_obj(organization_id=organization_id): - organization_obj = organization_obj_result - user_rec['organization'] = organization_obj - log.debug(user_rec) - #else: user_rec['organization'] = None - - # if inc_person: - # person_id = user_rec.get('person_id', None) - # if person_obj_result := load_person_obj(person_id=person_id): - # person_obj = person_obj_result - # user_rec['person'] = person_obj - # log.debug(user_rec) - # #else: user_rec['person'] = None - - #log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL - log.debug(user_rec) - else: - return False + #log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL + log.debug(user_rec) try: user_obj = User_Out_Base(**user_rec) @@ -123,5 +90,48 @@ def load_user_obj(user_id:int|str, inc_roles:bool=False, inc_contact:bool=False, log.error(e.json()) return False + if inc_roles: + if role_rec_li := sql_select(table_name='v_user_role_detail', field_name='user_id', field_value=user_id, as_list=True): + user_rec['role_list'] = role_rec_li + #log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL + log.debug(role_rec_li) + user_obj.role_list = role_rec_li + else: + user_rec['role_list'] = None + user_obj.role_list = None + + if inc_contact: + contact_id = user_rec.get('contact_id', None) + if contact_obj_result := load_contact_obj(contact_id=contact_id): + contact_obj = contact_obj_result + user_rec['contact'] = contact_obj + log.debug(user_rec) + user_obj.contact = contact_obj + else: + user_rec['contact'] = None + user_obj.contact = None + + if inc_organization: + organization_id = user_rec.get('organization_id', None) + if organization_obj_result := load_organization_obj(organization_id=organization_id): + organization_obj = organization_obj_result + user_rec['organization'] = organization_obj + log.debug(user_rec) + user_obj.organization = organization_obj + else: + user_rec['organization'] = None + user_obj.organization = None + + # if inc_person: + # person_id = user_rec.get('person_id', None) + # if person_obj_result := load_person_obj(person_id=person_id): + # person_obj = person_obj_result + # user_rec['person'] = person_obj + # log.debug(user_rec) + # #else: user_rec['person'] = None + + #log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL + log.debug(user_rec) + return user_obj # ### END ### API User Methods ### load_user_obj() ### diff --git a/app/models/address_models.py b/app/models/address_models.py index 5db54e8..91db31f 100644 --- a/app/models/address_models.py +++ b/app/models/address_models.py @@ -63,8 +63,6 @@ class Address_Base(BaseModel): created_on: Optional[datetime.datetime] = None updated_on: Optional[datetime.datetime] = None - #account: Optional[Account_Base] = Account_Base() - _processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now) #@validator('address_id_random', always=True) diff --git a/app/models/person_models.py b/app/models/person_models.py index 454442f..78d89ce 100644 --- a/app/models/person_models.py +++ b/app/models/person_models.py @@ -64,9 +64,9 @@ class Person_Base(BaseModel): updated_on: Optional[datetime.datetime] = None # Including other related objects - contact: Optional[Contact_Base] - organization: Optional[Organization_Base] - user: Optional[User_Base] + contact: Optional[Union[Contact_Base, None]] + organization: Optional[Union[Organization_Base, None]] + user: Optional[Union[User_Base, None]] _processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now) diff --git a/app/models/user_models.py b/app/models/user_models.py index dc4d3e2..c456fd2 100644 --- a/app/models/user_models.py +++ b/app/models/user_models.py @@ -183,10 +183,10 @@ class User_Out_Base(BaseModel): # Including other related objects #account: Optional[Account_Base] - contact: Optional[Contact_Base] - organization: Optional[Organization_Base] - #person: Optional[Person_Base]# Causes circular import - role_list: Optional[list] = [] + contact: Optional[Union[Contact_Base, None]] + organization: Optional[Union[Organization_Base, None]] + #person: Optional[Union[Person_Base, None]]# Causes circular import + role_list: Optional[Union[list, None]] = [] _processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now) diff --git a/app/routers/event_person.py b/app/routers/event_person.py index 7eeff6c..39b641c 100644 --- a/app/routers/event_person.py +++ b/app/routers/event_person.py @@ -86,7 +86,12 @@ async def post_event_person_new( create_person_obj_result = create_person_obj(person_obj_new=person_obj_new) if isinstance(create_person_obj_result, int): person_id = create_person_obj_result - person_obj = load_person_obj(person_id=person_id, inc_contact=True, inc_address=True, inc_organization=True) + person_obj = load_person_obj( + person_id=person_id, + inc_contact=True, + inc_address=True, + inc_organization=True + ) log.debug(person_obj) else: log.debug('A new person was not created') @@ -207,7 +212,6 @@ async def get_event_person_obj( #inc_event_presenter_list=inc_event_presenter_list, inc_event_registration=inc_event_registration, #inc_event_track=inc_event_track, - inc_poc_event_person=inc_poc_event_person, inc_person=inc_person, inc_user=inc_user, ):