Skip to content

Commit

Permalink
clean up of code
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-gray-tangent committed Jul 10, 2024
1 parent 914981b commit b6d7890
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 46 deletions.
6 changes: 0 additions & 6 deletions app/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,27 +229,21 @@ def institutions(request):


def search(request):
# 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)

print(page_obj)
Expand Down
4 changes: 3 additions & 1 deletion app/general/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

class DocumentFileFilter(django_filters.FilterSet):
search = django_filters.CharFilter(method="filter_search", label="Search")

institution = ModelMultipleChoiceFilter(
queryset=Institution.objects.all(), widget=forms.CheckboxSelectMultiple
)
Expand All @@ -35,10 +36,11 @@ def filter_search(self, queryset, name, value):
if value:
queue = SearchQuery(value)
search_rank = SearchRank(F("search_vector"), queue)

search_headline = SearchHeadline("document_data", queue)
queryset = (
queryset.annotate(
rank=search_rank,
search_headline=search_headline,
)
.defer("document_data")
.select_related("institution")
Expand Down
39 changes: 0 additions & 39 deletions app/general/forms.py

This file was deleted.

4 changes: 4 additions & 0 deletions app/templates/app/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ <h5 class="card-title">{% trans "Search a term" %}</h5>
<span class="mr-5"><b>{% trans "License:" %}</b></span>
<span>{{ document.license }}</span>
</li>
<li>
<span class="mr-5"><b>{% trans "License:" %}</b></span>
<span>{{ document.document_type }}</span>
</li>
<li>
<span class="mr-5"><b>{% trans "Mime Type:" %}</b></span>
<span>{{ document.mime_type }}</span>
Expand Down

0 comments on commit b6d7890

Please sign in to comment.