class CommonFieldsMixin: """Common system fields between records and drafts.""" versions_model_cls = models.RDMVersionsState parent_record_cls = RDMParent schema = ConstantField( '$schema', 'local://records/record-v2.0.0.json') dumper = ElasticsearchDumper( extensions=[ EDTFDumperExt('metadata.publication_date'), EDTFListDumperExt("metadata.dates", "date"), RelationDumperExt('relations'), ] ) relations = RelationsField( languages=PIDListRelation( 'metadata.languages', attrs=['id', 'title'], pid_field=Vocabulary.pid.with_type_ctx('languages') ), ) bucket_id = ModelField(dump=False) bucket = ModelField(dump=False) access = RecordAccessField() is_published = PIDStatusCheckField(status=PIDStatus.REGISTERED, dump=True) pids = DictField("pids")
class LOMDraft(Draft): """For representing entries from the 'lom_drafts_metadata'-SQL-table.""" model_cls = models.LOMDraftMetadata parent_record_cls = LOMParent versions_model_cls = models.LOMVersionsState pid = PIDField( key="id", provider=LOMDraftRecordIdProvider, resolver_cls=LOMResolver, context_cls=LOMPIDFieldContext, # flag for deleting pid from database on post-record-deletion, # delete pid via LOMRecordService instead delete=False, ) files = FilesField( file_cls=LOMFileDraft, delete=False, store=False, ) access = RecordAccessField() bucket_id = ModelField(dump=False) bucket = ModelField(dump=False) index = IndexField("lomrecords-drafts-draft-v1.0.0", search_alias="lomrecords") is_published = PIDStatusCheckField(status=PIDStatus.REGISTERED, dump=True) resource_type = DictField()
class FileRecord(RecordBase, SystemFieldsMixin): """Base class for a record describing a file.""" @classmethod def get_by_key(cls, record_id, key): """Get a record file by record ID and filename/key.""" with db.session.no_autoflush: obj = cls.model_cls.query.filter(cls.record_id == record_id, cls.key == key).one_or_none() if obj: return cls(obj.data, model=obj) @classmethod def list_by_record(cls, record_id): """List all record files by record ID.""" for obj in cls.model_cls.query.filter( cls.model_cls.record_id == record_id): yield cls(obj.data, model=obj) @property def file(self): """File wrapper object.""" if self.object_version: return File(object_model=self.object_version) @property def record(self): """Get the file's record.""" return self.record_cls(self._record.data, model=self._record) send_signals = False enable_jsonref = False #: Default model class used by the record API (specify in subclass). model_cls = None #: Record API class. record_cls = None #: Default dumper (which happens to also be used for indexing). dumper = ElasticsearchDumper() #: Metadata system field. metadata = DictField(clear_none=True, create_if_missing=True) key = ModelField() object_version_id = ModelField() object_version = ModelField(dump=False) record_id = ModelField() _record = ModelField('record', dump=False) def __repr__(self, ): """Represenation string for the record file.""" return f"<{type(self).__name__}({self.key}, {self.metadata})"
class Record(RecordBase, SystemFieldsMixin): """Base class for record APIs. Subclass this record, and specify as minimum the ``model_cls`` class-level attribute. """ #: Disable signals - we use record extensions instead (more precise). send_signals = False #: Disable JSONRef replacement (due to complexity of configuration). enable_jsonref = False #: Default model class used by the record API (specify in subclass). model_cls = None #: Default dumper (which happens to also be used for indexing). dumper = ElasticsearchDumper() #: Metadata system field. metadata = DictField(clear_none=True, create_if_missing=True)
class CommonFieldsMixin: """Common system fields between records and drafts.""" versions_model_cls = models.RDMVersionsState parent_record_cls = RDMParent schema = ConstantField( '$schema', 'local://records/record-v5.0.0.json') dumper = ElasticsearchDumper( extensions=[ EDTFDumperExt('metadata.publication_date'), EDTFListDumperExt("metadata.dates", "date"), RelationDumperExt('relations'), ] ) relations = RelationsField( creator_affiliations=PIDNestedListRelation( 'metadata.creators', relation_field='affiliations', keys=['name'], pid_field=Affiliation.pid, cache_key='affiliations', ), contributor_affiliations=PIDNestedListRelation( 'metadata.contributors', relation_field='affiliations', keys=['name'], pid_field=Affiliation.pid, cache_key='affiliations', ), languages=PIDListRelation( 'metadata.languages', keys=['title'], pid_field=Vocabulary.pid.with_type_ctx('languages'), cache_key='languages', ), resource_type=PIDRelation( 'metadata.resource_type', keys=['title', 'props.type', 'props.subtype'], pid_field=Vocabulary.pid.with_type_ctx('resourcetypes'), cache_key='resource_type', value_check=dict(tags=['depositable']), ), subjects=PIDListRelation( 'metadata.subjects', keys=['subject', 'scheme'], pid_field=Subject.pid, cache_key='subjects', ), licenses=PIDListRelation( 'metadata.rights', keys=['title', 'description', 'icon', 'props.url', 'props.scheme'], pid_field=Vocabulary.pid.with_type_ctx('licenses'), cache_key='licenses', ), related_identifiers=PIDListRelation( 'metadata.related_identifiers', keys=['title'], pid_field=Vocabulary.pid.with_type_ctx('resourcetypes'), cache_key='resource_type', relation_field='resource_type', value_check=dict(tags=['linkable']), ), title_types=PIDListRelation( 'metadata.additional_titles', keys=['title'], pid_field=Vocabulary.pid.with_type_ctx('titletypes'), cache_key='title_type', relation_field='type', ), title_languages=PIDListRelation( 'metadata.additional_titles', keys=['title'], pid_field=Vocabulary.pid.with_type_ctx('languages'), cache_key='languages', relation_field='lang', ), creators_role=PIDListRelation( 'metadata.creators', keys=['title'], pid_field=Vocabulary.pid.with_type_ctx('creatorsroles'), cache_key='role', relation_field='role' ), contributors_role=PIDListRelation( 'metadata.contributors', keys=['title'], pid_field=Vocabulary.pid.with_type_ctx('contributorsroles'), cache_key='role', relation_field='role' ), description_type=PIDListRelation( 'metadata.additional_descriptions', keys=['title'], pid_field=Vocabulary.pid.with_type_ctx('descriptiontypes'), cache_key='description_type', relation_field='type', ), description_languages=PIDListRelation( 'metadata.additional_descriptions', keys=['title'], pid_field=Vocabulary.pid.with_type_ctx('languages'), cache_key='languages', relation_field='lang', ), date_types=PIDListRelation( 'metadata.dates', keys=['title'], pid_field=Vocabulary.pid.with_type_ctx('datetypes'), cache_key='date_types', relation_field='type', ), relation_types=PIDListRelation( 'metadata.related_identifiers', keys=['title'], pid_field=Vocabulary.pid.with_type_ctx('relationtypes'), cache_key='relation_types', relation_field='relation_type', ), ) bucket_id = ModelField(dump=False) bucket = ModelField(dump=False) access = RecordAccessField() is_published = PIDStatusCheckField(status=PIDStatus.REGISTERED, dump=True) pids = DictField("pids")
class Record1(Record, SystemFieldsMixin): metadata = DictField()
class Record1(Record, SystemFieldsMixin): metadata = DictField('metadata', clear_none=True)
class Record1(Record, SystemFieldsMixin): metadata = DictField('metadata.a.b', create_if_missing=False)
class TestRecord(Record, SystemFieldsMixin): afield = DictField()