176 lines
5.5 KiB
Python
176 lines
5.5 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.common_field_schema import base_fields, default_num_bytes
|
|
|
|
class Core_Std_Obj_Base(BaseModel):
|
|
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(locals())
|
|
|
|
id_random: Optional[str] = Field(
|
|
alias = 'obj_id_random', # Not the DB field name
|
|
)
|
|
id: Optional[int] = Field(
|
|
alias = 'obj_id' # Not the DB field name
|
|
)
|
|
|
|
# id: int
|
|
oid: Optional[str] = None
|
|
otype: Optional[str] = None
|
|
|
|
code: Optional[str] = None
|
|
|
|
name: Optional[str] = None
|
|
|
|
# Including JSON data
|
|
data_json: Optional[Json]
|
|
other_json: Optional[Json]
|
|
meta_json: Optional[Json]
|
|
|
|
# For moderation:
|
|
enable: Optional[bool] # Manager override to fully enable/disable
|
|
enable_from: Optional[datetime.datetime] = None
|
|
enable_to: Optional[datetime.datetime] = None
|
|
|
|
status: Optional[int]
|
|
review: Optional[bool] # ready for review or not ready for review
|
|
approve: Optional[bool] # approved or not approved
|
|
ready: Optional[bool]
|
|
archive: Optional[bool]
|
|
|
|
hide: Optional[bool]
|
|
priority: Optional[bool]
|
|
sort: Optional[int]
|
|
group: Optional[str]
|
|
|
|
notes: Optional[str]
|
|
|
|
xyz: 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('oid', always=True)
|
|
def id_random_to_oid(cls, v, values, **kwargs):
|
|
if isinstance(v, str):
|
|
log.info('Got oid value!')
|
|
return v
|
|
elif id_random := values.get('id_random'):
|
|
log.info('Got id_random value!')
|
|
return id_random
|
|
# return redis_lookup_id_random(record_id_random=id_random, table_name=otype)
|
|
return None
|
|
|
|
|
|
class Core_Object_Base(BaseModel):
|
|
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(locals())
|
|
|
|
# The actual database record ID
|
|
id: int # alias this one?
|
|
# id_random: str # alias this one?
|
|
|
|
# This is what used to be id_random
|
|
oid: str # obj_id or object_id or id_random
|
|
|
|
# The object type name
|
|
# Examples: contact, person, user, event, event_file, membership, membership_person
|
|
otype: str # obj_type or object_type or type
|
|
|
|
code: str # Human friendly unique ID per account and object type
|
|
external_id: str # External service/system/client unique ID per account and object type
|
|
import_id: str # In theory this should not be needed. Use to supplement external_id
|
|
|
|
account_oid: Optional[str]
|
|
account_id: Optional[int]
|
|
|
|
user_id: Optional[int] # Owner/Creator user???
|
|
group_id: Optional[int] # Owner/Creator group???
|
|
|
|
# The current record the object is linked to for the data.
|
|
record_id: int
|
|
|
|
# for_type: Optional[str]
|
|
# for_id: Optional[int]
|
|
|
|
# obj_id_random: str # alias this one based on obj_type?
|
|
# obj_id_rand: str # alias this one based on obj_type?
|
|
|
|
# Common information fields
|
|
name: Optional[str]
|
|
summary: Optional[str]
|
|
description: Optional[str]
|
|
|
|
# Including JSON data
|
|
other_json: Optional[Json]
|
|
meta_json: Optional[Json]
|
|
|
|
# For moderation:
|
|
status: Optional[int]
|
|
review: Optional[bool] # ready for review or not ready for review
|
|
approve: Optional[bool] # approved or not approved
|
|
ready: Optional[bool]
|
|
|
|
enable: Optional[bool] # Manager override to fully enable/disable
|
|
enable_from: Optional[datetime.datetime] = None
|
|
enable_to: Optional[datetime.datetime] = None
|
|
|
|
# The user access levels
|
|
# 1 super, 2 manager
|
|
# 3 administrator, 4 support, 5 assistant, 6 trusted
|
|
# 7 verified, 8 provisional
|
|
# 9 authenticated, 10 public (shared)
|
|
# 11 anonymous (not logged in)
|
|
access_level: Optional[int]
|
|
|
|
hide: Optional[bool] # Administrator and others can show/hide. Still accessible, just not shown in lists.
|
|
hide_from: Optional[datetime.datetime] = None
|
|
hide_to: Optional[datetime.datetime] = None
|
|
|
|
public: Optional[bool]
|
|
public_hide: Optional[bool] # Still accessible, just not shown in lists.
|
|
|
|
priority: Optional[bool] # Sorted first
|
|
sort: Optional[int] # Sorted second
|
|
group: Optional[str] # Group
|
|
|
|
notes: Optional[str]
|
|
created_on: Optional[datetime.datetime]
|
|
updated_on: Optional[datetime.datetime]
|
|
versioned_on: Optional[datetime.datetime]
|
|
|
|
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
|
|
|
|
|
class Example_Object_Base(Core_Object_Base): # Based on Core_Object_Base
|
|
title: Optional[str] = None
|
|
description: Optional[str] = None
|
|
password_set_on: Optional[datetime.datetime] = None
|
|
archive_on: Optional[datetime.datetime] = None
|
|
logged_in_on: Optional[datetime.datetime] = None
|
|
last_activity_on: Optional[datetime.datetime] = None
|
|
other_random_fields: dict
|
|
list_of_: Optional[dict] = {}
|
|
|
|
# Create, Read/Get, Update, Delete
|
|
# CRUD or CGUD
|
|
|
|
# def create_object(object_data):
|
|
# return False # True, False, or None or object_data
|
|
|
|
# def get_object(object_id):
|
|
# return object_data # False or None
|
|
|
|
# def update_object(object_id, object_data):
|
|
# return False # True, False, or None or object_data
|
|
|
|
# def delete_object(object_id):
|
|
# return False # True, False, or None or object_data
|