This commit is contained in:
Scott Idem
2022-03-09 17:42:24 -05:00
parent fd23018647
commit 57e3298dc6
4 changed files with 38 additions and 69 deletions

View File

@@ -1,4 +1,3 @@
from __future__ import annotations
import datetime, hashlib, logging, os, pytz, redis, secrets
from typing import Dict, List, Optional, Set, Union
@@ -11,7 +10,7 @@ from .common_field_schema import base_fields, default_num_bytes
class Hosted_File_Base(BaseModel):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
id_random: Optional[str] = Field(
@@ -20,8 +19,9 @@ class Hosted_File_Base(BaseModel):
default_factory = lambda:secrets.token_urlsafe(default_num_bytes),
)
id: Optional[int] = Field(
#alias = 'hosted_file_id'
alias = 'hosted_file_id'
)
account_id_random: Optional[str]
account_id: Optional[int]
@@ -67,30 +67,22 @@ class Hosted_File_Base(BaseModel):
#@validator('hosted_file_id_random', always=True)
def hosted_file_id_random_copy(cls, v, values, **kwargs):
log.setLevel(logging.WARNING)
log.debug(locals())
if values['id_random']:
return values['id_random']
return None
@validator('id', always=True)
def hosted_file_id_lookup(cls, v, values, **kwargs):
log.setLevel(logging.WARNING)
log.debug(locals())
if values['id_random']:
log.debug(values['id_random'])
return redis_lookup_id_random(record_id_random=values['id_random'], table_name='hosted_file')
if isinstance(v, int) and v > 0: return v
elif id_random := values.get('id_random'):
return redis_lookup_id_random(record_id_random=id_random, table_name='hosted_file')
return None
@validator('account_id', always=True)
def account_id_lookup(cls, v, values, **kwargs):
log.setLevel(logging.WARNING)
log.debug(locals())
if values['account_id_random']:
return redis_lookup_id_random(record_id_random=values['account_id_random'], table_name='account')
if isinstance(v, int) and v > 0: return v
elif id_random := values.get('account_id_random'):
return redis_lookup_id_random(record_id_random=id_random, table_name='account')
return None
class Config: