Files
OSIT-AE-API-FastAPI/app/models/core_object_models.py
2021-11-18 21:20:41 -05:00

117 lines
3.8 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.common_field_schema import base_fields, default_num_bytes
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