Fakultas Ilmu Komputer UI

Commit 9dbe00da authored by Mika dabelza abi's avatar Mika dabelza abi
Browse files

[GREEN] implementing function filter,sort,and search

parent aca82609
......@@ -10,9 +10,9 @@
<div class="col">
<h2 class="pageTitle">Temukan Materi Yang Kamu Mau!</h2>
<p class="description">Cari dengan judul buku, penerbit, atau penulis</p>
<form class="searchBar">
<form class="searchBar" action=''>
<div class="col-6 form-group">
<input type="email" class="form-control" placeholder="Tulis di sini">
<input type="text" name='search' class="form-control" placeholder="Tulis di sini" value='{{request.GET.search}}'>
</div>
<button type="submit" class="btn btn-cari">Cari</button>
</form>
......@@ -40,9 +40,11 @@
aria-labelledby="headingOne"
data-parent="#accordionExample">
<div class="card-body">
<p>Kategory test1</p>
<p>Kategory test1</p>
<p>Kategory test1</p>
{% for itemKategori in kategori_list %}
<li>
<a href="?kategori={{itemKategori.pk}}">{{itemKategori.name}}</a>
</li>
{% endfor %}
</div>
</div>
</div>
......@@ -56,9 +58,15 @@
</div>
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordionExample">
<div class="card-body">
<p>Sort test1</p>
<p>Sort test1</p>
<p>Sort test1</p>
<li>
<a href="?sort=judul">judul</a>
</li>
<li>
<a href="?sort=penulis">penulis</a>
</li>
<li>
<a href="?sort=pengunggah">pengunggah</a>
</li>
</div>
</div>
</div>
......
......@@ -3,7 +3,9 @@ from django.template import loader
from django.http import HttpResponse, JsonResponse, HttpResponseRedirect
from django.views.generic import TemplateView
from django.core import serializers
from .models import Materi
from .models import Materi,Category
from django.db.models import Q
class DaftarKatalog(TemplateView):
template_name = "app/katalog_materi.html"
......@@ -13,7 +15,37 @@ class DaftarKatalog(TemplateView):
def get(self, request, *args, **kwargs):
context = self.get_context_data(**kwargs)
context["kategori_list"] = Category.objects.all()
context["materi_list"] = Materi.objects.all()
getSearch = request.GET.get('search')
if getSearch:
list = Materi.objects.all().filter(
Q(title__icontains = getSearch) |
Q(descriptions__icontains = getSearch) |
Q(author__icontains=getSearch) |
Q(uploader__icontains=getSearch) |
Q(publisher__icontains=getSearch)
).distinct
context["materi_list"] = list
getKategori = request.GET.get("kategori")
if getKategori:
pkGet = request.GET.get("kategori")
kategori = Category.objects.get(pk = pkGet)
list = Materi.objects.filter(categories = kategori.pk)
context["materi_list"] = list
getSort = request.GET.get("sort")
if getSort:
list = Materi.objects.all()
if(getSort == "judul"):
context["materi_list"] = list.order_by('title')
elif(getSort == "penulis"):
context["materi_list"] = list.order_by('author')
elif(getSort == "pengunggah"):
context["materi_list"] = list.order_by('uploader')
return self.render_to_response(context=context)
class DetailMateri(TemplateView):
......@@ -26,6 +58,7 @@ class DetailMateri(TemplateView):
context = self.get_context_data(**kwargs)
context["materi_list"] = Materi.objects.all()
return self.render_to_response(context=context)
def listMateri(self):
queries = Materi.objects.all()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment