(20241219) SMS module fully re-organized.
This commit is contained in:
+78
-9
@@ -36,7 +36,7 @@ sys.path.append(".")
|
||||
sys.path.append("..")
|
||||
|
||||
# For making data behaviour_models:
|
||||
from pydantic import BaseModel, Field, field_validator, PastDatetime
|
||||
from pydantic import BaseModel, Field, field_validator, PastDatetime, EmailStr
|
||||
from typing import Optional, Literal, List
|
||||
|
||||
# My utils:
|
||||
@@ -103,9 +103,33 @@ class MailSendRequestHeaders(BaseModel):
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class MailSendInlineFiles(BaseModel):
|
||||
|
||||
key: str = Field(
|
||||
description = "the key in the form data under which the file has been sent",
|
||||
frozen = True
|
||||
)
|
||||
|
||||
cid: str = Field(
|
||||
description = "the content id to assign to the file",
|
||||
frozen = True
|
||||
)
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class MailSendRequestData(BaseModel):
|
||||
|
||||
tokenKey: str = Field(
|
||||
tokenKey: ObjectId = Field(
|
||||
description = "the account identifier (Mongo ObjectId)",
|
||||
frozen = True
|
||||
)
|
||||
@@ -115,11 +139,34 @@ class MailSendRequestData(BaseModel):
|
||||
frozen = True
|
||||
)
|
||||
|
||||
inlineKeys: List[str] = Field(
|
||||
to: List[EmailStr] = Field(
|
||||
description = "the recipient of your mail",
|
||||
# default = None,
|
||||
# validate_default = True,
|
||||
frozen = True
|
||||
)
|
||||
|
||||
cc: List[EmailStr] = Field(
|
||||
description = "the list of ids to add as cc",
|
||||
default = None,
|
||||
validate_default = True,
|
||||
frozen = True
|
||||
)
|
||||
|
||||
bcc: List[EmailStr] = Field(
|
||||
description = "the list of ids to add as bcc",
|
||||
default = None,
|
||||
validate_default = True,
|
||||
frozen = True
|
||||
)
|
||||
|
||||
inlineFiles: List[MailSendInlineFiles] = Field(
|
||||
description = (
|
||||
"when sending files, this will be a list of keys whose "
|
||||
"associated files will be treated as inline files"
|
||||
),
|
||||
default = None,
|
||||
validate_default = True,
|
||||
frozen = True
|
||||
)
|
||||
|
||||
@@ -142,13 +189,35 @@ class MailSendRequestData(BaseModel):
|
||||
except: pass
|
||||
return value
|
||||
|
||||
@field_validator("inlineKeys", mode = "before")
|
||||
@field_validator("inlineFiles", mode = "before")
|
||||
def parse_json(cls, value):
|
||||
try:
|
||||
value = json.from_string(value)
|
||||
if not isinstance(value, list): raise ValueError("'inlineKeys' needs to be an array")
|
||||
except Exception as exception:
|
||||
raise ValueError("'inlineKeys' could not be parsed")
|
||||
|
||||
# If we get a null value or an empty string:
|
||||
if value is None: return []
|
||||
if isinstance(value, str):
|
||||
if not value.strip(): return []
|
||||
|
||||
# If we get a properly populated string:
|
||||
try: value = json.from_string(value)
|
||||
except: pass
|
||||
|
||||
# Done here:
|
||||
return value
|
||||
|
||||
@field_validator("to", "cc", "bcc", mode = "before")
|
||||
def parse_recipients(cls, value):
|
||||
|
||||
# If we get a null value or an empty string:
|
||||
if value is None: return []
|
||||
if isinstance(value, str):
|
||||
if not value.strip(): return []
|
||||
|
||||
# If we get a properly populated string:
|
||||
try: value = json.from_string(value)
|
||||
except: value = [value.strip()]
|
||||
|
||||
# Done here:
|
||||
return value
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
|
||||
Reference in New Issue
Block a user