Skip to content

Commit

Permalink
added search
Browse files Browse the repository at this point in the history
  • Loading branch information
sumandari committed Jan 21, 2022
1 parent a0680ee commit 9c84388
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
table td {
background-color: white;
}
.sort-header {
background-color: #EEEEEE;
}
</style>
{% endblock %}

Expand Down Expand Up @@ -62,12 +65,22 @@ <h3>No certifying organisations are defined, but you can <a
{% endif %}
{% endifequal %}

<div class="form-group pull-right">
<form method="GET" action="" id="searchform">
<span class="glyphicon glyphicon-search form-control-feedback"></span>
<input class="searchfield form-control" id="searchbox" name="q" type="text"
value="{{ request.GET.q }}" placeholder="Search Organisation..."/>
</form>
</div>



<table class="table table-striped">
<thead>
<tr>
<th>{% sort_link "Organisation Name" "name" %}</th>
<th>{% sort_link "Application Date" "submit_date" %}</th>
<th>{% sort_link "Status" "status" %}</th>
<th class="sort-header">{% sort_link "Organisation Name" "name" %}</th>
<th class="sort-header">{% sort_link "Application Date" "submit_date" %}</th>
<th class="sort-header">{% sort_link "Status" "status" %}</th>
</tr>
</thead>
<tbody>
Expand Down
16 changes: 14 additions & 2 deletions django_project/certification/views/certifying_organisation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# coding=utf-8
from base.models import Project
from django.contrib import messages
from django.contrib.postgres.search import SearchVector
from django.core.mail import send_mail
from django.urls import reverse
from django.shortcuts import get_list_or_404
Expand Down Expand Up @@ -652,16 +653,27 @@ def form_valid(self, form):
'this name is already exists!')


class CertifyingOrganisationSearchMixin(object):
"""Mixin class to provide search in ListView."""

def get_queryset_search(self, qs):
q = self.request.GET.get('q')
if q:
qs = qs.annotate(search=SearchVector('name')).filter(search=q)
return qs


class PendingCertifyingOrganisationListView(
LoginRequiredMixin,
CertifyingOrganisationMixin,
PaginationMixin,
CertifyingOrganisationSearchMixin,
ListView):
"""List view for pending certifying organisation."""

context_object_name = 'certifyingorganisations'
template_name = 'certifying_organisation/pending-list.html'
paginate_by = 20
paginate_by = 10

def __init__(self):
"""
Expand Down Expand Up @@ -732,7 +744,7 @@ def get_queryset(self):
queryset = queryset.order_by(Lower('name').desc())
else:
queryset = queryset.order_by(sort_by)
return queryset
return self.get_queryset_search(queryset)
else:
raise Http404(
'Sorry! We could not find your Certifying Organisation!')
Expand Down

0 comments on commit 9c84388

Please sign in to comment.