A lot of changes related to person and membership and event
This commit is contained in:
@@ -215,8 +215,9 @@ def load_account_obj(
|
||||
# Updated 2021-06-17
|
||||
if inc_event_list:
|
||||
if event_rec_list_result := get_event_rec_list(
|
||||
for_obj_type = 'account',
|
||||
for_obj_id = account_id,
|
||||
# for_obj_type = 'account',
|
||||
# for_obj_id = account_id,
|
||||
account_id = account_id,
|
||||
limit = limit,
|
||||
enabled = enabled,
|
||||
):
|
||||
|
||||
@@ -249,38 +249,47 @@ def load_event_obj(
|
||||
|
||||
# ### BEGIN ### API Event Methods ### get_event_rec_list() ###
|
||||
def get_event_rec_list(
|
||||
for_obj_type: str,
|
||||
for_obj_id: str,
|
||||
account_id: str = None,
|
||||
organization_id: str = None,
|
||||
person_id: str = None,
|
||||
user_id: str = None,
|
||||
limit: int = 1000,
|
||||
enabled: str = 'enabled', # enabled, disabled, all
|
||||
conference: bool = False,
|
||||
conference: bool = False, # If it is a conference then organization, person, and user are queried as participants (not the owner/organizer)
|
||||
) -> list|bool:
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if for_obj_id := redis_lookup_id_random(record_id_random=for_obj_id, table_name=for_obj_type): pass
|
||||
if account_id or organization_id or person_id or user_id: pass
|
||||
else: return False
|
||||
data = {}
|
||||
data[f'{for_obj_type}_id'] = for_obj_id
|
||||
# data['for_obj_type'] = for_obj_type
|
||||
sql_obj_type_id = f'`tbl`.{for_obj_type}_id = :{for_obj_type}_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 = ''
|
||||
if account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'): pass
|
||||
else: pass
|
||||
|
||||
if organization_id := redis_lookup_id_random(record_id_random=organization_id, table_name='organization'): pass
|
||||
else: pass
|
||||
|
||||
if person_id := redis_lookup_id_random(record_id_random=person_id, table_name='person'): pass
|
||||
else: pass
|
||||
|
||||
if user_id := redis_lookup_id_random(record_id_random=user_id, table_name='user'): pass
|
||||
else: pass
|
||||
|
||||
data = {}
|
||||
data['account_id'] = account_id
|
||||
data['organization_id'] = organization_id
|
||||
data['person_id'] = person_id
|
||||
data['user_id'] = user_id
|
||||
data['conference'] = conference
|
||||
|
||||
if conference:
|
||||
data['conference'] = True
|
||||
sql_conference = f'AND `tbl`.conference = :conference'
|
||||
sql_conference = f'AND `event`.conference = :conference'
|
||||
else:
|
||||
data['conference'] = False
|
||||
sql_conference = f'AND `tbl`.conference = :conference'
|
||||
sql_conference = f'AND `event`.conference = :conference'
|
||||
|
||||
|
||||
|
||||
if limit:
|
||||
data['limit'] = limit
|
||||
@@ -288,16 +297,70 @@ def get_event_rec_list(
|
||||
else:
|
||||
sql_limit = ''
|
||||
|
||||
sql = f"""
|
||||
SELECT `tbl`.id AS 'event_id', `tbl`.id_random AS 'event_id_random'
|
||||
FROM `event` AS `tbl`
|
||||
WHERE
|
||||
{sql_obj_type_id}
|
||||
{sql_enabled}
|
||||
{sql_conference}
|
||||
ORDER BY `tbl`.created_on DESC, `tbl`.updated_on DESC
|
||||
{sql_limit};
|
||||
"""
|
||||
if account_id or not conference and (organization_id or person_id or user_id):
|
||||
if account_id:
|
||||
sql_where_type_id = f'`event`.account_id = :account_id'
|
||||
elif organization_id:
|
||||
sql_where_type_id = f'`event`.organization_id = :organization_id'
|
||||
elif person_id:
|
||||
sql_where_type_id = f'`event`.person_id = :person_id'
|
||||
elif user_id:
|
||||
sql_where_type_id = f'`event`.user_id = :user_id'
|
||||
|
||||
if enabled in ['enabled', 'disabled', 'all']:
|
||||
if enabled == 'enabled':
|
||||
data['enable'] = True
|
||||
sql_enabled = f'AND `event`.enable = :enable'
|
||||
elif enabled == 'disabled':
|
||||
data['enable'] = False
|
||||
sql_enabled = f'AND `event`.enable = :enable'
|
||||
elif enabled == 'all':
|
||||
sql_enabled = ''
|
||||
else:
|
||||
sql_enabled = f'AND `event`.enable = :enable'
|
||||
|
||||
sql = f"""
|
||||
SELECT `event`.id AS 'event_id', `event`.id_random AS 'event_id_random'
|
||||
FROM `event` AS `event`
|
||||
WHERE
|
||||
{sql_where_type_id}
|
||||
{sql_enabled}
|
||||
{sql_conference}
|
||||
ORDER BY `event`.created_on DESC, `event`.updated_on DESC
|
||||
{sql_limit};
|
||||
"""
|
||||
elif conference and (organization_id or person_id or user_id): # If it is a conference then organization, person, and user are queried as participants (not the owner/organizer)
|
||||
if organization_id: # Not sure if this makes sense?
|
||||
sql_inner_join = f'`organization` ON event_person.organization_id = organization.id AND organization.id AND organization.id = :organization_id'
|
||||
elif person_id:
|
||||
sql_inner_join = f'`person` ON event_person.person_id = person.id AND person.id AND person.id = :person_id'
|
||||
elif user_id:
|
||||
sql_inner_join = f'`user` ON event_person.user_id = user.id AND user.id AND user.id = :user_id'
|
||||
|
||||
if enabled in ['enabled', 'disabled', 'all']:
|
||||
if enabled == 'enabled':
|
||||
data['enable'] = True
|
||||
sql_enabled = f'`event`.enable = :enable'
|
||||
elif enabled == 'disabled':
|
||||
data['enable'] = False
|
||||
sql_enabled = f'`event`.enable = :enable'
|
||||
elif enabled == 'all':
|
||||
sql_enabled = ''
|
||||
else:
|
||||
sql_enabled = f'`event`.enable = :enable'
|
||||
|
||||
sql = f"""
|
||||
SELECT `event`.id AS 'event_id', `event`.id_random AS 'event_id_random'
|
||||
FROM `event` AS `event`
|
||||
INNER JOIN `event_person` ON event.id = event_person.event_id
|
||||
/*INNER JOIN `person` ON event_person.person_id = person.id*/
|
||||
INNER JOIN {sql_inner_join}
|
||||
WHERE
|
||||
{sql_enabled}
|
||||
{sql_conference}
|
||||
ORDER BY `event`.created_on DESC, `event`.updated_on DESC
|
||||
{sql_limit};
|
||||
"""
|
||||
|
||||
if event_rec_li_result := sql_select(data=data, sql=sql, as_list=True):
|
||||
event_rec_li = event_rec_li_result
|
||||
|
||||
@@ -138,7 +138,7 @@ class Event_Base(BaseModel):
|
||||
event_presenter_list: Optional[list] # Optional[Event_Presenter_Base]
|
||||
event_session_list: Optional[list] # Optional[Event_Session_Base]
|
||||
event_track_list: Optional[list] # Optional[Event_Track_Base]
|
||||
poc_event_person: Optional[Event_Person_Base]
|
||||
# poc_event_person: Optional[Event_Person_Base]
|
||||
poc_person: Optional[Person_Base]
|
||||
user: Optional[User_Base]
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ from app.db_sql import redis_lookup_id_random
|
||||
from app.lib_general import log, logging
|
||||
|
||||
from app.models.common_field_schema import base_fields, default_num_bytes
|
||||
# from app.models.event_models import Event_Base
|
||||
# from app.models.event_models import Event_Base # Causes an import loop
|
||||
from app.models.event_badge_models import Event_Badge_Base
|
||||
# from app.models.event_person_detail_models import Event_Person_Detail_Base
|
||||
from app.models.event_registration_models import Event_Registration_Base
|
||||
@@ -26,18 +26,23 @@ class Event_Person_Base(BaseModel):
|
||||
default_factory = lambda:secrets.token_urlsafe(default_num_bytes),
|
||||
)
|
||||
id: Optional[int] = Field(
|
||||
#alias = 'event_person_id'
|
||||
alias = 'event_person_id'
|
||||
)
|
||||
account_id_random: Optional[str]
|
||||
account_id: Optional[int]
|
||||
|
||||
event_id_random: Optional[str]
|
||||
event_id: Optional[int]
|
||||
|
||||
event_badge_id_random: Optional[str]
|
||||
event_badge_id: Optional[int]
|
||||
|
||||
event_registration_id_random: Optional[str]
|
||||
event_registration_id: Optional[int]
|
||||
|
||||
person_id_random: Optional[str]
|
||||
person_id: Optional[int]
|
||||
|
||||
user_id_random: Optional[str]
|
||||
user_id: Optional[int]
|
||||
|
||||
@@ -50,6 +55,7 @@ class Event_Person_Base(BaseModel):
|
||||
updated_on: Optional[datetime.datetime] = None
|
||||
|
||||
# Including other related objects
|
||||
# event: Optional[Event_Base] # Causes an import loop
|
||||
event_abstract_list: Optional[list] # Use event_person_detail table. An event_person record can be linked to one or more abstracts
|
||||
event_badge: Optional[Event_Badge_Base]
|
||||
event_exhibit_list: Optional[list] # Use event_person_detail table. An event_person record can be linked to one or more exhibits
|
||||
|
||||
@@ -35,10 +35,10 @@ class Membership_Person_Base(BaseModel):
|
||||
account_id_random: Optional[str]
|
||||
account_id: Optional[int]
|
||||
|
||||
membership_person_status_id: Optional[int] = Field(
|
||||
lu_membership_person_status_id: Optional[int] = Field(
|
||||
alias = 'status_id'
|
||||
)
|
||||
membership_person_status_name: Optional[str] = Field(
|
||||
lu_membership_person_status_name: Optional[str] = Field(
|
||||
alias = 'status_name'
|
||||
)
|
||||
|
||||
@@ -52,6 +52,16 @@ class Membership_Person_Base(BaseModel):
|
||||
alias = 'group_name',
|
||||
)
|
||||
|
||||
membership_group_person_id_random: Optional[str] = Field(
|
||||
alias = 'group_person_id_random',
|
||||
) # NOTE: This is not optional
|
||||
membership_group_person_id: Optional[int] = Field(
|
||||
alias = 'group_person_id',
|
||||
) # NOTE: This is not optional
|
||||
membership_group_person_name: Optional[str] = Field(
|
||||
alias = 'group_person_name',
|
||||
)
|
||||
|
||||
membership_type_id_random: Optional[str] = Field(
|
||||
alias = 'type_id_random',
|
||||
) # NOTE: This is not optional
|
||||
@@ -62,11 +72,31 @@ class Membership_Person_Base(BaseModel):
|
||||
alias = 'type_name',
|
||||
)
|
||||
|
||||
membership_type_person_id_random: Optional[str] = Field(
|
||||
alias = 'type_person_id_random',
|
||||
) # NOTE: This is not optional
|
||||
membership_type_person_id: Optional[int] = Field(
|
||||
alias = 'type_person_id',
|
||||
) # NOTE: This is not optional
|
||||
membership_type_person_name: Optional[str] = Field(
|
||||
alias = 'type_person_name',
|
||||
)
|
||||
|
||||
person_id_random: Optional[str]
|
||||
person_id: Optional[int]
|
||||
|
||||
product_id_random: Optional[str]
|
||||
product_id: Optional[int] # The product they purchased to get this membership
|
||||
# For products use:
|
||||
# link using membership_person.membership_group_person_id to membership_group_person.id
|
||||
# link using membership_person.membership_type_person_id to membership_type_person.id
|
||||
|
||||
# product_id_random: Optional[str]
|
||||
# product_id: Optional[int] # The product they purchased to get this membership
|
||||
|
||||
# membership_group_product_id_random: Optional[str]
|
||||
# membership_group_product_id: Optional[int] # The product they purchased to get this group
|
||||
|
||||
# membership_type_product_id_random: Optional[str]
|
||||
# membership_type_product_id: Optional[int] # The product they purchased to get this type
|
||||
|
||||
user_id_random: Optional[str]
|
||||
user_id: Optional[int]
|
||||
@@ -162,6 +192,15 @@ class Membership_Person_Base(BaseModel):
|
||||
return redis_lookup_id_random(record_id_random=values['membership_group_id_random'], table_name='membership_group')
|
||||
return None
|
||||
|
||||
@validator('membership_group_person_id', always=True)
|
||||
def membership_group_person_id_lookup(cls, v, values, **kwargs):
|
||||
log.setLevel(logging.WARNING)
|
||||
log.debug(locals())
|
||||
|
||||
if values['membership_group_person_id_random']:
|
||||
return redis_lookup_id_random(record_id_random=values['membership_group_person_id_random'], table_name='membership_group_person')
|
||||
return None
|
||||
|
||||
@validator('membership_type_id', always=True)
|
||||
def membership_type_id_lookup(cls, v, values, **kwargs):
|
||||
log.setLevel(logging.WARNING)
|
||||
@@ -171,6 +210,15 @@ class Membership_Person_Base(BaseModel):
|
||||
return redis_lookup_id_random(record_id_random=values['membership_type_id_random'], table_name='membership_type')
|
||||
return None
|
||||
|
||||
@validator('membership_type_person_id', always=True)
|
||||
def membership_type_person_id_lookup(cls, v, values, **kwargs):
|
||||
log.setLevel(logging.WARNING)
|
||||
log.debug(locals())
|
||||
|
||||
if values['membership_type_person_id_random']:
|
||||
return redis_lookup_id_random(record_id_random=values['membership_type_person_id_random'], table_name='membership_type_person')
|
||||
return None
|
||||
|
||||
@validator('person_id', always=True)
|
||||
def person_id_lookup(cls, v, values, **kwargs):
|
||||
log.setLevel(logging.WARNING)
|
||||
@@ -180,14 +228,14 @@ class Membership_Person_Base(BaseModel):
|
||||
return redis_lookup_id_random(record_id_random=values['person_id_random'], table_name='person')
|
||||
return None
|
||||
|
||||
@validator('product_id', always=True)
|
||||
def product_id_lookup(cls, v, values, **kwargs):
|
||||
log.setLevel(logging.WARNING)
|
||||
log.debug(locals())
|
||||
# @validator('product_id', always=True)
|
||||
# def product_id_lookup(cls, v, values, **kwargs):
|
||||
# log.setLevel(logging.WARNING)
|
||||
# log.debug(locals())
|
||||
|
||||
if values['product_id_random']:
|
||||
return redis_lookup_id_random(record_id_random=values['product_id_random'], table_name='product')
|
||||
return None
|
||||
# if values['product_id_random']:
|
||||
# return redis_lookup_id_random(record_id_random=values['product_id_random'], table_name='product')
|
||||
# return None
|
||||
|
||||
@validator('user_id', always=True)
|
||||
def user_id_lookup(cls, v, values, **kwargs):
|
||||
|
||||
@@ -26,7 +26,7 @@ class User_New_Base(BaseModel):
|
||||
default_factory = lambda:secrets.token_urlsafe(default_num_bytes),
|
||||
)
|
||||
id: Optional[int] = Field(
|
||||
#alias = 'user_id'
|
||||
alias = 'user_id'
|
||||
)
|
||||
account_id_random: str
|
||||
account_id: Optional[int]
|
||||
|
||||
@@ -9,7 +9,7 @@ from app.db_sql import sql_insert, sql_update, sql_insert_or_update, sql_select,
|
||||
|
||||
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.event_methods import load_event_obj, update_event_obj
|
||||
from app.methods.event_methods import get_event_rec_list, load_event_obj, update_event_obj
|
||||
|
||||
from app.models.event_models import Event_Base
|
||||
from app.models.response_models import Resp_Body_Base, mk_resp
|
||||
@@ -341,6 +341,72 @@ async def get_event_obj(
|
||||
# ### END ### API Event ### get_event_obj() ###
|
||||
|
||||
|
||||
|
||||
# ### BEGIN ### API Event Methods ### get_person_event_obj_li() ###
|
||||
# Updated 2021-07-12
|
||||
@router.get('/person/{person_id}/event/list', response_model=Resp_Body_Base)
|
||||
async def get_person_event_obj_li(
|
||||
person_id: str = Query(..., min_length=1, max_length=22),
|
||||
enabled: str = 'enabled',
|
||||
limit: int = 1000,
|
||||
conference: bool = False, # If it is a conference then organization, person, and user are queried as participants (not the owner/organizer)
|
||||
inc_address: bool = False,
|
||||
inc_contact: bool = False,
|
||||
inc_event_abstract_list: bool = False,
|
||||
inc_event_badge: bool = False,
|
||||
inc_event_cfg: bool = False,
|
||||
inc_event_exhibit_list: bool = False,
|
||||
inc_event_file_list: bool = False,
|
||||
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_organization: bool = False,
|
||||
inc_person: bool = False,
|
||||
x_account_id: str = Header(...),
|
||||
by_alias: Optional[bool] = True,
|
||||
exclude_unset: Optional[bool] = True,
|
||||
):
|
||||
log.setLevel(logging.WARNING) # 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 mk_resp(data=None, status_code=404)
|
||||
|
||||
# Updated 2021-07-12
|
||||
if event_rec_list_result := get_event_rec_list(
|
||||
person_id = person_id,
|
||||
limit = limit,
|
||||
enabled = enabled,
|
||||
conference = conference,
|
||||
):
|
||||
event_result_list = []
|
||||
for event_rec in event_rec_list_result:
|
||||
if load_event_result := load_event_obj(
|
||||
event_id = event_rec.get('event_id', None),
|
||||
enabled = enabled,
|
||||
limit = limit,
|
||||
inc_address = inc_address,
|
||||
inc_contact = inc_contact,
|
||||
inc_event_cfg = inc_event_cfg,
|
||||
inc_organization = inc_organization,
|
||||
inc_person = inc_person,
|
||||
by_alias = by_alias,
|
||||
exclude_unset = exclude_unset,
|
||||
# model_as_dict = model_as_dict,
|
||||
):
|
||||
event_result_list.append(load_event_result)
|
||||
else:
|
||||
event_result_list.append(None)
|
||||
response_data = event_result_list
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400) # Bad Request
|
||||
|
||||
return mk_resp(data=response_data)
|
||||
# ### END ### API Event Methods ### get_person_event_obj_li() ###
|
||||
|
||||
|
||||
@router.delete('/{obj_id}', response_model=Resp_Body_Base)
|
||||
async def delete_event_obj(
|
||||
obj_id: str = Query(..., min_length=1, max_length=22),
|
||||
|
||||
@@ -269,3 +269,37 @@ async def get_event_person_obj(
|
||||
|
||||
return mk_resp(data=event_person_obj)
|
||||
# ### END ### API Event ### get_event_person_obj() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Event Person Methods ### get_person_event_person_obj_li() ###
|
||||
# Updated 2021-07-12
|
||||
@router.get('/person/{person_id}/event/person/list', response_model=Resp_Body_Base)
|
||||
async def get_person_event_person_obj_li(
|
||||
person_id: str = Query(..., min_length=1, max_length=22),
|
||||
enabled: str = 'enabled',
|
||||
limit: int = 1000,
|
||||
inc_address: bool = False,
|
||||
inc_contact: bool = False,
|
||||
# inc_event: bool = False,
|
||||
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_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_user: bool = False,
|
||||
x_account_id: str = Header(...),
|
||||
by_alias: Optional[bool] = True,
|
||||
exclude_unset: Optional[bool] = True,
|
||||
):
|
||||
log.setLevel(logging.WARNING) # 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 mk_resp(data=None, status_code=404)
|
||||
|
||||
return mk_resp(data=response_data)
|
||||
# ### BEGIN ### API Event Person Methods ### get_person_event_person_obj_li() ###
|
||||
|
||||
Reference in New Issue
Block a user