Fakultas Ilmu Komputer UI

Commit 26195ff4 authored by Erithiana Sisijoan Koesnadi's avatar Erithiana Sisijoan Koesnadi
Browse files

Merge branch '2006560850-56' into 'master'

[56] Fitur Sort by Jumlah Unduh (Download)

See merge request !40
parents 32b762dd 4caec5a5
Pipeline #58147 canceled with stages
in 10 minutes and 16 seconds
......@@ -15,6 +15,7 @@ media
/static/
media/
.coverage
virtualenv
# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
# in your Git repository. Update and uncomment the following line accordingly.
......
......@@ -133,6 +133,9 @@
<li>
<a href="?sort=pengunggah">pengunggah</a>
</li>
<li>
<a href="?sort=jumlah_unduh">jumlah unduh</a>
</li>
</div>
</div>
</div>
......
import json, tempfile, os, mock
import pandas as pd
from io import StringIO
import time
from bs4 import BeautifulSoup
from datetime import datetime
......@@ -136,6 +137,45 @@ class DaftarKatalogTest(TestCase):
self.assertSequenceEqual(search_result, expected_search_result)
class DaftarKatalogSortingByJumlahUnduhTest(TestCase):
def setUp(self):
self.client = Client()
self.contributor_credential = {
"email": "kontributor@gov.id",
"password": "passwordtest"
}
self.contributor_credential_2 = {
"email": "kontributor2@gov.id",
"password": "passwordtest"
}
self.contributor = get_user_model().objects.create_user(
**self.contributor_credential, name="Kontributor 1", is_contributor=True)
self.contributor2 = get_user_model().objects.create_user(
**self.contributor_credential_2, name="Kontributor 2", is_contributor=True)
self.cover = SimpleUploadedFile(
"Cherprang_Areekul40_nJM9dGt.jpg", b"Test file")
self.content = SimpleUploadedFile("Bahan_PA_RKK.pdf", b"Test file")
Materi(title="Materi 1", author="Agas", uploader=self.contributor,
publisher="Kelas SC", descriptions="Deskripsi Materi 1",
status="APPROVE", cover=self.cover, content=self.content).save()
time.sleep(1)
Materi(title="Materi 2", author="Agas", uploader=self.contributor,
publisher="Kelas SC", descriptions="Deskripsi Materi 2",
status="APPROVE", cover=self.cover, content=self.content).save()
self.last_uploaded_material = Materi.objects.last()
material_unduh_url = f"/materi/{self.last_uploaded_material.id}/unduh"
self.client.get(material_unduh_url)
def test_sorting_by_jumlah_unduh(self):
response = self.client.get("/?sort=jumlah_unduh")
self.assertRegex(str(response.content), rf'.*Materi 2.*Materi 1.*')
class DaftarKatalogPerKontributorTest(TestCase):
def setUp(self):
......
......@@ -78,18 +78,20 @@ class DaftarKatalog(TemplateView):
getSort = request.GET.get("sort")
if getSort:
url = url + "&sort={0}".format(getSort)
if getSort == "judul":
lstMateri = lstMateri.order_by("title")
elif getSort == "penulis":
lstMateri = lstMateri.order_by("author")
elif getSort == "pengunggah":
lstMateri = lstMateri.order_by("uploader")
elif getSort == "terbaru":
lstMateri = lstMateri.order_by("-date_created")
elif getSort == "terlama":
lstMateri = lstMateri.order_by("date_created")
elif getSort == "terpopuler":
lstMateri = lstMateri.annotate(count=Count("like__id")).order_by("-count")
if(getSort == "judul"):
lstMateri = lstMateri.order_by('title')
elif(getSort == "penulis"):
lstMateri = lstMateri.order_by('author')
elif(getSort == "pengunggah"):
lstMateri = lstMateri.order_by('uploader')
elif(getSort == "terbaru"):
lstMateri = lstMateri.order_by('-date_created')
elif(getSort == "terlama"):
lstMateri = lstMateri.order_by('date_created')
elif(getSort == "terpopuler"):
lstMateri = lstMateri.annotate(count=Count('like__id')).order_by('-count')
elif(getSort == "jumlah_unduh"):
lstMateri = lstMateri.annotate(count=Count('unduh__id')).order_by('-count')
context["materi_list"] = lstMateri
paginator = Paginator(context["materi_list"], 15)
......
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