def add_identifiers_to_preprints(dry_run=True): from osf.models import PreprintService preprints_without_identifiers = PreprintService.objects.filter(identifiers__isnull=True) logger.info('About to add identifiers to {} preprints.'.format(preprints_without_identifiers.count())) identifiers_added = 0 for preprint in preprints_without_identifiers: logger.info('Saving identifier for preprint {} from source {}'.format(preprint._id, preprint.provider.name)) if not dry_run: ezid_response = request_identifiers_from_ezid(preprint) id_dict = parse_identifiers(ezid_response) preprint.set_identifier_values(doi=id_dict['doi']) preprint.save() doi = preprint.get_identifier('doi') assert preprint._id.upper() in doi.value identifiers_added += 1 logger.info('Created DOI {} for Preprint with guid {} from service {}'.format(doi.value, preprint._id, preprint.provider.name)) time.sleep(1) else: logger.info('Dry run - would have created identifier for preprint {} from service {}'.format(preprint._id, preprint.provider.name)) logger.info('Finished Adding identifiers to {} preprints.'.format(identifiers_added))
def get_and_set_preprint_identifiers(preprint_id): from osf.models import PreprintService preprint = PreprintService.load(preprint_id) ezid_response = request_identifiers_from_ezid(preprint) id_dict = parse_identifiers(ezid_response) preprint.set_identifier_values(doi=id_dict['doi'], ark=id_dict['ark'])
def add_identifiers_to_preprints(dry_run=True): from osf.models import PreprintService preprints_without_identifiers = PreprintService.objects.filter( is_published=True, preprint_doi_created__isnull=True) logger.info('About to add identifiers to {} preprints.'.format( preprints_without_identifiers.count())) identifiers_added = 0 for preprint in preprints_without_identifiers: logger.info('Saving identifier for preprint {} from source {}'.format( preprint._id, preprint.provider.name)) if not dry_run: ezid_response = request_identifiers_from_ezid(preprint) id_dict = parse_identifiers(ezid_response) preprint.set_identifier_values(doi=id_dict['doi']) preprint.save() doi = preprint.get_identifier('doi') assert preprint._id.upper() in doi.value identifiers_added += 1 logger.info( 'Created DOI {} for Preprint with guid {} from service {}'. format(doi.value, preprint._id, preprint.provider.name)) time.sleep(1) else: logger.info( 'Dry run - would have created identifier for preprint {} from service {}' .format(preprint._id, preprint.provider.name)) logger.info('Finished Adding identifiers to {} preprints.'.format( identifiers_added))
def get_and_set_preprint_identifiers(preprint_id): PreprintService = apps.get_model('osf.PreprintService') preprint = PreprintService.load(preprint_id) ezid_response = request_identifiers_from_ezid(preprint) if ezid_response is None: return id_dict = parse_identifiers(ezid_response) preprint.set_identifier_values(doi=id_dict['doi'], ark=id_dict['ark'], save=True)
def get_and_set_preprint_identifiers(preprint_id): PreprintService = apps.get_model('osf.PreprintService') preprint = PreprintService.load(preprint_id) ezid_response = request_identifiers_from_ezid(preprint) if ezid_response is None: return id_dict = parse_identifiers(ezid_response) preprint.set_identifier_values(doi=id_dict['doi'], save=True)
def get_and_set_preprint_identifiers(preprint): ezid_response = request_identifiers_from_ezid(preprint) id_dict = parse_identifiers(ezid_response) preprint.set_identifier_values(doi=id_dict['doi'], ark=id_dict['ark'])
def get_and_set_preprint_identifiers(preprint): ezid_response = request_identifiers_from_ezid(preprint) if ezid_response is None: return id_dict = parse_identifiers(ezid_response) preprint.set_identifier_values(doi=id_dict['doi'], save=True)