def on_preprint_updated(preprint_id): # WARNING: Only perform Read-Only operations in an asynchronous task, until Repeatable Read/Serializable # transactions are implemented in View and Task application layers. from website.models import PreprintService preprint = PreprintService.load(preprint_id) if settings.SHARE_URL: if not preprint.provider.access_token: raise ValueError( 'No access_token for {}. Unable to send {} to SHARE.'.format( preprint.provider, preprint)) resp = requests.post( '{}api/v2/normalizeddata/'.format(settings.SHARE_URL), json={ 'data': { 'type': 'NormalizedData', 'attributes': { 'tasks': [], 'raw': None, 'data': { '@graph': format_preprint(preprint) } } } }, headers={ 'Authorization': 'Bearer {}'.format(preprint.provider.access_token), 'Content-Type': 'application/vnd.api+json' }) logger.debug(resp.content) resp.raise_for_status()
def on_preprint_updated(preprint_id): # WARNING: Only perform Read-Only operations in an asynchronous task, until Repeatable Read/Serializable # transactions are implemented in View and Task application layers. from website.models import PreprintService preprint = PreprintService.load(preprint_id) if settings.SHARE_URL and settings.SHARE_API_TOKEN: resp = requests.post('{}api/v2/normalizeddata/'.format(settings.SHARE_URL), json={ 'created_at': datetime.datetime.utcnow().isoformat(), 'normalized_data': { '@graph': format_preprint(preprint) }, }, headers={'Authorization': 'Bearer {}'.format(settings.SHARE_API_TOKEN)}) logger.debug(resp.content) resp.raise_for_status()
def on_preprint_updated(preprint_id): # WARNING: Only perform Read-Only operations in an asynchronous task, until Repeatable Read/Serializable # transactions are implemented in View and Task application layers. from website.models import PreprintService preprint = PreprintService.load(preprint_id) if settings.SHARE_URL: if not preprint.provider.access_token: raise ValueError('No access_token for {}. Unable to send {} to SHARE.'.format(preprint.provider, preprint)) resp = requests.post('{}api/v2/normalizeddata/'.format(settings.SHARE_URL), json={ 'data': { 'type': 'NormalizedData', 'attributes': { 'tasks': [], 'raw': None, 'data': {'@graph': format_preprint(preprint)} } } }, headers={'Authorization': 'Bearer {}'.format(preprint.provider.access_token), 'Content-Type': 'application/vnd.api+json'}) logger.debug(resp.content) resp.raise_for_status()
def on_preprint_updated(preprint_id): # WARNING: Only perform Read-Only operations in an asynchronous task, until Repeatable Read/Serializable # transactions are implemented in View and Task application layers. from website.models import PreprintService preprint = PreprintService.load(preprint_id) if settings.SHARE_URL and settings.SHARE_API_TOKEN: resp = requests.post('{}api/v2/normalizeddata/'.format( settings.SHARE_URL), json={ 'created_at': datetime.datetime.utcnow().isoformat(), 'normalized_data': { '@graph': format_preprint(preprint) }, }, headers={ 'Authorization': 'Bearer {}'.format(settings.SHARE_API_TOKEN) }) logger.debug(resp.content) resp.raise_for_status()