From c910e219b5151acb5110ef60ddc305fc33927f28 Mon Sep 17 00:00:00 2001 From: "J.-S. Caux" <J.S.Caux@uva.nl> Date: Wed, 9 Nov 2016 17:15:08 +0100 Subject: [PATCH] Include Publication objects in search lists --- scipost/templates/scipost/search.html | 31 ++++++++++++++++++++++++++- scipost/views.py | 19 +++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/scipost/templates/scipost/search.html b/scipost/templates/scipost/search.html index 2d17ac83f..419dcf4f4 100644 --- a/scipost/templates/scipost/search.html +++ b/scipost/templates/scipost/search.html @@ -12,11 +12,39 @@ <section> <h1>Search results</h1> - {% if commentary_search_list or submission_search_list or thesislink_search_list or comment_search_link %} + {% 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"> @@ -44,6 +72,7 @@ {% endif %} + {% if submission_search_list %} <br /> <hr class="hr12"> diff --git a/scipost/views.py b/scipost/views.py index 5a6729f02..c015f61c0 100644 --- a/scipost/views.py +++ b/scipost/views.py @@ -96,6 +96,8 @@ def documentsSearchResults(query): Naive implementation based on exact match of query. NEEDS UPDATING with e.g. Haystack. """ + publication_query = get_query(query, + ['title', 'author_list', 'abstract', 'doi_string']) commentary_query = get_query(query, ['pub_title', 'author_list', 'pub_abstract']) submission_query = get_query(query, @@ -105,6 +107,9 @@ def documentsSearchResults(query): comment_query = get_query(query, ['comment_text']) + publication_search_queryset = Publication.objects.filter( + publication_query, + ).order_by('-publication_date') commentary_search_queryset = Commentary.objects.filter( #commentary_search_list = Commentary.objects.filter( commentary_query, @@ -123,7 +128,8 @@ def documentsSearchResults(query): comment_query, status__gte='1', ).order_by('-date_submitted') - context = {'commentary_search_queryset': commentary_search_queryset, + context = {'publication_search_queryset': publication_search_queryset, + 'commentary_search_queryset': commentary_search_queryset, #'commentary_search_list': commentary_search_list, 'submission_search_queryset': submission_search_queryset, #'submission_search_list': submission_search_list, @@ -146,6 +152,17 @@ def search(request): else: context = {} + if 'publication_search_queryset' in context: + publication_search_list_paginator = Paginator (context['publication_search_queryset'], 10) + publication_search_list_page = request.GET.get('publication_search_list_page') + try: + publication_search_list = publication_search_list_paginator.page(publication_search_list_page) + except PageNotAnInteger: + publication_search_list = publication_search_list_paginator.page(1) + except EmptyPage: + publication_search_list = publication_search_list_paginator.page(publication_search_list_paginator.num_pages) + context['publication_search_list'] = publication_search_list + if 'commentary_search_queryset' in context: commentary_search_list_paginator = Paginator (context['commentary_search_queryset'], 10) commentary_search_list_page = request.GET.get('commentary_search_list_page') -- GitLab