def send_crossref_deposit(test_mode, identifier): # todo: work out whether this is acceptance or publication # if it's acceptance, then we use "0" for volume and issue # if publication, then use real values # the code here is for acceptance from utils import setting_handler article = identifier.article error = False template = 'common/identifiers/crossref.xml' template_context = create_crossref_template(identifier) crossref_template = render_to_string(template, template_context) logger.debug(crossref_template) util_models.LogEntry.add_entry('Submission', "Sending request: {0}".format(crossref_template), 'Info', target=identifier.article) doi_prefix = setting_handler.get_setting('Identifiers', 'crossref_prefix', article.journal) username = setting_handler.get_setting('Identifiers', 'crossref_username', identifier.article.journal).processed_value password = setting_handler.get_setting('Identifiers', 'crossref_password', identifier.article.journal).processed_value filename = uuid4() depositor = Depositor(prefix=doi_prefix, api_user=username, api_key=password, use_test_server=test_mode) response = depositor.register_doi(submission_id=filename, request_xml=crossref_template) logger.debug("[CROSSREF:DEPOSIT:{0}] Sending".format(identifier.article.id)) logger.debug("[CROSSREF:DEPOSIT:%s] Response code %s" % (identifier.article.id, response.status_code)) if response.status_code != 200: util_models.LogEntry.add_entry('Error', "Error depositing: {0}. {1}".format(response.status_code, response.text), 'Debug', target=identifier.article) status = "Error depositing: {code}, {text}".format( code=response.status_code, text=response.text ) logger.error(status) error = True else: status = "Deposited DOI" util_models.LogEntry.add_entry('Submission', status, 'Info', target=identifier.article) logger.info(status) crd = models.CrossrefDeposit(identifier=identifier, file_name=filename) crd.save() crd.poll() return status, error
def register_crossref_component(article, xml, supp_file): from utils import setting_handler use_crossref = setting_handler.get_setting('Identifiers', 'use_crossref', article.journal).processed_value if not use_crossref: logger.info("[DOI] Not using Crossref DOIs on this journal. Aborting registration.") return test_mode = setting_handler.get_setting( 'Identifiers', 'crossref_test', article.journal ).processed_value or settings.DEBUG if test_mode: util_models.LogEntry.add_entry('Submission', "DOI component registration running in test mode", 'Info', target=article) else: util_models.LogEntry.add_entry('Submission', "DOI component registration running in live mode", 'Info', target=article) doi_prefix = setting_handler.get_setting('Identifiers', 'crossref_prefix', article.journal) username = setting_handler.get_setting('Identifiers', 'crossref_username', article.journal).processed_value password = setting_handler.get_setting('Identifiers', 'crossref_password', article.journal).processed_value depositor = Depositor(prefix=doi_prefix, api_user=username, api_key=password, use_test_server=test_mode) response = depositor.register_doi(submission_id='component{0}.xml'.format(uuid4()), request_xml=xml) logger.debug("[CROSSREF:DEPOSIT:{0}] Sending".format(article.id)) logger.debug("[CROSSREF:DEPOSIT:%s] Response code %s" % (article.id, response.status_code)) if response.status_code != 200: util_models.LogEntry.add_entry('Error', "Error depositing: {0}. {1}".format(response.status_code, response.text), 'Debug', target=article) status = "Error depositing: {code}, {text}".format( code=response.status_code, text=response.text ) logger.error(status) logger.error(response.text) error = True else: util_models.LogEntry.add_entry('Submission', "Deposited DOI.", 'Info', target=article)
def check_status_by_doi_batch_id(doi_batch_id, prefix, username, password, use_test_server=False, data_type="result"): """Get the status of a submission by DOI batch ID. Parameters ---------- doi_batch_id : str or int Batch ID for the registration submission you wish to check on. prefix : str Your organization's DOI prefix. username : str Crossref username. password : str Crossref password. use_test_server : bool If True submit to the test server instead of actually attempting to register DOIs. Defaults to False. data_type : str The data type you want in response. "result" will return the status of your submission. "content" will return the XML submitted. Defaults to "result". Returns ------- requests.Response """ etiquette = Etiquette(__name__, __version__, __author__, __email__) depositor = Depositor(prefix, username, password, etiquette, use_test_server) response = depositor.request_doi_status_by_batch_id( doi_batch_id, data_type) return response
def submit_xml(doi_batch_id, xml, prefix, username, password, use_test_server=False): """Register DOIs with Crossref. Submit XML to the Crossref API to register DOIs. Parameters ---------- doi_batch_id : str or int Batch ID for the registration submission. xml : str XML file to submit to Crossref API. prefix : str Your organization's DOI prefix. username : str Crossref username. password : str Crossref password. use_test_server : bool If True submit to the test server instead of actually attempting to register DOIs. Defaults to False. Returns ------- requests.Response """ etiquette = Etiquette(__name__, __version__, __author__, __email__) depositor = Depositor(prefix, username, password, etiquette, use_test_server) response = depositor.register_doi(doi_batch_id, xml) return response