From d386ea5e3f4edd6391938e84fb856184d0178dd9 Mon Sep 17 00:00:00 2001
From: "J.-S. Caux" <J.S.Caux@uva.nl>
Date: Thu, 8 Mar 2018 06:14:36 +0100
Subject: [PATCH] Add feed of doi to arXiv

---
 journals/views.py | 26 ++++++++++++++++++++++++++
 scipost/urls.py   |  1 +
 2 files changed, 27 insertions(+)

diff --git a/journals/views.py b/journals/views.py
index 432e6dc16..920a6da3e 100644
--- a/journals/views.py
+++ b/journals/views.py
@@ -1315,3 +1315,29 @@ def publication_detail_pdf(request, doi_label):
     response['Content-Disposition'] = ('filename='
                                        + publication.doi_label.replace('.', '_') + '.pdf')
     return response
+
+
+######################
+# Feed DOIs to arXiv #
+######################
+
+"""
+This method provides arXiv with the doi and journal ref of the 100 most recent
+publications in the journal specified by doi_label.
+"""
+def arxiv_doi_feed(request, doi_label):
+    journal = get_object_or_404(Journal, doi_label=doi_label)
+    feedxml = ('<preprint xmlns="http://arxiv.org/doi_feed" '
+               'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
+               'identifier="SciPost.org arXiv.org DOI feed" '
+               'version="DOI SnappyFeed v1.0" '
+               'xsi:schemaLocation="http://arxiv.org/doi_feed '
+               'http://arxiv.org/schemas/doi_feed.xsd">')
+    publications = Publication.objects.filter(
+        in_issue__in_volume__in_journal=journal).order_by('-publication_date')[:100]
+    for publication in publications:
+        feedxml += ('\n<article preprint_id="%s" doi="%s" journal_ref="%s" />' % (
+            publication.arxiv_identifer_wo_vn_nr, publication.doi_string,
+            publication.citation()))
+    feedxml += '\n</preprint>'
+    return HttpResponse(feedxml, content_type='text/xml')
diff --git a/scipost/urls.py b/scipost/urls.py
index 9da0a19f2..b1bb8f2df 100644
--- a/scipost/urls.py
+++ b/scipost/urls.py
@@ -207,6 +207,7 @@ urlpatterns = [
     # Journal landing page
     url(r'^10.21468/%s' % JOURNAL_REGEX, journals_views.landing_page, name='landing_page'),
     url(r'^%s' % JOURNAL_REGEX, journals_views.landing_page, name='landing_page'),
+    url(r'^arxiv_doi_feed/%s' % JOURNAL_REGEX, journals_views.arxiv_doi_feed, name='arxiv_doi_feed'),
 
     ################
     # Howto guides #
-- 
GitLab