diff --git a/scipost/context_processors.py b/scipost/context_processors.py deleted file mode 100644 index 19c0fbf686bb62fb3d3908d1f0a370bc9f23165b..0000000000000000000000000000000000000000 --- a/scipost/context_processors.py +++ /dev/null @@ -1,5 +0,0 @@ -from .forms import SearchForm - - -def searchform(request): - return {'search_form': SearchForm()} diff --git a/scipost/forms.py b/scipost/forms.py index 04f36192dbf87b171561b533c64707c7afffa624..47c6ef82fca8c106a0fb0bda996bfa7df543b9dd 100644 --- a/scipost/forms.py +++ b/scipost/forms.py @@ -210,9 +210,8 @@ class RemarkForm(forms.Form): class SearchForm(forms.Form): - query = forms.CharField(max_length=100, label='', - widget=forms.TextInput(attrs={ - 'class': 'form-control mr-0 mb-2 mr-lg-2 mb-lg-0'})) + q = forms.CharField(max_length=100, label='', widget=forms.TextInput(attrs={ + 'class': 'form-control mr-0 mb-2 mr-lg-2 mb-lg-0'})) class EmailGroupMembersForm(forms.Form): diff --git a/scipost/templates/scipost/navbar.html b/scipost/templates/scipost/navbar.html index 04cce9fedff90383eb8df8bf20fd99d4fdc1d979..29161549ed69fbbefbb3dd886868c413b44f1f65 100644 --- a/scipost/templates/scipost/navbar.html +++ b/scipost/templates/scipost/navbar.html @@ -38,9 +38,8 @@ {% endif %} </ul> - <form action="{% url 'scipost:search' %}" method="post" class="form-inline"> - {% csrf_token %} - {{ search_form }} + <form action="{% url 'scipost:search' %}" method="get" class="form-inline"> + <input class="form-control mr-0 mb-2 mr-lg-2 mb-lg-0" id="id_q" maxlength="100" name="q" type="text" required=""> <button class="btn btn-primary" type="submit">Search</button> </form> </div> diff --git a/scipost/templates/scipost/search.html b/scipost/templates/scipost/search.html index 050dbafd542fae2959975c7f27117d6c7cece837..911e4686ed965a1f8a4ebb054ac3e25b8a0adcaa 100644 --- a/scipost/templates/scipost/search.html +++ b/scipost/templates/scipost/search.html @@ -2,125 +2,171 @@ {% block pagetitle %}: list{% endblock pagetitle %} -{% block headsup %} - -{% endblock headsup %} - -{% block bodysup %} - - -<section> - <h1>Search results</h1> - - {% if publication_search_list or commentary_search_list or submission_search_list or thesislink_search_list or comment_search_link %} - {% else %} - <p>Your search query did not return any result.</p> - {% endif %} - - {% if publication_search_list %} - <br /> - <hr class="hr12"> - <h3>Publications:</h3> - - <ul> - {% for publication in publication_search_list %} - {{ publication.header_as_li }} - {% endfor %} - </ul> - - <div class="pagination"> - <span class="step-links"> - {% if publication_search_list.has_previous %} - <a href="?publication_search_list_page={{ publication_search_list.previous_page_number }}">previous</a> - {% endif %} - <span class="current"> - Page {{ publication_search_list.number }} of {{ publication_search_list.paginator.num_pages }}. - </span> - {% if publication_search_list.has_next %} - <a href="?publication_search_list_page={{ publication_search_list.next_page_number }}">next</a> - {% endif %} - </span> - </div> - - {% endif %} - - - {% if commentary_search_list %} - <br /> - <hr class="hr12"> - <h3>Commentaries:</h3> - - <ul> - {% for commentary in commentary_search_list %} - {{ commentary.header_as_li }} - {% endfor %} - </ul> - - <div class="pagination"> - <span class="step-links"> - {% if commentary_search_list.has_previous %} - <a href="?commentary_search_list_page={{ commentary_search_list.previous_page_number }}">previous</a> - {% endif %} - <span class="current"> - Page {{ commentary_search_list.number }} of {{ commentary_search_list.paginator.num_pages }}. - </span> - {% if commentary_search_list.has_next %} - <a href="?commentary_search_list_page={{ commentary_search_list.next_page_number }}">next</a> - {% endif %} - </span> - </div> - - {% endif %} - - - {% if submission_search_list %} - <br /> - <hr class="hr12"> - <h3>Submissions:</h3> - <ul> - {% for submission in submission_search_list %} - {{ submission.header_as_li }} - {% endfor %} - </ul> - - <div class="pagination"> - <span class="step-links"> - {% if submission_search_list.has_previous %} - <a href="?submission_search_list_page={{ submission_search_list.previous_page_number }}">previous</a> - {% endif %} - <span class="current"> - Page {{ submission_search_list.number }} of {{ submission_search_list.paginator.num_pages }} - </span> - {% if submission_search_list.has_next %} - <a href="?submission_search_list_page={{ submission_search_list.next_page_number }}">next</a> - {% endif %} - </span> - </div> - - {% endif %} - - {% if thesislink_search_list %} - <br /> - <hr class="hr12"> - <h3>Theses:</h3> - <ul> - {% for thesislink in thesislink_search_list %} - {% include 'theses/_thesislink_header_as_li.html' with thesislink=thesislink %} - {% endfor %} - </ul> - {% endif %} - - {% if comment_search_list %} - <br /> - <hr class="hr12"> - <h3>Comments:</h3> - <ul> - {% for comment in comment_search_list %} - {{ comment.header_as_li }} - {% endfor %} - </ul> - {% endif %} - -</section> - -{% endblock bodysup %} +{% block content %} + +<div class="row"> + <div class="col-12"> + <h1>Search results{% if search_term %}: <small><i>{{ search_term }}</i></small>{% endif %}</h1> + {% if not publication_search_list and not commentary_search_list and not submission_search_list and not thesislink_search_list and not comment_search_link and not comment_search_list %} + <p>Your search query did not return any result.</p> + {% endif %} + </div> +</div> + +{% if publication_search_list %} +<hr> +<div class="row"> + <div class="col-12"> + <div class="panel"> + <h2>Publications</h2> + </div> + </div> +</div> + +<div class="row"> + <div class="col-12"> + {% for publication in publication_search_list %} + {{ publication.header_as_li }} + {% endfor %} + </div> +</div> + +<div class="row"> + <div class="col-12"> + <div class="pagination"> + <span class="step-links"> + {% if publication_search_list.has_previous %} + <a href="?publication_search_list_page={{ publication_search_list.previous_page_number }}">previous</a> + {% endif %} + <span class="current"> + Page {{ publication_search_list.number }} of {{ publication_search_list.paginator.num_pages }}. + </span> + {% if publication_search_list.has_next %} + <a href="?publication_search_list_page={{ publication_search_list.next_page_number }}">next</a> + {% endif %} + </span> + </div> + + </div> +</div> +{% endif %} + + +{% if commentary_search_list %} +<hr> +<div class="row"> + <div class="col-12"> + <div class="panel"> + <h2>Commentaries</h2> + </div> + </div> +</div> +<div class="row"> + <div class="col-12"> + <ul> + {% for commentary in commentary_search_list %} + {{ commentary.header_as_li }} + {% endfor %} + </ul> + </div> +</div> + +<div class="row"> + <div class="col-12"> + <div class="pagination"> + <span class="step-links"> + {% if commentary_search_list.has_previous %} + <a href="?commentary_search_list_page={{ commentary_search_list.previous_page_number }}">previous</a> + {% endif %} + <span class="current"> + Page {{ commentary_search_list.number }} of {{ commentary_search_list.paginator.num_pages }}. + </span> + {% if commentary_search_list.has_next %} + <a href="?commentary_search_list_page={{ commentary_search_list.next_page_number }}">next</a> + {% endif %} + </span> + </div> + + </div> +</div> +{% endif %} + + +{% if submission_search_list %} +<hr> +<div class="row"> + <div class="col-12"> + <div class="panel"> + <h2>Submissions</h2> + </div> + </div> +</div> +<div class="row"> + <div class="col-12"> + <ul> + {% for submission in submission_search_list %} + {{ submission.header_as_li }} + {% endfor %} + </ul> + </div> +</div> + +<div class="row"> + <div class="col-12"> + <div class="pagination"> + <span class="step-links"> + {% if submission_search_list.has_previous %} + <a href="?submission_search_list_page={{ submission_search_list.previous_page_number }}">previous</a> + {% endif %} + <span class="current"> + Page {{ submission_search_list.number }} of {{ submission_search_list.paginator.num_pages }} + </span> + {% if submission_search_list.has_next %} + <a href="?submission_search_list_page={{ submission_search_list.next_page_number }}">next</a> + {% endif %} + </span> + </div> + </div> +</div> +{% endif %} + +{% if thesislink_search_list %} +<hr> +<div class="row"> + <div class="col-12"> + <div class="panel"> + <h2>Theses</h2> + </div> + </div> +</div> +<div class="row"> + <div class="col-12"> + <ul> + {% for thesislink in thesislink_search_list %} + {% include 'theses/_thesislink_header_as_li.html' with thesislink=thesislink %} + {% endfor %} + </ul> + {% endif %} + + {% if comment_search_list %} + <div class="row"> + <div class="col-12"> + <div class="panel"> + <h2>Comments</h2> + </div> + </div> + </div> + <div class="row"> + <div class="col-12"> + <ul> + {% for comment in comment_search_list %} + {{ comment.header_as_li }} + {% endfor %} + </ul> + </div> + </div> + {% endif %} + </div> +</div> + +{% endblock content %} diff --git a/scipost/views.py b/scipost/views.py index 496ceb09a3032657e7148518705a682a1aa36d56..bae70ff6fd044e7bd82edca43986b8a76f1e450f 100644 --- a/scipost/views.py +++ b/scipost/views.py @@ -153,17 +153,15 @@ def documentsSearchResults(query): def search(request): """ For the global search form in navbar """ - if request.method == 'POST': - form = SearchForm(request.POST) - if form.is_valid(): - context = documentsSearchResults(form.cleaned_data['query']) - request.session['query'] = form.cleaned_data['query'] - else: - context = {} + form = SearchForm(request.GET or None) + context = {} + if form.is_valid(): + context = documentsSearchResults(form.cleaned_data['q']) + request.session['query'] = form.cleaned_data['q'] + context['search_term'] = form.cleaned_data['q'] elif 'query' in request.session: - context = documentsSearchResults(request.session['query']) - else: - context = {} + context = documentsSearchResults(request.session['query']) + context['search_term'] = request.session['query'] if 'publication_search_queryset' in context: publication_search_list_paginator = Paginator(context['publication_search_queryset'], 10)