Files
OSIT-AE-API-FastAPI/app/models/account_models.py
Scott Idem 17a627a981 feat: Implement Event File Hosted Data Fix and API Guide Update
Address critical data visibility issues for Event Files and enhance frontend documentation.

This commit resolves the persistent problem where top-level hosted file convenience fields
(e.g., , , ) were
returning as  in V3 Event File API responses, even when .

Key changes include:
- Refactored  Pydantic model:
    - Removed redundant  definitions from top-level hosted file convenience fields,
      allowing direct mapping from SQL view columns.
    - Simplified  to focus solely on conditionally loading the nested
       object, as top-level fields are now populated directly by Pydantic
      from the  view.
    - Added comprehensive comments to clarify data flow, Pydantic's behavior, and the
      expected origin of these convenience fields from SQL views.
- Updated :
    - Introduced a new section detailing how to retrieve Event File data, including the
      use of  to get both top-level convenience fields and a nested
       object.
    - Clarified all ID references as random string IDs.
    - Renumbered the troubleshooting section.
- Copied updated guide to .
- Continued ID Vision compliance audit, ensuring consistent handling of random string IDs
  across various core and event models (Account, Address, Contact, DataStore, Event Badge Template).
- Consolidated ID Vision E2E tests and updated related documentation.
- Minor updates to  and
  to support Event File data retrieval with .
2026-02-19 15:22:17 -05:00

102 lines
4.2 KiB
Python

import datetime, pytz
from typing import Dict, List, Optional, Set, Union, ClassVar
from pydantic import BaseModel, EmailStr, Field, Json, PrivateAttr, ValidationError, validator, root_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.account_cfg_models import Account_Cfg_Base
# from app.models.address_models import Address_Base
# from app.models.contact_models import Contact_Base
# from app.models.event_models import Event_Base
from app.models.fundraising_cfg_models import Fundraising_Cfg_Base
from app.models.membership_cfg_models import Membership_Cfg_Base
# from app.models.person_models import Person_Base
# from app.models.user_models import User_Base
# ### BEGIN ### API Account Models ### Account_Base() ###
class Account_Base(BaseModel):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
# --- Standardized Vision IDs (Strings) ---
id: Optional[str] = Field(None, **base_fields['account_id_random'])
account_id: Optional[str] = Field(None, **base_fields['account_id_random'])
# --- Standardized Legacy / Internal IDs (Excluded) ---
id_random: Optional[str] = Field(None, alias='account_id_random', exclude=True)
code: Optional[str]
name: Optional[str]
short_name: Optional[str]
description: Optional[str]
hide: Optional[bool]
priority: Optional[bool]
sort: Optional[int]
group: Optional[str]
enable: Optional[bool]
enable_from: Optional[datetime.datetime] = None
enable_to: Optional[datetime.datetime] = None
notes: Optional[str]
created_on: Optional[datetime.datetime] = None
updated_on: Optional[datetime.datetime] = None
# testing: Optional[str]
# Including other related objects
account_cfg: Optional[Account_Cfg_Base] # Priority l1
address_list: Optional[list] # Address_Base() # Priority l3
archive_list: Optional[list] # Archive_Base() # Priority l1
contact_list: Optional[list] # Contact_Base() # Priority l3
event_list: Optional[list] # Event_Base() # Priority l1
fundraising_cfg: Optional[Fundraising_Cfg_Base] # Priority l2
hosted_file_list: Optional[list] # Hosted_File_Base() # Priority l2
journal_list: Optional[list] # Journal_Base() # Priority l3
membership_cfg: Optional[Membership_Cfg_Base] # Priority l2
membership_group_list: Optional[list] # Membership_Group_Base() # Priority l2
membership_person_list: Optional[list] # Membership_Person_Base() # Priority l2
membership_type_list: Optional[list] # Membership_Type_Base() # Priority l2
order_list: Optional[list] # Order_Base() # Priority l2
organization_list: Optional[list] # Organization_Base() # Priority l3
page_list: Optional[list] # Page_Base() # Priority l3
person_list: Optional[list] # Person_Base() # Priority l2
post_list: Optional[list] # Post_Base() # Priority l1
product_list: Optional[list] # Product_Base() # Priority l3
site_list: Optional[list] # Site_Base() # Priority l3
user_list: Optional[list] # User_Base() # Priority l2
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
@root_validator(pre=True)
def map_v3_ids(cls, values):
"""
Vision Transformer:
Map DB keys to clean API keys and strip internal integers.
"""
# 1. Map Random Strings to Clean Names
if rid := values.get('id_random') or values.get('account_id_random'):
values['id'] = rid
values['account_id'] = rid
# 2. Final Vision Enforcement: Strip internal integers from public fields
for k in ['id', 'account_id']:
val = values.get(k)
if val is not None:
# If it's not a valid random string ID
if not isinstance(val, str) or len(val) < 11:
values[k] = None
return values
class Config:
underscore_attrs_are_private = True
allow_population_by_field_name = False
fields = base_fields
# ### END ### API Account Models ### Account_Base() ###