69 lines
2.4 KiB
Python
69 lines
2.4 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
|
|
|
|
|
|
# ### BEGIN ### API Fundraising Config Models ### Fundraising_Cfg_Base() ###
|
|
class Fundraising_Cfg_Base(BaseModel):
|
|
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(locals())
|
|
|
|
id_random: Optional[str] = Field(
|
|
**base_fields['fundraising_id_random'],
|
|
alias = 'fundraising_id_random',
|
|
)
|
|
id: Optional[int] = Field(
|
|
#alias = 'fundraising_id'
|
|
)
|
|
|
|
account_id_random: Optional[str]
|
|
account_id: Optional[int]
|
|
|
|
header_html: Optional[str]
|
|
start_html: Optional[str]
|
|
message_html: Optional[str]
|
|
end_html: Optional[str]
|
|
footer_html: Optional[str]
|
|
|
|
order_thanks: Optional[str] # Is this needed here or at all?
|
|
order_message: Optional[str] # Is this needed here or at all?
|
|
message: Optional[str] # Is this needed here or at all?
|
|
|
|
enable: Optional[bool]
|
|
|
|
hide: Optional[bool]
|
|
priority: Optional[bool]
|
|
sort: Optional[int]
|
|
group: Optional[str] # Same or similar as file_purpose?
|
|
|
|
created_on: Optional[datetime.datetime] = None
|
|
updated_on: Optional[datetime.datetime] = None
|
|
|
|
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
|
|
|
@validator('id', always=True)
|
|
def fundraising_cfg_id_lookup(cls, v, values, **kwargs):
|
|
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='v_fundraising_cfg') # There is only a view 2022-11-18
|
|
return None
|
|
|
|
@validator('account_id', always=True)
|
|
def account_id_lookup(cls, v, values, **kwargs):
|
|
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:
|
|
underscore_attrs_are_private = True
|
|
allow_population_by_field_name = True
|
|
fields = base_fields
|
|
# ### END ### API Fundraising Config Models ### Fundraising_Cfg_Base() ###
|