diff --git a/scipost_django/preprints/models.py b/scipost_django/preprints/models.py index 9bafbc8db4bebd2effa42d023d39c5e3b760ddc0..eac6e3c27b767c5e7677160a5d94056083463f23 100644 --- a/scipost_django/preprints/models.py +++ b/scipost_django/preprints/models.py @@ -2,11 +2,15 @@ __copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)" __license__ = "AGPL v3" +import requests + from django.contrib.sites.models import Site from django.urls import reverse from django.db import models from django.http import Http404 +from submissions.exceptions import PreprintDocumentNotFoundError + class Preprint(models.Model): """ @@ -43,6 +47,18 @@ class Preprint(models.Model): return reverse('preprints:pdf', args=(self.identifier_w_vn_nr,)) raise Http404 + def get_document(self): + """ + Retrieve the preprint document itself, calling preprint server if necessary. + """ + url = self.get_absolute_url() + if url[0] == '/': # SciPost-hosted, add base url + url = 'https://%s%s' % (Site.objects.get_current().domain, url) + response = requests.get(url) + if response.status_code != 200: + raise PreprintDocumentNotFoundError(self.get_absolute_url()) + return response.content + @property def citation_pdf_url(self): """Return the absolute URL of the pdf for the meta tag for Google Scholar.""" diff --git a/scipost_django/submissions/exceptions.py b/scipost_django/submissions/exceptions.py index 1349a3c6769337ec18faf21e9700793538cc6f17..3c2a868570e86c6cac1b136e98b16d61d54dfab0 100644 --- a/scipost_django/submissions/exceptions.py +++ b/scipost_django/submissions/exceptions.py @@ -18,6 +18,10 @@ class InvalidReportVettingValue(BaseCustomException): pass +class PreprintDocumentNotFoundError(BaseCustomException): + pass + + class ArxivPDFNotFound(Exception): pass diff --git a/scipost_django/submissions/forms.py b/scipost_django/submissions/forms.py index 297e9467d4c622654d5dea08d44a0b72147d8e52..1ec03c1cebd68bef581a15a6871182a19e660417 100644 --- a/scipost_django/submissions/forms.py +++ b/scipost_django/submissions/forms.py @@ -1919,12 +1919,13 @@ class iThenticateReportForm(forms.ModelForm): doc_id = self.instance.doc_id if not doc_id and not self.fields.get('file'): try: - cleaned_data['document'] = helpers.retrieve_pdf_from_arxiv( - self.submission.preprint.identifier_w_vn_nr) - except exceptions.ArxivPDFNotFound: + # cleaned_data['document'] = helpers.retrieve_pdf_from_arxiv( + # self.submission.preprint.identifier_w_vn_nr) + cleaned_data['document'] = self.submission.preprint.get_document() + except exceptions.PreprintDocumentNotFoundError: self.add_error( - None, 'The pdf could not be found at arXiv. Please upload the pdf manually.') - self.fields['file'] = forms.FileField() + None, 'Preprint document not found. Please upload the pdf manually.') + self.fields['file'] = forms.FileField() # Add this field now it's needed elif not doc_id and cleaned_data.get('file'): cleaned_data['document'] = cleaned_data['file'].read() elif doc_id: @@ -1944,12 +1945,12 @@ class iThenticateReportForm(forms.ModelForm): except AttributeError: if not self.fields.get('file'): # The document is invalid. - self.add_error(None, ('A valid pdf could not be found at arXiv.' + self.add_error(None, ('A valid pdf could not be found.' ' Please upload the pdf manually.')) + self.fields['file'] = forms.FileField() else: self.add_error(None, ('The uploaded file is not valid.' ' Please upload a valid pdf.')) - self.fields['file'] = forms.FileField() elif hasattr(self, 'document_id'): self.response = self.call_ithenticate() diff --git a/scipost_django/submissions/templates/submissions/_submission_refereeing_history.html b/scipost_django/submissions/templates/submissions/_submission_refereeing_history.html index 53ca47102e863a606339785c34afcc8fdd81c06b..a5f9b4afebfd6ee9a5d32ac92f6890a6924b462b 100644 --- a/scipost_django/submissions/templates/submissions/_submission_refereeing_history.html +++ b/scipost_django/submissions/templates/submissions/_submission_refereeing_history.html @@ -7,7 +7,7 @@ <small class="text-muted">Thread {{ submission.thread_hash }} <br/>(all emails concerning this stream contain this uuid)</small> {% endif %} - {% if perms.scipost.can_oversee_refereeing or request.user|is_in_submission_fellowship:submission %} + {% if perms.scipost.can_oversee_refereeing or request.user|is_in_submission_fellowship:submission %} {% for sibling in submission.thread_full %} <div class="p-2{% if sibling.preprint.identifier_w_vn_nr in request.path %} border border-secondary{% endif %}"> {% include 'submissions/_submission_refereeing_history_entry.html' with sibling=sibling %}