This commit refactors numerous Pydantic models to align with the V3 ID Vision standard, ensuring that primary and foreign key fields are represented as clean string IDs in the API. It also introduces and populates the ClassVar in each model to prevent view-only fields and linked objects from being inadvertently written to the database during PATCH/POST operations. Specifically, this includes: - Adding to exclude view-derived or joined fields such as , , nested objects (e.g., , ), and convenience fields (e.g., ). - Adjusting root validators to correctly map string IDs and strip internal integer IDs for API responses. - Resolving a KeyError by adding to . These changes are crucial for maintaining data integrity and consistency with the V3 API architecture.
107 lines
6.1 KiB
Python
107 lines
6.1 KiB
Python
import copy, datetime, hashlib, pytz, secrets
|
|
|
|
default_num_bytes = 8 # URL safe 8 bytes is 11 characters long and 16 bytes is 22 characters long
|
|
|
|
xxx_id_random_field_schema: dict = {
|
|
'title': 'XXX ID Random',
|
|
'description': 'This is an id_random field for this object.',
|
|
'min_length': 11,
|
|
'max_length': 22,
|
|
'example': secrets.token_urlsafe(8) # random each reloading of app with: secrets.token_urlsafe(8)
|
|
}
|
|
|
|
xxx_id_random_field_schema_default: dict = copy.copy(xxx_id_random_field_schema)
|
|
xxx_id_random_field_schema_default['default_factory'] = lambda:secrets.token_urlsafe(8)
|
|
|
|
created_updated_on_field_schema: dict = {
|
|
'title': 'Created or Updated On',
|
|
'description': 'This is the created or updated on timestamp field for this object. It is filled in by the SQL DB.',
|
|
'example': '2021-12-31T21:10:10'
|
|
}
|
|
|
|
base_fields = {}
|
|
#base_fields['id_random'] = xxx_id_random_field_schema_default
|
|
base_fields['obj_id_random'] = xxx_id_random_field_schema # General or generic object_id_random
|
|
base_fields['account_id_random'] = xxx_id_random_field_schema
|
|
base_fields['account_cfg_id_random'] = xxx_id_random_field_schema
|
|
base_fields['activity_log_id_random'] = xxx_id_random_field_schema
|
|
base_fields['address_id_random'] = xxx_id_random_field_schema
|
|
base_fields['archive_id_random'] = xxx_id_random_field_schema
|
|
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
|
|
base_fields['event_id_random'] = xxx_id_random_field_schema
|
|
base_fields['event_abstract_id_random'] = xxx_id_random_field_schema
|
|
base_fields['event_badge_id_random'] = xxx_id_random_field_schema
|
|
base_fields['event_badge_template_id_random'] = xxx_id_random_field_schema
|
|
base_fields['event_cfg_id_random'] = xxx_id_random_field_schema # Not really ready yet
|
|
base_fields['event_device_id_random'] = xxx_id_random_field_schema
|
|
base_fields['event_location_id_random'] = xxx_id_random_field_schema
|
|
base_fields['event_person_id_random'] = xxx_id_random_field_schema
|
|
base_fields['event_person_detail_id_random'] = xxx_id_random_field_schema
|
|
base_fields['event_person_profile_id_random'] = xxx_id_random_field_schema
|
|
base_fields['event_person_tracking_id_random'] = xxx_id_random_field_schema
|
|
base_fields['event_presentation_id_random'] = xxx_id_random_field_schema
|
|
base_fields['event_presenter_id_random'] = xxx_id_random_field_schema
|
|
base_fields['event_registration_id_random'] = xxx_id_random_field_schema
|
|
base_fields['event_registration_cfg_id_random'] = xxx_id_random_field_schema
|
|
base_fields['event_session_id_random'] = xxx_id_random_field_schema
|
|
base_fields['event_track_id_random'] = xxx_id_random_field_schema
|
|
base_fields['flask_cfg_id_random'] = xxx_id_random_field_schema
|
|
base_fields['fundraising_id_random'] = xxx_id_random_field_schema
|
|
base_fields['fundraising_cfg_id_random'] = xxx_id_random_field_schema
|
|
base_fields['grant_id_random'] = xxx_id_random_field_schema
|
|
base_fields['hosted_file_id_random'] = xxx_id_random_field_schema
|
|
base_fields['journal_id_random'] = xxx_id_random_field_schema
|
|
base_fields['journal_entry_id_random'] = xxx_id_random_field_schema
|
|
base_fields['log_client_viewing_id_random'] = xxx_id_random_field_schema
|
|
# base_fields['membership_id_random'] = xxx_id_random_field_schema # renamed to membership_type
|
|
base_fields['membership_cfg_id_random'] = xxx_id_random_field_schema
|
|
base_fields['membership_group_id_random'] = xxx_id_random_field_schema
|
|
base_fields['membership_person_group_id_random'] = xxx_id_random_field_schema
|
|
base_fields['membership_person_id_random'] = xxx_id_random_field_schema
|
|
base_fields['membership_person_profile_id_random'] = xxx_id_random_field_schema
|
|
base_fields['membership_type_id_random'] = xxx_id_random_field_schema
|
|
base_fields['membership_person_type_id_random'] = xxx_id_random_field_schema
|
|
base_fields['order_cart_id_random'] = xxx_id_random_field_schema
|
|
base_fields['order_cart_line_id_random'] = xxx_id_random_field_schema
|
|
base_fields['order_id_random'] = xxx_id_random_field_schema
|
|
base_fields['order_line_id_random'] = xxx_id_random_field_schema
|
|
base_fields['order_transaction_id_random'] = xxx_id_random_field_schema
|
|
base_fields['organization_id_random'] = xxx_id_random_field_schema
|
|
base_fields['page_id_random'] = xxx_id_random_field_schema
|
|
base_fields['person_id_random'] = xxx_id_random_field_schema
|
|
base_fields['post_id_random'] = xxx_id_random_field_schema
|
|
base_fields['post_comment_id_random'] = xxx_id_random_field_schema
|
|
base_fields['product_id_random'] = xxx_id_random_field_schema
|
|
base_fields['site_id_random'] = xxx_id_random_field_schema
|
|
base_fields['site_domain_id_random'] = xxx_id_random_field_schema
|
|
base_fields['status_id_random'] = xxx_id_random_field_schema
|
|
base_fields['sponsorship_cfg_id_random'] = xxx_id_random_field_schema
|
|
base_fields['sponsorship_id_random'] = xxx_id_random_field_schema
|
|
base_fields['user_id_random'] = xxx_id_random_field_schema
|
|
base_fields['user_role_id_random'] = xxx_id_random_field_schema
|
|
|
|
base_fields['created_on'] = created_updated_on_field_schema
|
|
base_fields['updated_on'] = created_updated_on_field_schema
|
|
|
|
base_fields['obj_type'] = {}
|
|
base_fields['obj_id_random'] = xxx_id_random_field_schema_default
|
|
base_fields['obj_id_rand'] = xxx_id_random_field_schema_default
|
|
base_fields['obj_id'] = {}
|
|
base_fields['obj_name'] = {}
|
|
base_fields['obj_notes'] = {}
|
|
|
|
# base_fields['for_id_random'] = xxx_id_random_field_schema_default # NOTE: This field may need to be set = None in the actual models with this field.
|
|
|
|
#xxx_id_random_field_schema['alias'] = 'order_id_random'
|
|
#base_fields['id_random'] = xxx_id_random_field_schema_default
|
|
#xxx_id_random_field_schema['alias'] = 'user_id_random_x'
|
|
#c = {'alias': 'user_id_random_x'}
|
|
#base_fields['user_id_random'] = combine_dict(xxx_id_random_field_schema, c)
|