SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 47b388e8 authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Add 302 redirect to latest vn of submission pdf for Google Scholar

parent 58ec73d6
No related branches found
No related tags found
No related merge requests found
......@@ -6,10 +6,15 @@ from django.conf.urls import url
from . import views
from submissions.constants import SCIPOST_PREPRINT_W_VN_REGEX
from submissions.constants import SUBMISSIONS_NO_VN_REGEX, SUBMISSIONS_COMPLETE_REGEX
app_name = 'preprints'
urlpatterns = [
url(r'^{regex}/$'.format(regex=SCIPOST_PREPRINT_W_VN_REGEX), views.preprint_pdf, name='pdf'),
url(r'^{regex}/$'.format(regex=SUBMISSIONS_NO_VN_REGEX),
views.preprint_latest_pdf,
name='latest_pdf'),
url(r'^{regex}/$'.format(regex=SUBMISSIONS_COMPLETE_REGEX),
views.preprint_pdf,
name='pdf'),
]
......@@ -5,6 +5,7 @@ import os
from django.http import Http404, HttpResponse
from django.shortcuts import get_object_or_404, redirect
from django.urls import reverse
from submissions.helpers import check_verified_author
from submissions.models import Submission
......@@ -39,3 +40,12 @@ def preprint_pdf(request, identifier_w_vn_nr):
filename = '{}{}'.format(preprint.identifier_w_vn_nr, extension)
response['Content-Disposition'] = ('filename=' + filename)
return response
def preprint_latest_pdf(request, identifier_wo_vn_nr):
submission = Submission.objects.filter(
preprint__identifier_wo_vn_nr=identifier_wo_vn_nr).first()
if not submission:
raise Http404
return redirect(reverse('preprints:pdf',
args=[submission.get_latest_version().preprint.identifier_w_vn_nr,]))
......@@ -277,7 +277,6 @@ scipost_regex_wo_vn = 'scipost_[0-9]{4,}_[0-9]{4,}'
scipost_regex_w_vn = 'scipost_[0-9]{4,}_[0-9]{4,}v[0-9]{1,2}'
SUBMISSIONS_NO_VN_REGEX = '(?P<identifier_wo_vn_nr>(%s|%s))' % (arxiv_regex_wo_vn, scipost_regex_wo_vn)
SUBMISSIONS_COMPLETE_REGEX = '(?P<identifier_w_vn_nr>(%s|%s))' % (arxiv_regex_w_vn, scipost_regex_w_vn)
SCIPOST_PREPRINT_W_VN_REGEX = '(?P<identifier_w_vn_nr>%s)' % scipost_regex_w_vn
# `EXPLICIT_REGEX_MANUSCRIPT_CONSTRAINTS` tracks the regex rules for the manuscripts
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment