Work on a lot of things. Mainly cleaning up person and profile related fields in multiple tables.
This commit is contained in:
@@ -4,7 +4,7 @@ import datetime, hashlib, logging, os, pytz, redis, secrets
|
||||
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, get_id_random
|
||||
from app.db_sql import get_id_random, redis_lookup_id_random
|
||||
from app.lib_general import log, logging
|
||||
|
||||
from app.models.common_field_schema import base_fields, default_num_bytes
|
||||
@@ -27,11 +27,12 @@ class Event_File_Base(BaseModel):
|
||||
hosted_file_id_random: Optional[str]
|
||||
hosted_file_id: Optional[int]
|
||||
|
||||
# NOTE: Handeling this outside of the Pydantic model and model validation. See below as well. -STI 2021-09-10
|
||||
for_type: Optional[str]
|
||||
# for_id: Optional[int] # NOTE: This is reversed with for_id_random I HAVE NO IDEA 2021-08-26 4:05 AM
|
||||
# for_id_random: Optional[str] # NOTE: This is reversed with for_id I HAVE NO IDEA 2021-08-26 4:05 AM
|
||||
for_id_random: Optional[str]
|
||||
for_id: Optional[int]
|
||||
for_id: Optional[int] # NOTE: This is reversed with for_id_random
|
||||
for_id_random: Optional[str] # NOTE: This is reversed with for_id
|
||||
# for_id_random: Optional[str] = None # Need to override value from common_field_schema.py
|
||||
# for_id: Optional[int]
|
||||
|
||||
event_id_random: Optional[str]
|
||||
event_id: Optional[int]
|
||||
@@ -64,7 +65,7 @@ class Event_File_Base(BaseModel):
|
||||
|
||||
priority: Optional[bool]
|
||||
sort: Optional[int]
|
||||
group: Optional[str]
|
||||
group: Optional[str] # Same or similar as file_purpose?
|
||||
|
||||
# notes: Optional[str]
|
||||
created_on: Optional[datetime.datetime] = None
|
||||
@@ -166,23 +167,26 @@ class Event_File_Base(BaseModel):
|
||||
return redis_lookup_id_random(record_id_random=values['event_track_id_random'], table_name='event_track')
|
||||
return None
|
||||
|
||||
# NOTE: I kind of give up on this. Handeling this outside of Pydantic and before the data is even attempted to be loaded into the Event_File_Base model. -STI 2021-09-10
|
||||
# NOTE: This validator will try to find and "set" the for_id_random value. However, The value is not really "set" in Pydantic. To get this value, exclude_unset=True when returning a dict from the model.
|
||||
# @validator('for_id_random', always=True)
|
||||
# def for_id_random_lookup(cls, v, values, **kwargs):
|
||||
# log.setLevel(logging.DEBUG)
|
||||
# log.setLevel(logging.WARNING)
|
||||
# log.debug(locals())
|
||||
|
||||
# if values['for_id'] and values['for_type']:
|
||||
# if values.get('for_id') and values['for_type']:
|
||||
# return get_id_random(record_id=values['for_id'], table_name=values['for_type'])
|
||||
# return None
|
||||
|
||||
@validator('for_id', always=True)
|
||||
def for_id_lookup(cls, v, values, **kwargs):
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.debug(locals())
|
||||
# @validator('for_id', always=True)
|
||||
# def for_id_lookup(cls, v, values, **kwargs):
|
||||
# log.setLevel(logging.DEBUG)
|
||||
# log.debug(locals())
|
||||
|
||||
if values['for_id_random'] and values['for_type']:
|
||||
return redis_lookup_id_random(record_id_random=values['for_id_random'], table_name=values['for_type'])
|
||||
return None
|
||||
# if values.get('for_id_random', None) and values['for_type']:
|
||||
# return redis_lookup_id_random(record_id_random=values['for_id_random'], table_name=values['for_type'])
|
||||
# # return None
|
||||
# else: return v
|
||||
|
||||
class Config:
|
||||
underscore_attrs_are_private = True
|
||||
|
||||
Reference in New Issue
Block a user