From 15e51000256c644b5592c5855f0699f7df7584f7 Mon Sep 17 00:00:00 2001 From: Van Go <35277477+van-go@users.noreply.github.com> Date: Wed, 5 Jun 2024 16:50:15 -0500 Subject: [PATCH] Bug/download citation not working in next (#1285) * commit to main * Add useCitationMetrics hook for fetching citation metrics in publications module * Refactor useCitationMetrics hook and update ProjectPreview module and styles * Add MetricsModal to project modals and update Datacite API endpoints * Refactor useCitationMetrics hook and update ProjectPreview module and styles * Refactor ProjectCitation module and styles, and add DownloadCitation component * Refactor ProjectCitation module and styles, and add DownloadCitation component * chore: Refactor ProjectCitation module, add DOI link to PublishedCitation * Refactor ProjectCitation module, add DOI link to PublishedCitation * chore: Update Docker images and volumes configuration for development environment * Refactor ProjectPreview module, fix useState declaration * Refactor useState declaration in ProjectPreview module * Refactor ProjectCitation module, optimize DOI retrieval and usage * feat: Optimize DOI retrieval and usage in ProjectCitation module * Refactor ProjectCitation module, optimize DOI retrieval and usage * Refactor ProjectCitation module, remove commented out code for MetricsModal * Refactor DOI retrieval and usage in ProjectCitation module * test commit * Update index.ts --- designsafe/apps/api/publications/urls.py | 2 +- designsafe/apps/api/publications/views.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/designsafe/apps/api/publications/urls.py b/designsafe/apps/api/publications/urls.py index 81f6127880..6f3626f822 100644 --- a/designsafe/apps/api/publications/urls.py +++ b/designsafe/apps/api/publications/urls.py @@ -9,7 +9,7 @@ # # GET /listing//// url(r'^data-cite/events$', PublicationDataCiteEventsView.as_view(), name='publication_datacite_usage'), - url(r'^data-cite/(?P[ \S]*)$', PublicationDataCiteView.as_view(), name='publication_datacite'), + url(r'^data-cite/(?P\S+)$', PublicationDataCiteView.as_view(), name='publication_datacite'), url(r'^(?P[\w.-]+)/$', PublicationListingView.as_view(), name='publication_listing'), url(r'^(?P[\w.-]+)/(?P[A-Z\-]+-[0-9]+)(v(?P[0-9]+))?/$', PublicationDetailView.as_view(), name='publication_detail'), url(r'^(?P[\w.-]+)/(?P[\w.-]+)/$', PublicationDetailView.as_view(), name='legacy-publication_detail') diff --git a/designsafe/apps/api/publications/views.py b/designsafe/apps/api/publications/views.py index f31c6fab4d..af5d640022 100644 --- a/designsafe/apps/api/publications/views.py +++ b/designsafe/apps/api/publications/views.py @@ -43,11 +43,16 @@ def get(self, request, operation, project_id, revision=None): """ class PublicationDataCiteView(BaseApiView): def get(self, request, doi): + url = f'https://api.datacite.org/dois/{doi}' + try: - response = DataciteManager.get_doi(doi) - return JsonResponse(response) + response = requests.get(url) + response.raise_for_status() # Raises an HTTPError for bad responses (4xx and 5xx) + return JsonResponse(response.json()) # Assuming the response is JSON except HTTPError as e: return JsonResponse({'message': str(e)}, status=e.response.status_code) + except Exception as e: + return JsonResponse({'message': str(e)}, status=500) """ View for getting DataCite metrics details from publications.