Fakultas Ilmu Komputer UI

Commit 84bb7a6b authored by Samuel Dimas Partogi's avatar Samuel Dimas Partogi
Browse files

Merge branch 'PBI-6-Halaman_Katalog' into 'staging'

Pbi 6 halaman katalog

See merge request ppl-fasilkom-ui/2020/ppl-c/diskominfo-depok-digipus/marjinal-digipus!68
parents 5d0409ac c44206a0
......@@ -108,7 +108,16 @@
</h2>
</div>
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordionExample">
<div class="card-body">
<div class="card-body">
<li>
<a href="?sort=terbaru">terbaru</a>
</li>
<li>
<a href="?sort=terlama">terlama</a>
</li>
<li>
<a href="?sort=terpopuler">terpopuler</a>
</li>
<li>
<a href="?sort=judul">judul</a>
</li>
......@@ -150,15 +159,15 @@
</br>
{% if materi_list.has_previous %}
<a href="?page=1" >&laquo; first</a>
<a href="?page={{ materi_list.previous_page_number }}">previous</a>
<a href="?page=1{{url}}" >&laquo; first</a>
<a href="?page={{ materi_list.previous_page_number }}{{url}}">previous</a>
{% endif %}
{% if materi_list.has_next %}
<a href="?page={{ materi_list.next_page_number }}">next</a>
<a href="?page={{ materi_list.paginator.num_pages }}">last &raquo;</a>
<a href="?page={{ materi_list.next_page_number }}{{url}}">next</a>
<a href="?page={{ materi_list.paginator.num_pages }}{{url}}">last &raquo;</a>
{% endif %}
</span>
</div>
......
......@@ -7,7 +7,7 @@ from django.contrib import messages
from django.core import serializers
from django.core.exceptions import PermissionDenied, ValidationError
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.db.models import Q
from django.db.models import Q, Count
from django.http import (Http404, HttpResponse, HttpResponseRedirect,
JsonResponse)
from django.shortcuts import get_object_or_404, redirect, render
......@@ -38,33 +38,49 @@ class DaftarKatalog(TemplateView):
except:
context["materi_list"] = None
list = Materi.objects.filter(status="APPROVE")
url = ""
getSearch = request.GET.get('search')
if getSearch:
list = Materi.objects.filter(
url = url + "&search={0}".format(getSearch)
list = list.filter(
Q(title__icontains=getSearch) |
Q(author__icontains=getSearch) |
Q(uploader__name__icontains=getSearch) |
Q(descriptions__icontains=getSearch) |
Q(publisher__icontains=getSearch)
).distinct()
context["materi_list"] = list.filter(status="APPROVE")
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.filter(status="APPROVE")
url = url + "&kategori={0}".format(getKategori)
kategori = Category.objects.get(pk=getKategori)
list = list.filter(categories=kategori.pk)
getSort = request.GET.get("sort")
if getSort:
list = Materi.objects.all().filter(status="APPROVE")
url = url + "&sort={0}".format(getSort)
if(getSort == "judul"):
context["materi_list"] = list.order_by('title')
list = list.order_by('title')
elif(getSort == "penulis"):
context["materi_list"] = list.order_by('author')
list = list.order_by('author')
elif(getSort == "pengunggah"):
context["materi_list"] = list.order_by('uploader')
list = list.order_by('uploader')
elif(getSort == "terbaru"):
list = list.order_by('-date_created')
elif(getSort == "terlama"):
list = list.order_by('date_created')
elif(getSort == "terpopuler"):
list = list.annotate(count=Count('like__id')).order_by('-count')
context["materi_list"] = list
paginator = Paginator(context["materi_list"], 15)
page_number = request.GET.get('page')
page_obj = paginator.get_page(page_number)
context["materi_list"] = page_obj
context["url"] = url
paginator = Paginator(context["materi_list"], 15)
page_number = request.GET.get('page')
......
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