Standardized Badge, Exhibit, and Tracking models to ID Vision standards. Included account_id support for exhibit tracking and removed legacy validators to ensure stable CRUD operations for the Tuesday demo.
128 lines
5.8 KiB
Python
128 lines
5.8 KiB
Python
import datetime, pytz
|
|
|
|
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 log, logging
|
|
|
|
from app.models.common_field_schema import base_fields, default_num_bytes
|
|
from app.models.event_exhibit_tracking_models import Event_Exhibit_Tracking_Base
|
|
|
|
|
|
# ### BEGIN ### API Event Exhibit Models ### Event_Exhibit_Base() ###
|
|
class Event_Exhibit_Base(BaseModel):
|
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(locals())
|
|
|
|
# --- Standardized Vision IDs (Strings for API, Integers for DB) ---
|
|
id: Optional[Union[int, str]] = Field(None, **base_fields['event_exhibit_id_random'])
|
|
event_exhibit_id: Optional[Union[int, str]] = Field(None, **base_fields['event_exhibit_id_random'])
|
|
account_id: Optional[Union[int, str]] = Field(None, **base_fields['account_id_random'])
|
|
event_id: Optional[Union[int, str]] = Field(None, **base_fields['event_id_random'])
|
|
organization_id: Optional[Union[int, str]] = Field(None, **base_fields['organization_id_random'])
|
|
contact_id: Optional[Union[int, str]] = Field(None, **base_fields['contact_id_random'])
|
|
person_id: Optional[Union[int, str]] = Field(None, **base_fields['person_id_random'])
|
|
status_id: Optional[Union[int, str]] = Field(None, **base_fields['status_id_random'])
|
|
|
|
# --- Standardized Legacy / Internal IDs (Excluded) ---
|
|
id_random: Optional[str] = Field(None, alias='event_exhibit_id_random', exclude=True)
|
|
account_id_random: Optional[str] = Field(None, exclude=True)
|
|
event_id_random: Optional[str] = Field(None, exclude=True)
|
|
organization_id_random: Optional[str] = Field(None, exclude=True)
|
|
contact_id_random: Optional[str] = Field(None, exclude=True)
|
|
person_id_random: Optional[str] = Field(None, exclude=True)
|
|
status_id_random: Optional[str] = Field(None, exclude=True)
|
|
|
|
@root_validator(pre=True)
|
|
def map_v3_ids(cls, values):
|
|
"""
|
|
Vision Transformer:
|
|
Map DB keys to clean API keys and strip internal integers during READ operations.
|
|
"""
|
|
# 1. Map Random Strings to Clean Names
|
|
rid = values.get('id_random') or values.get('event_exhibit_id_random')
|
|
if rid and isinstance(rid, str):
|
|
values['id'] = rid
|
|
values['event_exhibit_id'] = rid
|
|
|
|
if a_rid := values.get('account_id_random'): values['account_id'] = a_rid
|
|
if e_rid := values.get('event_id_random'): values['event_id'] = e_rid
|
|
if o_rid := values.get('organization_id_random'): values['organization_id'] = o_rid
|
|
if c_rid := values.get('contact_id_random'): values['contact_id'] = c_rid
|
|
if p_rid := values.get('person_id_random'): values['person_id'] = p_rid
|
|
if s_rid := values.get('status_id_random'): values['status_id'] = s_rid
|
|
|
|
# 2. Prevent "Collision Population" or leakage of integers during API responses
|
|
for k in ['id', 'event_exhibit_id', 'account_id', 'event_id', 'organization_id', 'contact_id', 'person_id', 'status_id']:
|
|
val = values.get(k)
|
|
if val is not None and not isinstance(val, str):
|
|
if values.get(f'{k}_random') or (k=='id' and values.get('id_random')):
|
|
del values[k]
|
|
|
|
return values
|
|
|
|
code: Optional[str] # The assigned booth number or ID
|
|
|
|
staff_passcode: Optional[str]
|
|
|
|
name: Optional[str]
|
|
tagline: Optional[str]
|
|
description: Optional[str]
|
|
logo_path: Optional[str]
|
|
thumbnail_path: Optional[str]
|
|
banner_image_path: Optional[str]
|
|
banner_bg_color: Optional[str]
|
|
background_image_path: Optional[str]
|
|
background_bg_color: Optional[str]
|
|
|
|
embed_html: Optional[str]
|
|
|
|
staff_limit: Optional[int]
|
|
hosted_file_limit: Optional[int]
|
|
|
|
leads_api_access: Optional[bool] # NOTE: API access and use
|
|
# Json type NOTE: All keys and values must be double quoted!
|
|
# {"field_name": "The field value"}
|
|
leads_custom_questions_json: Optional[Json] # NOTE: For now just using string instead of Json Pydantic data type. When getting the dict version for SQL this should be a string.
|
|
leads_device_sm_qty: Optional[int] # NOTE: Cell phone sized devices rented by exhibitor. Should this be a separate linked table (event_device)?
|
|
leads_device_lg_qty: Optional[int] # NOTE: Tablet (8 or 9 inch) sized devices rented by exhibitor. Should this be a separate linked table (event_device)?
|
|
|
|
data_json: Optional[Union[Json, None]]
|
|
license_max: Optional[int]
|
|
license_li_json: Optional[Union[Json, None]]
|
|
cfg_json: Optional[Union[Json, None]]
|
|
|
|
enable_organization_name_change: Optional[bool]
|
|
enable_name_change: Optional[bool]
|
|
enable_banner_image: Optional[bool]
|
|
enable_background_image: Optional[bool]
|
|
enable_embedded_content: Optional[bool]
|
|
enable_staff_photo: Optional[bool]
|
|
|
|
# access_key: Optional[str] # Maybe use in the future?
|
|
|
|
enable: Optional[bool]
|
|
# enable_from: Optional[datetime.datetime] = None # Maybe use in the future?
|
|
# enable_to: Optional[datetime.datetime] = None # Maybe use in the future?
|
|
|
|
hide: Optional[bool]
|
|
priority: Optional[bool]
|
|
sort: Optional[int]
|
|
group: Optional[str]
|
|
|
|
notes: Optional[str]
|
|
created_on: Optional[datetime.datetime] = None
|
|
updated_on: Optional[datetime.datetime] = None
|
|
|
|
# Including other related objects
|
|
event_exhibit_tracking_list: Optional[list[Event_Exhibit_Tracking_Base]]
|
|
|
|
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
|
|
|
class Config:
|
|
underscore_attrs_are_private = True
|
|
allow_population_by_field_name = True
|
|
fields = base_fields
|
|
# ### END ### API Event Exhibit Models ### Event_Exhibit_Base() ###
|