Now with the an email send endpoint!
This commit is contained in:
78
app/models/util_email_models.py
Normal file
78
app/models/util_email_models.py
Normal file
@@ -0,0 +1,78 @@
|
||||
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
|
||||
|
||||
from app.models.core_object_models import Core_Std_Obj_Base
|
||||
|
||||
|
||||
# ### BEGIN ### API Utility: Email Models ### Email_Send_Base() ###
|
||||
# Update 2023-06-27
|
||||
class Email_Send_Base(BaseModel):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
id_random: Optional[str] = Field(
|
||||
# **base_fields['email_id_random'],
|
||||
alias = 'email_id_random',
|
||||
)
|
||||
id: Optional[int] = Field(
|
||||
alias = 'email_id'
|
||||
)
|
||||
|
||||
account_id_random: Optional[str]
|
||||
account_id: Optional[int]
|
||||
|
||||
testing: Optional[bool] = False
|
||||
|
||||
from_email: str # = 'from_test@example.com'
|
||||
from_name: str = None
|
||||
|
||||
to_email: str # = 'to_test@example.com'
|
||||
to_name: str = None
|
||||
|
||||
cc_email: str = None
|
||||
cc_name: str = None
|
||||
|
||||
bcc_email: str = None
|
||||
bcc_name: str = None
|
||||
|
||||
subject: str
|
||||
|
||||
body_html: str
|
||||
body_text: str = None
|
||||
|
||||
# json: Optional[str] # "json" is reserved; need to change field name? json_str?
|
||||
# json_str: Optional[Union[Json, None]] = Field(
|
||||
# alias = 'json',
|
||||
# )
|
||||
# text: Optional[str]
|
||||
|
||||
# notes: Optional[str]
|
||||
|
||||
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
||||
|
||||
@validator('id', always=True)
|
||||
def email_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='email')
|
||||
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 Grant Models ### Grant_Base() ###
|
||||
Reference in New Issue
Block a user