diff --git a/app/app/views.py b/app/app/views.py index 69f31017..b8622dc1 100644 --- a/app/app/views.py +++ b/app/app/views.py @@ -1,5 +1,5 @@ # from pprint import pprint - +from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator from django.db.models import Count from django.http import HttpResponse from django.shortcuts import get_object_or_404, render @@ -229,14 +229,35 @@ def institutions(request): def search(request): - # form = DocumentFileSearchForm(request.GET or None) - # pprint(request.GET) + # f = DocumentFileFilter(request.GET, queryset=DocumentFile.objects.all().defer("document_data")) f = DocumentFileFilter(request.GET, queryset=DocumentFile.objects.all()) + template = "app/search.html" + + print(f.qs) + + paginator = Paginator(f.qs, 5) # 5 documents per page + + print(paginator) + + page_number = request.GET.get("page") + + try: + # Get the page + page_obj = paginator.page(page_number) + except PageNotAnInteger: + # If page is not an integer, deliver first page + page_obj = paginator.page(1) + except EmptyPage: + # If page is out of range (e.g., 9999), deliver last page of results + page_obj = paginator.page(paginator.num_pages) + + # Update the context with the page object context = { + "search_results": paginator.page(page_obj.number), "filter": f, + "documents": page_obj, } - template = "app/search.html" return render(request, template_name=template, context=context) diff --git a/app/templates/app/search.html b/app/templates/app/search.html index 9fcd8ec7..78572781 100644 --- a/app/templates/app/search.html +++ b/app/templates/app/search.html @@ -6,11 +6,9 @@
-
+
{% trans "Search a term" %}
- -
{% trans "Search a term" %} value="{{ request.GET.search|default_if_none:'' }}">
- -
-


- - {% for document in filter.qs %} -
-
    -
  • - {% trans "Title:" %} - {{ document.title }} -
  • -
  • - {% trans "Institution:" %} - {{ document.institution }} -
  • -
  • - {% trans "Headline:" %} - {{ document.search_headline|safe }} +
    + {% for document in search_results %} +
    +
    • + {{ forloop.counter0 }}
    • -
    • - {% trans "File:" %} - {{ document.uploaded_file }} -
    • -
    • - {% trans "License:" %} - {{ document.license }} -
    • -
    • - {% trans "Mime Type:" %} - {{ document.mime_type }} -
    • -
    • - {% trans "Rank:" %} - {{ document.rank }} -
    • -
    -
    - {% endfor %} +
  • + {% trans "Title:" %} + {{ document.title }} +
  • +
  • + {% trans "Institution:" %} + {{ document.institution }} +
  • +
  • + {% trans "Headline:" %} + {{ document.search_headline|safe }} +
  • +
  • + {% trans "File:" %} + {{ document.uploaded_file }} +
  • +
  • + {% trans "License:" %} + {{ document.license }} +
  • +
  • + {% trans "Mime Type:" %} + {{ document.mime_type }} +
  • +
  • + {% trans "Rank:" %} + {{ document.rank }} +
  • +
+
+ {% endfor %} +
- {# #} - {#
#} - {# test section end#} - {# {% else %}#} - {#

{% trans "Functionality of this page coming soon" %}

#} - {# {% endif %}#} +
+
+ +
+
+
- + - - -
+
-
-
-
- -
- {% for checkbox in filter.form.institution %} -
- {{ checkbox.tag }} - -
- {% endfor %} -
+
+
+
+ +
+ {% for checkbox in filter.form.institution %} +
+ {{ checkbox.tag }} + +
+ {% endfor %}
-
-
- -
- {% for checkbox in filter.form.document_type %} -
- {{ checkbox.tag }} - -
- {% endfor %} -
+
+
+
+ +
+ {% for checkbox in filter.form.document_type %} +
+ {{ checkbox.tag }} + +
+ {% endfor %}
-
-
- -
- {% for checkbox in filter.form.subjects %} -
- {{ checkbox.tag }} - -
- {% endfor %} -
+
+
+
+ +
+ {% for checkbox in filter.form.subjects %} +
+ {{ checkbox.tag }} + +
+ {% endfor %}
-
-
- -
- {% for checkbox in filter.form.languages %} -
- {{ checkbox.tag }} - -
- {% endfor %} -
+
+
+
+ +
+ {% for checkbox in filter.form.languages %} +
+ {{ checkbox.tag }} + +
+ {% endfor %}
- -
-
- - -
+
+
+ +
+