From 92b63780047e797b5c247609a4d2692538230fab Mon Sep 17 00:00:00 2001 From: Geert Kapteijns <ghkapteijns@gmail.com> Date: Sun, 14 May 2017 13:24:15 +0200 Subject: [PATCH] Add better placeholders and help_texts, move string literals to strings module --- commentaries/forms.py | 10 ++++-- .../commentaries/request_arxiv_preprint.html | 30 +++++++++++------ .../request_published_article.html | 32 ++++++++++++------- strings/__init__.py | 15 +++++++++ 4 files changed, 62 insertions(+), 25 deletions(-) diff --git a/commentaries/forms.py b/commentaries/forms.py index 68796e3f4..fd158ef1e 100644 --- a/commentaries/forms.py +++ b/commentaries/forms.py @@ -9,11 +9,13 @@ from .models import Commentary, COMMENTARY_PUBLISHED, COMMENTARY_PREPRINT from scipost.services import DOICaller, ArxivCaller from scipost.models import Contributor +import strings + class DOIToQueryForm(forms.Form): VALID_DOI_REGEXP = r'^(?i)10.\d{4,9}/[-._;()/:A-Z0-9]+$' - doi = forms.RegexField(regex=VALID_DOI_REGEXP, strip=False, widget=forms.TextInput( - {'label': 'DOI', 'placeholder': 'ex.: 10.21468/00.000.000000'})) + doi = forms.RegexField(regex=VALID_DOI_REGEXP, strip=True, help_text=strings.doi_query_help_text, + widget=forms.TextInput({'label': 'DOI', 'placeholder': strings.doi_query_placeholder})) def clean_doi(self): input_doi = self.cleaned_data['doi'] @@ -41,7 +43,9 @@ class ArxivQueryForm(forms.Form): IDENTIFIER_PATTERN_OLD = r'^[-.a-z]+/[0-9]{7,}v[0-9]{1,2}$' VALID_ARXIV_IDENTIFIER_REGEX = "(?:{})|(?:{})".format(IDENTIFIER_PATTERN_NEW, IDENTIFIER_PATTERN_OLD) - identifier = forms.RegexField(regex=VALID_ARXIV_IDENTIFIER_REGEX, strip=True) + identifier = forms.RegexField(regex=VALID_ARXIV_IDENTIFIER_REGEX, strip=True, + help_text=strings.arxiv_query_help_text, widget=forms.TextInput( + {'placeholder': strings.arxiv_query_placeholder})) def clean_identifier(self): identifier = self.cleaned_data['identifier'] diff --git a/commentaries/templates/commentaries/request_arxiv_preprint.html b/commentaries/templates/commentaries/request_arxiv_preprint.html index 75007dbae..d6e82ffa8 100644 --- a/commentaries/templates/commentaries/request_arxiv_preprint.html +++ b/commentaries/templates/commentaries/request_arxiv_preprint.html @@ -7,19 +7,29 @@ {% block content %} <div class="row"> - <form action="{% url 'commentaries:prefill_using_arxiv_identifier' %}" method="post"> - {% csrf_token %} - {{ arxiv_query_form|bootstrap }} - <input class="btn btn-secondary" type="submit" value="Query arXiv"/> - </form> + <div class="col-12"> + <h1 class="page-header">Request Activation of a Commentary Page</h1> + </div> </div> <div class="row"> - <form id="requestForm" action="{% url 'commentaries:request_arxiv_preprint' %}" method="post"> - {% csrf_token %} - {{ form|bootstrap }} - <input class="btn btn-primary" type="submit" value="Submit"/> - </form> + <div class="col-12 col-md-8"> + <form action="{% url 'commentaries:prefill_using_arxiv_identifier' %}" method="post"> + {% csrf_token %} + {{ arxiv_query_form|bootstrap }} + <input class="btn btn-secondary" type="submit" value="Query arXiv"/> + </form> + </div> +</div> + +<div class="row"> + <div class="col-12 col-md-8"> + <form id="requestForm" action="{% url 'commentaries:request_arxiv_preprint' %}" method="post"> + {% csrf_token %} + {{ form|bootstrap }} + <input class="btn btn-primary" type="submit" value="Submit"/> + </form> + </div> </div> {% endblock content%} diff --git a/commentaries/templates/commentaries/request_published_article.html b/commentaries/templates/commentaries/request_published_article.html index b03456af3..f9bc472a3 100644 --- a/commentaries/templates/commentaries/request_published_article.html +++ b/commentaries/templates/commentaries/request_published_article.html @@ -7,21 +7,29 @@ {% block content %} <div class="row"> - {# <h3><em>For published papers, you can prefill the form (except for domain, subject area and abstract) using the DOI:</em></h3>#} - {# <p><em>(give the DOI as 10.[4 to 9 digits]/[string], without prefix, as per the placeholder)</em></p>#} - <form action="{% url 'commentaries:prefill_using_DOI' %}" method="post"> - {% csrf_token %} - {{ doi_query_form|bootstrap }} - <input class="btn btn-secondary" type="submit" value="Query DOI"/> - </form> + <div class="col-12"> + <h1 class="page-header">Request Activation of a Commentary Page</h1> + </div> </div> <div class="row"> - <form id="requestForm" action="{% url 'commentaries:request_published_article' %}" method="post"> - {% csrf_token %} - {{ form|bootstrap }} - <input class="btn btn-primary" type="submit" value="Submit"/> - </form> + <div class='col-12 col-md-8'> + <form action="{% url 'commentaries:prefill_using_DOI' %}" method="post"> + {% csrf_token %} + {{ doi_query_form|bootstrap }} + <input class="btn btn-secondary" type="submit" value="Query DOI"/> + </form> + </div> +</div> + +<div class="row"> + <div class='col-12 col-md-8'> + <form id="requestForm" action="{% url 'commentaries:request_published_article' %}" method="post"> + {% csrf_token %} + {{ form|bootstrap }} + <input class="btn btn-primary" type="submit" value="Submit"/> + </form> + </div> </div> {% endblock content%} diff --git a/strings/__init__.py b/strings/__init__.py index 6e35b4e9e..67211441f 100644 --- a/strings/__init__.py +++ b/strings/__init__.py @@ -13,6 +13,21 @@ acknowledge_submit_comment = ( acknowledge_doi_query = "Crossref query by DOI successful." acknowledge_arxiv_query = "Arxiv query successful." +doi_query_placeholder = 'ex.: 10.21468/00.000.000000' +doi_query_help_text = ( + 'For published papers, you can prefill the form (except for domain, subject area and abstract) using the DOI. ' + "(Give the DOI as 10.[4 to 9 digits]/[string], without prefix, as per the placeholder)." +) + +arxiv_query_placeholder = ( + "new style: YYMM.####(#)v#(#) or " + "old style: cond-mat/YYMM###v#(#)" +) +arxiv_query_help_text = ( + "For preprints, you can prefill the form using the arXiv identifier. " + "Give the identifier without prefix and do not forget the version number, as per the placeholder." +) + # Arxiv response is not valid arxiv_caller_errormessages = { 'preprint_does_not_exist': -- GitLab