Files
OSIT-AE-API-FastAPI/app/models/account_cfg_models.py

133 lines
4.2 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 app.db_sql import redis_lookup_id_random
from app.lib_general import *
from app.models.common_field_schema import base_fields, default_num_bytes
from app.models.fundraising_cfg_models import Fundraising_Cfg_Base
from app.models.membership_cfg_models import Membership_Cfg_Base
class Account_Cfg_Base(BaseModel):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
id_random: Optional[str] = Field(
**base_fields['account_cfg_id_random'],
alias = 'account_cfg_id_random',
default_factory = lambda:secrets.token_urlsafe(default_num_bytes),
)
id: Optional[int] = Field(
alias = 'account_cfg_id'
)
account_id_random: Optional[str]
account_id: Optional[int]
account_code: Optional[str]
account_name: Optional[str]
account_short_name: Optional[str]
account_description: Optional[str]
account_enable: Optional[bool]
account_enable_from: Optional[datetime.datetime] = None
account_enable_to: Optional[datetime.datetime] = None
show_user_availability: Optional[bool]
show_person_create: Optional[bool]
person_create_label: Optional[str]
show_person_view: Optional[bool]
person_view_label: Optional[str]
show_person_load: Optional[bool]
person_load_label: Optional[str]
show_cart: Optional[bool]
cart_label: Optional[str]
default_no_reply_email: Optional[str]
default_no_reply_name: Optional[str]
default_reply_to_email: Optional[str]
default_reply_to_name: Optional[str]
confirm_email: Optional[str]
confirm_name: Optional[str]
help_event_email: Optional[str]
help_event_name: Optional[str]
help_general_email: Optional[str]
help_general_name: Optional[str]
help_member_email: Optional[str]
help_member_name: Optional[str]
help_tech_email: Optional[str]
help_tech_name: Optional[str]
order_header: Optional[str]
order_thanks: Optional[str]
order_message: Optional[str]
order_footer: Optional[str]
order_fundraising_thanks: Optional[str]
order_fundraising_message: Optional[str]
fundraising_message: Optional[str]
post_rules: Optional[str]
post_comment_rules: Optional[str]
show_post_title: Optional[bool]
show_post_comment_title: Optional[bool]
hide_posts_after: Optional[int] # Should posts be singular?
delete_posts_after: Optional[int] # Should posts be singular?
stripe_api_key: Optional[str]
stripe_publishable_key: Optional[str]
stripe_account_id: Optional[str]
created_on: Optional[datetime.datetime] = None
updated_on: Optional[datetime.datetime] = None
# Including other related objects
fundraising_cfg: Optional[Fundraising_Cfg_Base] # Priority l2
membership_cfg: Optional[Membership_Cfg_Base] # Priority l2
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
#@validator('account_cfg_id_random', always=True)
def account_cfg_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_cfg_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_cfg')
return None
@validator('account_id', always=True)
def account_id_lookup(cls, v, values, **kwargs):
log.setLevel(logging.DEBUG)
log.debug(locals())
if values['account_id_random']:
return redis_lookup_id_random(record_id_random=values['account_id_random'], table_name='account')
return None
class Config:
underscore_attrs_are_private = True
allow_population_by_field_name = True
fields = base_fields
#Account_Cfg_Base.update_forward_refs()