63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
from __future__ import annotations
|
|
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 ..lib_general import *
|
|
|
|
from .common_field_schema import base_fields, default_num_bytes
|
|
|
|
|
|
class Account_Base(BaseModel):
|
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(locals())
|
|
|
|
id_random: Optional[str] = Field(
|
|
**base_fields['account_id_random'],
|
|
alias='account_id_random',
|
|
default_factory=lambda:secrets.token_urlsafe(default_num_bytes),
|
|
)
|
|
id: Optional[int] = Field(
|
|
#alias='account_id'
|
|
)
|
|
|
|
code: Optional[str]
|
|
name: Optional[str]
|
|
description: 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
|
|
|
|
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
|
|
|
#@validator('account_id_random', always=True)
|
|
def account_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 account_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='account')
|
|
return None
|
|
|
|
class Config:
|
|
underscore_attrs_are_private = True
|
|
fields = base_fields
|
|
|
|
#Account_Base.update_forward_refs()
|