Fakultas Ilmu Komputer UI

Commit 54d33bea authored by I Gusti Putu Agastya Indrayana's avatar I Gusti Putu Agastya Indrayana
Browse files

[CHORES] Pull latest code.

parents 0c49b347 368e6c23
Pipeline #49946 passed with stage
in 6 minutes and 22 seconds
......@@ -32,19 +32,14 @@ class DaftarKatalog(TemplateView):
def get(self, request, *args, **kwargs):
context = self.get_context_data(**kwargs)
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 = ""
getSearch = request.GET.get('search')
if getSearch:
url = url + "&search={0}".format(getSearch)
list = list.filter(
lstMateri = lstMateri.filter(
Q(title__icontains=getSearch) |
Q(author__icontains=getSearch) |
Q(uploader__name__icontains=getSearch) |
......@@ -56,37 +51,31 @@ class DaftarKatalog(TemplateView):
if getKategori:
url = url + "&kategori={0}".format(getKategori)
kategori = Category.objects.get(pk=getKategori)
list = list.filter(categories=kategori.pk)
lstMateri = lstMateri.filter(categories=kategori.pk)
getSort = request.GET.get("sort")
if getSort:
url = url + "&sort={0}".format(getSort)
if(getSort == "judul"):
list = list.order_by('title')
lstMateri = lstMateri.order_by('title')
elif(getSort == "penulis"):
list = list.order_by('author')
lstMateri = lstMateri.order_by('author')
elif(getSort == "pengunggah"):
list = list.order_by('uploader')
lstMateri = lstMateri.order_by('uploader')
elif(getSort == "terbaru"):
list = list.order_by('-date_created')
lstMateri = lstMateri.order_by('-date_created')
elif(getSort == "terlama"):
list = list.order_by('date_created')
lstMateri = lstMateri.order_by('date_created')
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)
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')
page_obj = paginator.get_page(page_number)
context["materi_list"] = page_obj
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