Fakultas Ilmu Komputer UI

Commit 368e6c23 authored by Saul Andre's avatar Saul Andre
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!71
parents 12cfd103 fcc40796
...@@ -32,19 +32,14 @@ class DaftarKatalog(TemplateView): ...@@ -32,19 +32,14 @@ class DaftarKatalog(TemplateView):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
context = self.get_context_data(**kwargs) context = self.get_context_data(**kwargs)
context["kategori_list"] = Category.objects.all() context["kategori_list"] = Category.objects.all()
try:
context["materi_list"] = Materi.objects.all().filter(
status="APPROVE")
except:
context["materi_list"] = None
list = Materi.objects.filter(status="APPROVE") lstMateri = Materi.objects.filter(status="APPROVE").order_by("date_modified")
url = "" url = ""
getSearch = request.GET.get('search') getSearch = request.GET.get('search')
if getSearch: if getSearch:
url = url + "&search={0}".format(getSearch) url = url + "&search={0}".format(getSearch)
list = list.filter( lstMateri = lstMateri.filter(
Q(title__icontains=getSearch) | Q(title__icontains=getSearch) |
Q(author__icontains=getSearch) | Q(author__icontains=getSearch) |
Q(uploader__name__icontains=getSearch) | Q(uploader__name__icontains=getSearch) |
...@@ -56,37 +51,31 @@ class DaftarKatalog(TemplateView): ...@@ -56,37 +51,31 @@ class DaftarKatalog(TemplateView):
if getKategori: if getKategori:
url = url + "&kategori={0}".format(getKategori) url = url + "&kategori={0}".format(getKategori)
kategori = Category.objects.get(pk=getKategori) kategori = Category.objects.get(pk=getKategori)
list = list.filter(categories=kategori.pk) lstMateri = lstMateri.filter(categories=kategori.pk)
getSort = request.GET.get("sort") getSort = request.GET.get("sort")
if getSort: if getSort:
url = url + "&sort={0}".format(getSort) url = url + "&sort={0}".format(getSort)
if(getSort == "judul"): if(getSort == "judul"):
list = list.order_by('title') lstMateri = lstMateri.order_by('title')
elif(getSort == "penulis"): elif(getSort == "penulis"):
list = list.order_by('author') lstMateri = lstMateri.order_by('author')
elif(getSort == "pengunggah"): elif(getSort == "pengunggah"):
list = list.order_by('uploader') lstMateri = lstMateri.order_by('uploader')
elif(getSort == "terbaru"): elif(getSort == "terbaru"):
list = list.order_by('-date_created') lstMateri = lstMateri.order_by('-date_created')
elif(getSort == "terlama"): elif(getSort == "terlama"):
list = list.order_by('date_created') lstMateri = lstMateri.order_by('date_created')
elif(getSort == "terpopuler"): elif(getSort == "terpopuler"):
list = list.annotate(count=Count('like__id')).order_by('-count') lstMateri = lstMateri.annotate(count=Count('like__id')).order_by('-count')
context["materi_list"] = list context["materi_list"] = lstMateri
paginator = Paginator(context["materi_list"], 15) paginator = Paginator(context["materi_list"], 15)
page_number = request.GET.get('page') page_number = request.GET.get('page')
page_obj = paginator.get_page(page_number) page_obj = paginator.get_page(page_number)
context["materi_list"] = page_obj context["materi_list"] = page_obj
context["url"] = url context["url"] = url
paginator = Paginator(context["materi_list"], 15)
page_number = request.GET.get('page')
page_obj = paginator.get_page(page_number)
context["materi_list"] = page_obj
return self.render_to_response(context=context) return self.render_to_response(context=context)
......
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