From cd57a57854af302839370e41aa2c6c57bc1513fa Mon Sep 17 00:00:00 2001 From: Alzpetka Date: Fri, 20 Sep 2024 10:23:34 +0200 Subject: [PATCH] can possibly create --- oarepo_doi/api.py | 16 ++++++++-------- oarepo_doi/types/doi.py | 9 +++++++++ setup.cfg | 2 +- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/oarepo_doi/api.py b/oarepo_doi/api.py index 4d6a5fa..ef90196 100644 --- a/oarepo_doi/api.py +++ b/oarepo_doi/api.py @@ -56,16 +56,16 @@ def edit_doi(service, record, event=None): """edit existing draft""" mapping = obj_or_import_string(service.mapping[record.schema])() - errors = mapping.metadata_check(record) - record_service = get_record_service_for_record(record) - record["links"] = record_service.links_item_tpl.expand(system_identity, record) - if len(errors) > 0 and event: - raise ValidationError( - message=f"Could not assigned doi due to validation error: {errors} " - ) - doi_value = mapping.get_doi(record) + if doi_value: + errors = mapping.metadata_check(record) + record_service = get_record_service_for_record(record) + record["links"] = record_service.links_item_tpl.expand(system_identity, record) + if len(errors) > 0 and event: + raise ValidationError( + message=f"Could not assigned doi due to validation error: {errors} " + ) if not service.url.endswith("/"): url = service.url + "/" else: diff --git a/oarepo_doi/types/doi.py b/oarepo_doi/types/doi.py index 23a4a30..f3ea1e9 100644 --- a/oarepo_doi/types/doi.py +++ b/oarepo_doi/types/doi.py @@ -33,3 +33,12 @@ def can_create(self, identity, data, receiver, topic, creator, *args, **kwargs): message=f"Could not assigned doi due to validation error: {errors} " ) super().can_create(identity, data, receiver, topic, creator, *args, **kwargs) + + def can_possibly_create(self, identity, record , *args, **kwargs): + mapping_file = current_app.config.get("DATACITE_MAPPING") + mapping = obj_or_import_string(mapping_file[record.schema])() + doi_value = mapping.get_doi(record) + if doi_value: + return False + else: + return super().can_possibly_create(identity, record, *args, **kwargs) diff --git a/setup.cfg b/setup.cfg index ad30785..86a89ec 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = oarepo-doi -version = 1.0.8 +version = 1.0.9 description = authors = Alzbeta Pokorna readme = README.md