-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a management command for re-sending datasets to Datacite
- Loading branch information
Atro Himanen
committed
Feb 2, 2023
1 parent
2b449a0
commit 8221d3e
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/metax_api/management/commands/resend_dataset_to_datacite.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import logging | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
from metax_api.models import DataCatalog, CatalogRecord | ||
from metax_api.models.catalog_record import DataciteDOIUpdate | ||
from metax_api.utils import catalog_allows_datacite_update | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = """Resends the given datasets to Datacite""" | ||
|
||
def handle(self, *args, **options): | ||
cr_ids = options["catalog_record_identifiers"].split(",") | ||
crs = CatalogRecord.objects.filter(identifier__in = cr_ids) | ||
|
||
for cr in crs: | ||
if catalog_allows_datacite_update(cr.get_catalog_identifier()): | ||
logger.info(f"Resending Catalog Record: {cr}") | ||
DataciteDOIUpdate(cr, cr.research_dataset["preferred_identifier"], "update").__call__() | ||
|
||
logger.info("All Catalog Records resent to Datacite") | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument("catalog_record_identifiers", type=str, | ||
help="Comma separated list of identifiers of the catalog records which are re-sent to Datacite") |