Skip to content

Commit

Permalink
backup of code
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-gray-tangent committed Jul 8, 2024
1 parent 121bd31 commit b661d4b
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 131 deletions.
29 changes: 25 additions & 4 deletions app/app/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

Expand Down
254 changes: 127 additions & 127 deletions app/templates/app/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,162 +6,162 @@

<div class="body">
<div class="section mt-3 mb-3">
<div class="card content-card">
<div class="card content-card p-2">
<div class="card-body">
<h5 class="card-title">{% trans "Search a term" %}</h5>


<form method="get" class="container">

<input type="search" name="{{ filter.form.search.name }}" placeholder="{% trans 'Search...' %}"
class="form-control search-input"
value="{{ request.GET.search|default_if_none:'' }}">

<br>

<br>
<br>
<input type="submit" class="btn btn-success float-left"/>
</form>
<br>
<br>

{% for document in filter.qs %}
<div>
<ul>
<li>
<span class="mr-5 text-primary"><b>{% trans "Title:" %}</b></span>
<span>{{ document.title }}</span>
</li>
<li class="mb-2">
<span class="mr-5"><b>{% trans "Institution:" %}</b></span>
<span>{{ document.institution }}</span>
</li>
<li class="mb-2">
<span class="mr-5"><b>{% trans "Headline:" %}</b></span>
<span>{{ document.search_headline|safe }}</span>
<div class="container">
{% for document in search_results %}
<div>
<ul><li>
{{ forloop.counter0 }}
</li>
<li>
<span class="mr-5"><b>{% trans "File:" %}</b></span>
<span>{{ document.uploaded_file }}</span>
</li>
<li>
<span class="mr-5"><b>{% trans "License:" %}</b></span>
<span>{{ document.license }}</span>
</li>
<li>
<span class="mr-5"><b>{% trans "Mime Type:" %}</b></span>
<span>{{ document.mime_type }}</span>
</li>
<li class="mt-2">
<span class="mr-5"><b>{% trans "Rank:" %}</b></span>
<span><i>{{ document.rank }}</i></span>
</li>
</ul>
</div>
{% endfor %}
<li>
<span class="mr-5 text-primary"><b>{% trans "Title:" %}</b></span>
<span>{{ document.title }}</span>
</li>
<li class="mb-2">
<span class="mr-5"><b>{% trans "Institution:" %}</b></span>
<span>{{ document.institution }}</span>
</li>
<li class="mb-2">
<span class="mr-5"><b>{% trans "Headline:" %}</b></span>
<span>{{ document.search_headline|safe }}</span>
</li>
<li>
<span class="mr-5"><b>{% trans "File:" %}</b></span>
<span>{{ document.uploaded_file }}</span>
</li>
<li>
<span class="mr-5"><b>{% trans "License:" %}</b></span>
<span>{{ document.license }}</span>
</li>
<li>
<span class="mr-5"><b>{% trans "Mime Type:" %}</b></span>
<span>{{ document.mime_type }}</span>
</li>
<li class="mt-2">
<span class="mr-5"><b>{% trans "Rank:" %}</b></span>
<span><i>{{ document.rank }}</i></span>
</li>
</ul>
</div>
{% endfor %}
</div>
</div>
{# <div class="pagination">#}
{# <span class="step-links">#}
{# {% if documents.has_previous %}#}
{# <a href="?page=1">&laquo; {% trans "first" %}</a>#}
{# <a href="?page={{ documents.previous_page_number }}">{% trans "previous" }</a>#}
{# {% endif %}#}
{# <span class="current">#}
{# Page {{ documents.number }} of {{ documents.paginator.num_pages }}.#}
{# </span>#}
{# {% if documents.has_next %}#}
{# <a href="?page={{ documents.next_page_number }}">{% trans "next" %}</a>#}
{# <a href="?page={{ documents.paginator.num_pages }}">{% trans "last" %} &raquo;</a>#}
{# {% endif %}#}
{# </span>#}
{# <hr>#}
{# </div>#}
{# </div>#}
{# test section end#}
{# {% else %}#}
{# <p>{% trans "Functionality of this page coming soon" %}</p>#}
{# {% endif %}#}
<div class="container">
<hr>
<div class="pagination ">
{% if documents.has_previous %}
<a href="?search={{ request.GET.search|default_if_none:'' }}
&document_type={{ request.GET.document_type|default_if_none:'' }}
&institution={{ request.GET.institution|default_if_none:'' }}
&subjects={{ request.GET.subjects|default_if_none:'' }}
&languages={{ request.GET.languages|default_if_none:'' }}&page=1">&laquo; first</a>
<a href="?page={{ documents.previous_page_number }}">&lt; previous</a>
{% endif %}
<span class="current">
Page {{ documents.number }} of {{ documents.paginator.num_pages }}.
</span>
{% if documents.has_next %}
<a href="?search={{ request.GET.search|default_if_none:'' }}
&document_type={{ request.GET.document_type|default_if_none:'' }}
&institution={{ request.GET.institution|default_if_none:'' }}
&subjects={{ request.GET.subjects|default_if_none:'' }}
&languages={{ request.GET.languages|default_if_none:'' }}
&page={{ documents.next_page_number }}">next &gt;</a>
<a href="?search={{ request.GET.search|default_if_none:'' }}&page={{ documents.paginator.num_pages }}">last &raquo;</a>
{% endif %}
</div>
<hr>
</div>
<form method="get" class="container">

<form method="get" class="container">
<input type="search" name="{{ filter.form.search.name }}" placeholder="{% trans 'Search...' %}"
class="form-control search-input"
value="{{ request.GET.search|default_if_none:'' }}">

<input type="search" name="{{ filter.form.search.name }}" placeholder="{% trans 'Search...' %}"
class="form-control search-input"
value="{{ request.GET.search|default_if_none:'' }}">

<br>
<br>

<div class="row">
<div class="col-md-3">
<div class="form-group">
<label for="id_subjects">Institution</label>
<div class="subjects-checkbox-container">
{% for checkbox in filter.form.institution %}
<div class="form-check">
{{ checkbox.tag }}
<label class="form-check-label"
for="{{ checkbox.id_for_label }}">
{{ checkbox.choice_label }}
</label>
</div>
{% endfor %}
</div>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label for="id_subjects">Institution</label>
<div class="subjects-checkbox-container">
{% for checkbox in filter.form.institution %}
<div class="form-check">
{{ checkbox.tag }}
<label class="form-check-label"
for="{{ checkbox.id_for_label }}">
{{ checkbox.choice_label }}
</label>
</div>
{% endfor %}
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="id_subjects">Document Type</label>
<div class="subjects-checkbox-container">
{% for checkbox in filter.form.document_type %}
<div class="form-check">
{{ checkbox.tag }}
<label class="form-check-label" for="{{ checkbox.id_for_label }}">
{{ checkbox.choice_label }}
</label>
</div>
{% endfor %}
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="id_subjects">Document Type</label>
<div class="subjects-checkbox-container">
{% for checkbox in filter.form.document_type %}
<div class="form-check">
{{ checkbox.tag }}
<label class="form-check-label" for="{{ checkbox.id_for_label }}">
{{ checkbox.choice_label }}
</label>
</div>
{% endfor %}
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="id_subjects">Subjects</label>
<div class="subjects-checkbox-container">
{% for checkbox in filter.form.subjects %}
<div class="form-check">
{{ checkbox.tag }}
<label class="form-check-label" for="{{ checkbox.id_for_label }}">
{{ checkbox.choice_label }}
</label>
</div>
{% endfor %}
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="id_subjects">Subjects</label>
<div class="subjects-checkbox-container">
{% for checkbox in filter.form.subjects %}
<div class="form-check">
{{ checkbox.tag }}
<label class="form-check-label" for="{{ checkbox.id_for_label }}">
{{ checkbox.choice_label }}
</label>
</div>
{% endfor %}
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="id_subjects">Languages</label>
<div class="subjects-checkbox-container">
{% for checkbox in filter.form.languages %}
<div class="form-check">
{{ checkbox.tag }}
<label class="form-check-label" for="{{ checkbox.id_for_label }}">
{{ checkbox.choice_label }}
</label>
</div>
{% endfor %}
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="id_subjects">Languages</label>
<div class="subjects-checkbox-container">
{% for checkbox in filter.form.languages %}
<div class="form-check">
{{ checkbox.tag }}
<label class="form-check-label" for="{{ checkbox.id_for_label }}">
{{ checkbox.choice_label }}
</label>
</div>
{% endfor %}
</div>
</div>
</div>

<br>
<br>
<input type="submit" class="btn btn-success float-left"/>
</form>
<br>
</div>
<input type="submit" class="btn btn-success float-left"/>
<br>
</form>

</div>
<br>
</div>
</div>

Expand Down

0 comments on commit b661d4b

Please sign in to comment.