ApplicantPortal/app/database/utils.py
2025-03-12 20:43:26 -06:00

57 lines
1.8 KiB
Python

# from mongoengine import fields
# from app.util.schema import load_json_schema
# from . import DocumentBase
#
# def obj_from_schema(schema_file, base_classes=(DocumentBase, )):
# schema = load_json_schema(schema_file)
# type = schema['type']
# title = schema['title']
# required = schema.get('required', [])
# unique = schema.get('unique', [])
#
# obj_fields = {}
#
# def load_properties(obj_schema):
# for name, _schema in obj_schema['properties']:
# _required = name in required
# _unique = name in unique
# _sparse = not _required and _unique
# field_class = _get_field_class(_schema)
#
# # is this a list field?
# if field_class == fields.ListField:
# list_class = _get_field_class(_schema['items'])
# # is this an embedded document field?
# elif field_class == fields.EmbeddedDocumentField:
#
#
# print(schema)
#
#
# def _get_field_class(field_schema):
# _type = field_schema.get('type')
# if _type == 'string':
# str_format = field_schema.get('format', '').lower()
# if str_format == 'date':
# return fields.DateField
# if str_format == 'datetime':
# return fields.DateTimeField
# elif str_format == 'email':
# return fields.EmailField
# elif str_format == 'multiline':
# return fields.MultiLineStringField
# return fields.StringField
#
# elif _type == 'float':
# return fields.FloatField
# elif _type == 'integer':
# return fields.IntField
# elif _type == 'boolean':
# return fields.BooleanField
# elif _type == 'array':
# return fields.ListField
# elif _type == 'object':
# return fields.EmbeddedDocumentField