Working on the basic SQL select API CRUD and lots of models
This commit is contained in:
116
app/models/account_cfg_model.py
Normal file
116
app/models/account_cfg_model.py
Normal file
@@ -0,0 +1,116 @@
|
||||
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 ..lib_general import *
|
||||
from ..log import *
|
||||
|
||||
from .common_field_schema import base_fields, default_num_bytes
|
||||
|
||||
|
||||
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]
|
||||
|
||||
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
|
||||
|
||||
_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.WARNING)
|
||||
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
|
||||
fields = base_fields
|
||||
|
||||
Account_Cfg_Base.update_forward_refs()
|
||||
Reference in New Issue
Block a user