Working on event registration. Why wont it load???

This commit is contained in:
Scott Idem
2021-08-13 18:09:41 -04:00
parent 1bb3867463
commit 8fd8b89ff4
4 changed files with 92 additions and 14 deletions

View File

@@ -301,7 +301,7 @@ def sql_select(
max_count: int = 100000
):
current_log_level = log.level
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
if table_name and not (record_id or record_id_random or field_name or field_value or sql or data):

View File

@@ -0,0 +1,54 @@
from __future__ import annotations
import datetime
from typing import Dict, List, Optional, Set, Union
from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, validator
from app.db_sql import redis_lookup_id_random, sql_insert, sql_select, sql_update
from app.lib_general import log, logging
# from app.methods.address_methods import load_address_obj
# from app.methods.contact_methods import load_contact_obj
from app.methods.event_cfg_methods import load_event_cfg_obj
from app.methods.person_methods import load_person_obj
from app.models.event_registration_models import Event_Registration_Base
from app.models.event_cfg_models import Event_Cfg_Base
# ### BEGIN ### API Event Registration Methods ### load_event_registration_obj() ###
def load_event_registration_obj(
event_registration_id: int|str,
limit: int = 1000,
by_alias: bool = True,
exclude_unset: bool = True,
model_as_dict: bool = False,
enabled: str = 'enabled', # enabled, disabled, all
inc_address: bool = False, # Under contact
inc_contact: bool = False,
inc_event_cfg: bool = False,
inc_event_person_list: bool = False,
inc_event_registration_cfg: bool = False,
inc_person: bool = False,
) -> Event_Registration_Base|bool:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
if event_registration_id := redis_lookup_id_random(record_id_random=event_registration_id, table_name='event_registration'): pass
else: return False
if event_registration_rec := sql_select(table_name='v_event_registration', record_id=event_registration_id): pass
else: return False
print('******************************** HERE')
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(event_registration_rec)
try:
event_registration_obj = Event_Registration_Base(**event_registration_rec)
log.debug(event_registration_obj)
except ValidationError as e:
log.error(e.json())
return False
# ### END ### API Event Registration Methods ### load_event_registration_obj() ###

View File

@@ -12,7 +12,7 @@ from app.models.event_registration_cfg_models import Event_Registration_Cfg_Base
class Event_Registration_Base(BaseModel):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
id_random: Optional[str] = Field(
@@ -21,7 +21,7 @@ class Event_Registration_Base(BaseModel):
default_factory = lambda:secrets.token_urlsafe(default_num_bytes),
)
id: Optional[int] = Field(
#alias = 'event_registration_id'
alias = 'event_registration_id'
)
account_id_random: Optional[str]
account_id: Optional[int]
@@ -113,6 +113,7 @@ class Event_Registration_Base(BaseModel):
class Config:
underscore_attrs_are_private = True
allow_population_by_field_name = True
fields = base_fields
Event_Registration_Base.update_forward_refs()

View File

@@ -11,6 +11,8 @@ 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 app.methods.event_registration_methods import load_event_registration_obj
from app.models.event_registration_models import Event_Registration_Base
from app.models.response_models import *
@@ -93,25 +95,46 @@ async def get_event_registration_obj_li(
return result
@router.get('/{obj_id}', response_model=Resp_Body_Base)
@router.get('/{event_registration_id}', response_model=Resp_Body_Base)
async def get_event_registration_obj(
obj_id: str = Query(..., min_length=1, max_length=22),
event_registration_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_event_registration_cfg: bool = False,
inc_event_registration_list: bool = False,
x_account_id: str = Header(...),
by_alias: Optional[bool] = True,
exclude_unset: Optional[bool] = True,
response: Response = Response,
):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
obj_type = 'event_registration'
result = get_obj_template(
obj_type=obj_type,
obj_id=obj_id,
by_alias=True,
exclude_unset=True,
)
return result
if event_registration_id := redis_lookup_id_random(record_id_random=event_registration_id, table_name='event_registration'): pass
else: return mk_resp(data=None, status_code=404)
if event_registration_obj := load_event_registration_obj(
event_registration_id = event_registration_id,
limit = limit,
by_alias = by_alias,
exclude_unset = exclude_unset,
# model_as_dict = model_as_dict,
enabled = enabled,
):
pass
else:
return mk_resp(data=False, status_code=400, response=response) # Bad Request
return mk_resp(data=event_registration_obj)
# obj_type = 'event_registration'
# result = get_obj_template(
# obj_type=obj_type,
# obj_id=event_registration_id,
# by_alias=True,
# exclude_unset=True,
# )
# return result
@router.delete('/{obj_id}', response_model=Resp_Body_Base)