Files
OSIT-AE-API-FastAPI/app/models/sponsorship_models.py
2024-03-01 15:38:28 -05:00

136 lines
6.6 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
# from app.models.sponsorship_cfg_models import Sponsorship_Cfg_Base
# ### BEGIN ### API Sponsorship Models ### Sponsorship_Base() ###
class Sponsorship_Base(BaseModel):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
id_random: Optional[str] = Field(
**base_fields['sponsorship_id_random'],
alias = 'sponsorship_id_random',
)
id: Optional[int] = Field(
alias = 'sponsorship_id'
)
account_id_random: Optional[str]
account_id: Optional[int]
sponsorship_cfg_id_random: Optional[str]
sponsorship_cfg_id: Optional[int]
name: Optional[str]
description: Optional[str]
# This should be required for the confirmation email to be sent to the sponsor. The person's name and email address in the "To" address line.
poc_email_name: Optional[str]
poc_email: Optional[str]
# Store this here and under social_li_json. However, website_url should be the primary source for the website URL.
website_url: Optional[str]
# For the sponsoring organization, person, and point of contact in a JSON object format. The Aether standard field names should be used. Examples: name, given_name, family_name, full_name, full_name_override, email, phone, address_line_1, city, state_province, postal_code, country, etc.
# Example poc_json: {"given_name": "John", "family_name": "Doe", "full_name": "John Doe", "full_name_override": "John Doe", "email": "john.doe@example.com"}
organization_json: Optional[Union[Json, None]]
person_json: Optional[Union[Json, None]]
poc_json: Optional[Union[Json, None]]
# For the address in a JSON object format. The address types are expected to be: mailing, billing, home, work, etc. The Aether standard field names should be used. Examples: address_line_1, address_line_2, city, state_province, postal_code, country, etc.
address_li_json: Optional[Union[Json, None]]
# For additional contacts in a JSON object list (array) format. A contact person should contain: given_name, family_name, full_name, email, phone, etc.
contact_li_json: Optional[Union[Json, None]]
# For the logo and image in a JSON object format. The Aether standard field names should be used. Examples: url, url_text, alt_text, width, height, etc.
logo_li_json: Optional[Union[Json, None]]
# For media that have different predefined purposes in a JSON object list format. The Aether standard field names should be used. Examples: purpose, (file) type, (file) extension, (file) name, url, url_text, alt_text, width, height, size (in bytes), etc.
media_li_json: Optional[Union[Json, None]]
# For simple question answers in a JSON object list format. A question should contain: id, code, name, desc, note, answer, etc.
questions_li_json: Optional[Union[Json, None]]
# For social media in a JSON object format. The Aether standard field names should be used. Examples: url, url_text, icon, etc.
social_li_json: Optional[Union[Json, None]]
# For a (simple and short) guest list in a JSON object list (array) format. A guest person should contain: given_name, family_name, full_name, title, affiliations, email, phone, assistance, dietry, etc.
# Example: [{"given_name": "John", "family_name": "Doe", "full_name": "John Doe", "email": "john.doe@example.com"}, {"given_name": "Jane", "family_name": "Doe", "full_name": "Jane Doe", "email": "jane.doe@example.com"}]
# Example 2: [{"full_name": "Albert Einstein", "email": "albert.einstein@example.com"}, {"full_name": "Marie Curie", "email": "marie.curie@example.com"}]
guest_li_json: Optional[Union[Json, None]]
level_num: Optional[int]
level_str: Optional[str]
# For their selected sponsorship level in a JSON object format. A level option should contain: num, code, name, desc. Example: {"num": 1, "code": "platinum", "name": "Platinum", "desc": "Platinum Sponsorship"}
slct_level_json: Optional[Union[Json, None]]
# For their selected options in a JSON object list format. An option should contain: id, code, name, desc, note. Example: {"id": 1, "code": "option_1", "name": "Option 1", "desc": "Option 1 Description", "note": "Option 1 Note"}
slct_option_li_json: Optional[Union[Json, None]]
# Amount as an integer in cents. Example: 1000 = $10.00
amount: Optional[int]
paid: Optional[bool]
access_key: Optional[str] # This is for a unique access key or passcode to be used for a sponsorship page edit access.
# General catchall for agreement or consent
agree: Optional[bool]
# Comments from the sponsor. Assumed to be the POC. This is for internal use only.
comments: Optional[str]
cfg_json: Optional[Union[Json, None]]
meta_data: Optional[str]
# The standard fields:
enable: Optional[bool]
hide: Optional[bool]
priority: Optional[bool]
sort: Optional[int]
group: Optional[str]
notes: Optional[str]
created_on: Optional[datetime.datetime] = None
updated_on: Optional[datetime.datetime] = None
# Including other related objects
# example_cfg: Optional[Example_Cfg_Base]
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
@validator('id', always=True)
def account_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='account_cfg')
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
@validator('sponsorship_cfg_id', always=True)
def sponsorship_cfg_id_lookup(cls, v, values, **kwargs):
if isinstance(v, int) and v > 0: return v
elif id_random := values.get('sponsorship_cfg_id_random'):
return redis_lookup_id_random(record_id_random=id_random, table_name='sponsorship_cfg')
return None
class Config:
underscore_attrs_are_private = True
allow_population_by_field_name = True
fields = base_fields
# ### END ### API Sponsorship Models ### Sponsorship_Base() ###