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 16, 2024
1 parent 42479cf commit 1a4001c
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 137 deletions.
1 change: 1 addition & 0 deletions app/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ def search(request):

f = DocumentFileFilter(request.GET, queryset=DocumentFile.objects.all())

print(f.qs)
template = "app/search.html"

paginator = Paginator(f.qs, 5) # 5 documents per page
Expand Down
27 changes: 24 additions & 3 deletions app/general/filters.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import django_filters
from django import forms
from django.contrib.postgres.search import SearchHeadline, SearchQuery, SearchRank
from django.db.models import F
from django.db.models import F, Q
from django_filters import ModelMultipleChoiceFilter, MultipleChoiceFilter

from general.models import DocumentFile, Institution, Language, Subject
from general.models import DocumentFile, Institution, Language, Project, Subject


class DocumentFileFilter(django_filters.FilterSet):
Expand All @@ -23,6 +23,13 @@ class DocumentFileFilter(django_filters.FilterSet):
queryset=Language.objects.all(), widget=forms.CheckboxSelectMultiple
)

projects = django_filters.CharFilter(method="filter_projects", label="Projects")
# projects = django_filters.CharFilter(
# queryset=Project.objects.all(),
# method='filter_project',
# label="Projects"
# )

class Meta:
model = DocumentFile
fields = [
Expand All @@ -48,7 +55,15 @@ def filter_queryset(self, queryset):
.select_related("institution")
).order_by("-rank")

return queryset
project_query = Project.objects.filter(
Q(name__icontains=search) | Q(description__icontains=search)
)

# Combine the two querysets into a single list
combined_results = list(queryset) + list(project_query)
return combined_results

# return queryset

def filter_search(self, queryset, name, value):
if value:
Expand All @@ -57,3 +72,9 @@ def filter_search(self, queryset, name, value):

else:
return queryset

def filter_projects(self, queryset, name, value):
if value:
projects = value.split(",")
return queryset.filter(projects__name__in=projects).distinct()
return queryset
285 changes: 151 additions & 134 deletions app/templates/app/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,154 +3,171 @@
{% load i18n %}

{% block content %}
<div class="body">
<div class="section mt-3 mb-3">
<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:'' }}">
<div class="body">
<div class="section mt-3 mb-3">
<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>
<input type="submit" class="btn btn-success float-left"/>
</form>
<br>
<input type="submit" class="btn btn-success float-left"/>
</form>
<br>
<br>
<div class="container">
{% for document in search_results %}
<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>
</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 "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>
</li>
<li class="mt-2">
<span class="mr-5"><b>{% trans "Rank:" %}</b></span>
<span><i>{{ document.rank }}</i></span>
</li>
</ul>
</div>
{% endfor %}
<br>
<div class="container">
{% for document in search_results %}
<div>
<ul>
<li>
<span class="mr-5 text-primary"><b>{% trans "Project Name:" %}</b></span>
<span>{{ document.name }}</span>
</li>
<li>
<span class="mr-5 text-primary"><b>{% trans "Project description:" %}</b></span>
<span>{{ document.description }}</span>
</li>
<li>
<span> {% if document.logo %}
<img src="{{ document.logo.url }}" alt="
{% blocktrans with project_name=document.name %}{{ project_name }} logo{% endblocktrans %}"
class="project-logo">
{% endif %}
</span>
</li>
<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 "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>
</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>
<div class="container">
<hr>
<div class="pagination ">
{% if documents.has_previous %}
<a href="{{ search_params }}&page=1">&laquo; first</a>
<a href="{{ search_params }}&page={{ documents.previous_page_number }}">&lt; previous</a>
{% endif %}
<span class="current">
<div class="container">
<hr>
<div class="pagination ">
{% if documents.has_previous %}
<a href="{{ search_params }}&page=1">&laquo; first</a>
<a href="{{ search_params }}&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_params }}&page={{ documents.next_page_number }}">next &gt;</a>
<a href="{{ search_params }}&page={{ documents.paginator.num_pages }}">last
&raquo;</a>
{% endif %}
{% if documents.has_next %}
<a href="{{ search_params }}&page={{ documents.next_page_number }}">next &gt;</a>
<a href="{{ search_params }}&page={{ documents.paginator.num_pages }}">last
&raquo;</a>
{% endif %}
</div>
<hr>
</div>
<hr>
</div>
<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>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label for="id_subjects">Institution</label>
<div class="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 %}
<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>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label for="id_subjects">Institution</label>
<div class="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>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="id_subjects">Document Type</label>
<div class="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 class="col-md-3">
<div class="form-group">
<label for="id_subjects">Document Type</label>
<div class="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>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="id_subjects">Subjects</label>
<div class="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 class="col-md-3">
<div class="form-group">
<label for="id_subjects">Subjects</label>
<div class="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>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="id_subjects">Languages</label>
<div class="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 class="col-md-3">
<div class="form-group">
<label for="id_subjects">Languages</label>
<div class="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>
</div>
</div>
<br>
<input type="submit" class="btn btn-success float-left"/>
<br>
</form>
<br>
<input type="submit" class="btn btn-success float-left"/>
<br>
</form>
</div>
<br>
</div>
<br>
</div>
</div>

{% endblock content %}
{% endblock content %}

0 comments on commit 1a4001c

Please sign in to comment.