diff --git a/commentaries/forms.py b/commentaries/forms.py index 976aa10f2818ecff6f1d74dc2b74cdfc3632b367..d9664a43261d985084eb18f1e33ae0ae78c542f0 100644 --- a/commentaries/forms.py +++ b/commentaries/forms.py @@ -64,6 +64,10 @@ class ArxivQueryForm(forms.Form): return identifier + def request_arxiv_preprint_form_prefill_data(self): + additional_form_data = {'arxiv_identifier': self.cleaned_data['identifier']} + return {**self.arxiv_data, **additional_form_data} + # class IdentifierToQueryForm(forms.Form): # identifier = forms.CharField(widget=forms.TextInput( @@ -98,7 +102,7 @@ class RequestCommentaryForm(forms.ModelForm): class Meta: model = Commentary fields = [ - 'discipline', 'domain', 'subject_area', 'pub_title', 'author_list', 'pub_date', 'pub_DOI', 'pub_abstract' + 'discipline', 'domain', 'subject_area', 'pub_title', 'author_list', 'pub_date', 'pub_abstract' ] placeholders = { 'pub_date': 'Format: YYYY-MM-DD' diff --git a/commentaries/templates/commentaries/request_arxiv_preprint.html b/commentaries/templates/commentaries/request_arxiv_preprint.html index b0737c4825728f29fa8f0f8c4dc6786163131a15..75007dbae7018d0bd3234cf67838066423e3ecbf 100644 --- a/commentaries/templates/commentaries/request_arxiv_preprint.html +++ b/commentaries/templates/commentaries/request_arxiv_preprint.html @@ -15,7 +15,7 @@ </div> <div class="row"> - <form id="requestForm" action="{% url 'commentaries:request_published_article' %}" method="post"> + <form id="requestForm" action="{% url 'commentaries:request_arxiv_preprint' %}" method="post"> {% csrf_token %} {{ form|bootstrap }} <input class="btn btn-primary" type="submit" value="Submit"/> diff --git a/commentaries/views.py b/commentaries/views.py index 1e47459c76975bf7e7b3f3e0b5b4ef0b3cd76672..012ce38a43df6548bb49dd6d2060f36b24790311 100644 --- a/commentaries/views.py +++ b/commentaries/views.py @@ -119,7 +119,8 @@ def prefill_using_arxiv_identifier(request): if request.method == "POST": arxiv_query_form = ArxivQueryForm(request.POST) if arxiv_query_form.is_valid(): - raise NotImplementedError + prefill_data = arxiv_query_form.request_arxiv_preprint_form_prefill_data() + form = RequestArxivPreprintForm(initial=prefill_data) else: form = RequestArxivPreprintForm() diff --git a/scipost/services.py b/scipost/services.py index 495b580d29b8f31d69ed9a57d965662d9208ae2b..70dbcb9c01e1f25a372a4e3ac4d88b93f4c0f3da 100644 --- a/scipost/services.py +++ b/scipost/services.py @@ -3,6 +3,7 @@ import feedparser import requests import re import datetime +import dateutil.parser from django.template import Template, Context from .behaviors import ArxivCallable @@ -90,12 +91,14 @@ class ArxivCaller: author_list = [author['name'] for author in data['authors']] arxiv_link = data['id'] abstract = data['summary'] + pub_date = dateutil.parser.parse(data['published']).date() self.data = { 'pub_title': pub_title, 'author_list': author_list, 'arxiv_link': arxiv_link, 'pub_abstract': abstract, + 'pub_date': pub_date, } def _search_result_present(self, data): diff --git a/scipost/test_services.py b/scipost/test_services.py index 5316c60b058349bd33e5e40a3e52cedd39727e91..08bfbcc5d6586936aa78d4dacbd422c48736b443 100644 --- a/scipost/test_services.py +++ b/scipost/test_services.py @@ -1,3 +1,5 @@ +import datetime + from django.test import TestCase from .services import ArxivCaller, DOICaller @@ -10,15 +12,16 @@ class ArxivCallerTest(TestCase): caller = ArxivCaller('1612.07611v1') self.assertTrue(caller.is_valid) correct_data = { - 'pub_abstract': 'The Berezinskii-Kosterlitz-Thouless (BKT) transitions of the six-state clock\nmodel on the square lattice are investigated by means of the corner-transfer\nmatrix renormalization group method. The classical analogue of the entanglement\nentropy $S( L, T )$ is calculated for $L$ by $L$ square system up to $L = 129$,\nas a function of temperature $T$. The entropy has a peak at $T = T^{*}_{~}( L\n)$, where the temperature depends on both $L$ and boundary conditions. Applying\nthe finite-size scaling to $T^{*}_{~}( L )$ and assuming the presence of BKT\ntransitions, the transition temperature is estimated to be $T_1^{~} = 0.70$ and\n$T_2^{~} = 0.88$. The obtained results agree with previous analyses. It should\nbe noted that no thermodynamic function is used in this study.', 'author_list': ['Roman KrÄmár', 'Andrej Gendiar', 'Tomotoshi Nishino'], 'arxiv_link': 'http://arxiv.org/abs/1612.07611v1', 'pub_title': 'Phase transition of the six-state clock model observed from the\n entanglement entropy' + 'pub_abstract': 'The Berezinskii-Kosterlitz-Thouless (BKT) transitions of the six-state clock\nmodel on the square lattice are investigated by means of the corner-transfer\nmatrix renormalization group method. The classical analogue of the entanglement\nentropy $S( L, T )$ is calculated for $L$ by $L$ square system up to $L = 129$,\nas a function of temperature $T$. The entropy has a peak at $T = T^{*}_{~}( L\n)$, where the temperature depends on both $L$ and boundary conditions. Applying\nthe finite-size scaling to $T^{*}_{~}( L )$ and assuming the presence of BKT\ntransitions, the transition temperature is estimated to be $T_1^{~} = 0.70$ and\n$T_2^{~} = 0.88$. The obtained results agree with previous analyses. It should\nbe noted that no thermodynamic function is used in this study.', 'author_list': ['Roman KrÄmár', 'Andrej Gendiar', 'Tomotoshi Nishino'], 'arxiv_link': 'http://arxiv.org/abs/1612.07611v1', 'pub_title': 'Phase transition of the six-state clock model observed from the\n entanglement entropy', 'pub_date': datetime.date(2016, 12, 22) } self.assertEqual(caller.data, correct_data) def test_identifier_old_style(self): caller = ArxivCaller('cond-mat/0612480') self.assertTrue(caller.is_valid) + print(caller.data) correct_data = { - 'pub_title': 'Least Action Principle for the Real-Time Density Matrix Renormalization\n Group', 'arxiv_link': 'http://arxiv.org/abs/cond-mat/0612480v2', 'author_list': ['Kouji Ueda', 'Chenglong Jin', 'Naokazu Shibata', 'Yasuhiro Hieida', 'Tomotoshi Nishino'], 'pub_abstract': 'A kind of least action principle is introduced for the discrete time\nevolution of one-dimensional quantum lattice models. Based on this principle,\nwe obtain an optimal condition for the matrix product states on succeeding time\nslices generated by the real-time density matrix renormalization group method.\nThis optimization can also be applied to classical simulations of quantum\ncircuits. We discuss the time reversal symmetry in the fully optimized MPS.' + 'author_list': ['Kouji Ueda', 'Chenglong Jin', 'Naokazu Shibata', 'Yasuhiro Hieida', 'Tomotoshi Nishino'], 'pub_date': datetime.date(2006, 12, 19), 'arxiv_link': 'http://arxiv.org/abs/cond-mat/0612480v2', 'pub_abstract': 'A kind of least action principle is introduced for the discrete time\nevolution of one-dimensional quantum lattice models. Based on this principle,\nwe obtain an optimal condition for the matrix product states on succeeding time\nslices generated by the real-time density matrix renormalization group method.\nThis optimization can also be applied to classical simulations of quantum\ncircuits. We discuss the time reversal symmetry in the fully optimized MPS.', 'pub_title': 'Least Action Principle for the Real-Time Density Matrix Renormalization\n Group' } self.assertEqual(caller.data, correct_data)