Added new route, methods, and models for data_store. Also minor code clean up and less debug.
This commit is contained in:
@@ -31,6 +31,7 @@ base_fields['archive_content_id_random'] = xxx_id_random_field_schema
|
||||
base_fields['contact_id_random'] = xxx_id_random_field_schema
|
||||
base_fields['cont_edu_cert_id_random'] = xxx_id_random_field_schema
|
||||
base_fields['cont_edu_cert_person_id_random'] = xxx_id_random_field_schema
|
||||
base_fields['data_store_id_random'] = xxx_id_random_field_schema
|
||||
base_fields['event_exhibit_id_random'] = xxx_id_random_field_schema
|
||||
base_fields['event_exhibit_tracking_id_random'] = xxx_id_random_field_schema
|
||||
base_fields['event_file_id_random'] = xxx_id_random_field_schema
|
||||
|
||||
121
app/models/data_store_models.py
Normal file
121
app/models/data_store_models.py
Normal file
@@ -0,0 +1,121 @@
|
||||
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 log, logging
|
||||
|
||||
from app.models.common_field_schema import base_fields, default_num_bytes
|
||||
|
||||
|
||||
# ### BEGIN ### API Data Store Models ### Data_Store_Base() ###
|
||||
class Data_Store_Base(BaseModel):
|
||||
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
id_random: Optional[str] = Field(
|
||||
**base_fields['data_store_id_random'],
|
||||
alias = 'data_store_id_random',
|
||||
default_factory = lambda:secrets.token_urlsafe(default_num_bytes),
|
||||
)
|
||||
id: Optional[int] = Field(
|
||||
alias = 'data_store_id'
|
||||
)
|
||||
|
||||
account_id_random: Optional[str]
|
||||
account_id: Optional[int]
|
||||
|
||||
for_type: Optional[str]
|
||||
for_id_random: Optional[str]
|
||||
for_id: Optional[int]
|
||||
|
||||
person_id_random: Optional[str]
|
||||
person_id: Optional[int]
|
||||
|
||||
user_id_random: Optional[str]
|
||||
user_id: Optional[int]
|
||||
|
||||
code: Optional[str]
|
||||
|
||||
name: Optional[str]
|
||||
description: Optional[str]
|
||||
|
||||
# json: Optional[str] # "json" is reserved; need to change field name? json_str?
|
||||
text: Optional[str]
|
||||
meta_json: Optional[str]
|
||||
meta_text: Optional[str]
|
||||
|
||||
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 convenience data
|
||||
# This is only for convenience. Probably going to keep unless it causes a problem.
|
||||
|
||||
# Including JSON data
|
||||
# other_json: Optional[Json]
|
||||
# meta_json: Optional[Json]
|
||||
|
||||
# Including other related objects
|
||||
|
||||
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
||||
|
||||
#@validator('data_store_id_random', always=True)
|
||||
def data_store_id_random_copy(cls, v, values, **kwargs):
|
||||
if values['id_random']:
|
||||
return values['id_random']
|
||||
return None
|
||||
|
||||
@validator('id', always=True)
|
||||
def data_store_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='data_store')
|
||||
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('for_id', always=True)
|
||||
def for_id_lookup(cls, v, values, **kwargs):
|
||||
log.setLevel(logging.WARNING)
|
||||
log.debug(locals())
|
||||
if isinstance(v, int) and v > 0: return v
|
||||
elif values.get('for_id_random') and values.get('for_type'):
|
||||
for_id_random = values.get('for_id_random')
|
||||
for_type = values.get('for_type')
|
||||
return redis_lookup_id_random(record_id_random=for_id_random, table_name=for_type)
|
||||
return None
|
||||
|
||||
@validator('person_id', always=True)
|
||||
def person_id_lookup(cls, v, values, **kwargs):
|
||||
if isinstance(v, int) and v > 0: return v
|
||||
elif id_random := values.get('person_id_random'):
|
||||
return redis_lookup_id_random(record_id_random=id_random, table_name='person')
|
||||
return None
|
||||
|
||||
@validator('user_id', always=True)
|
||||
def user_id_lookup(cls, v, values, **kwargs):
|
||||
if isinstance(v, int) and v > 0: return v
|
||||
elif id_random := values.get('user_id_random'):
|
||||
return redis_lookup_id_random(record_id_random=id_random, table_name='user')
|
||||
return None
|
||||
|
||||
class Config:
|
||||
underscore_attrs_are_private = True
|
||||
allow_population_by_field_name = True
|
||||
fields = base_fields
|
||||
# ### END ### API Data Store Models ### Data_Store_Base() ###
|
||||
@@ -23,6 +23,7 @@ class Event_Device_Base(BaseModel):
|
||||
id: Optional[int] = Field(
|
||||
alias = 'event_device_id'
|
||||
)
|
||||
|
||||
account_id_random: Optional[str]
|
||||
account_id: Optional[int]
|
||||
|
||||
@@ -79,9 +80,6 @@ class Event_Device_Base(BaseModel):
|
||||
|
||||
@validator('id', always=True)
|
||||
def event_device_id_lookup(cls, v, values, **kwargs):
|
||||
log.setLevel(logging.WARNING)
|
||||
log.debug(locals())
|
||||
|
||||
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='event_device')
|
||||
@@ -89,9 +87,6 @@ class Event_Device_Base(BaseModel):
|
||||
|
||||
@validator('account_id', always=True)
|
||||
def account_id_lookup(cls, v, values, **kwargs):
|
||||
log.setLevel(logging.WARNING)
|
||||
log.debug(locals())
|
||||
|
||||
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')
|
||||
@@ -99,9 +94,6 @@ class Event_Device_Base(BaseModel):
|
||||
|
||||
@validator('event_id', always=True)
|
||||
def event_id_lookup(cls, v, values, **kwargs):
|
||||
log.setLevel(logging.WARNING)
|
||||
log.debug(locals())
|
||||
|
||||
if isinstance(v, int) and v > 0: return v
|
||||
elif id_random := values.get('event_id_random'):
|
||||
return redis_lookup_id_random(record_id_random=id_random, table_name='event')
|
||||
@@ -109,9 +101,6 @@ class Event_Device_Base(BaseModel):
|
||||
|
||||
@validator('event_location_id', always=True)
|
||||
def event_location_id_lookup(cls, v, values, **kwargs):
|
||||
log.setLevel(logging.WARNING)
|
||||
log.debug(locals())
|
||||
|
||||
if isinstance(v, int) and v > 0: return v
|
||||
elif id_random := values.get('event_location_id_random'):
|
||||
return redis_lookup_id_random(record_id_random=id_random, table_name='event_location')
|
||||
|
||||
Reference in New Issue
Block a user