Fakultas Ilmu Komputer UI

Commit db19e628 authored by Erithiana Sisijoan Koesnadi's avatar Erithiana Sisijoan Koesnadi
Browse files

[53] Fitur Sorting Materi By Jumlah Tampilan

parent 503de4cb
......@@ -60,6 +60,8 @@ class DafterKatalogService:
lst_materi = lst_materi.annotate(count=Count('like__id')).order_by('-count')
elif (get_sort == "jumlah_unduh"):
lst_materi = lst_materi.annotate(count=Count('unduh__id')).order_by('-count')
elif (get_sort == "jumlah_tampilan"):
lst_materi = lst_materi.annotate(count=Count('baca__id')).order_by('-count')
return lst_materi, url
@staticmethod
......
......@@ -141,6 +141,9 @@
<li>
<a href="?sort=jumlah_unduh">jumlah unduh</a>
</li>
<li>
<a href="?sort=jumlah_tampilan">jumlah tampilan</a>
</li>
</ul>
</div>
</div>
......
......@@ -186,6 +186,40 @@ class DaftarKatalogSortingByJumlahUnduhTest(TestCase):
response = self.client.get("/?sort=jumlah_unduh")
self.assertRegex(str(response.content), rf'.*Materi 2.*Materi 1.*')
class DaftarKatalogSortingByJumlahTampilanTest(TestCase):
def setUp(self):
self.contributor_credential = {
"email": "kontributor@gov.id",
"password": id_generator()
}
self.contributor = get_user_model().objects.create_user(
**self.contributor_credential, name="Kontributor", is_contributor=True
)
self.client = Client()
content = b"Test file"
self.cover = SimpleUploadedFile(
"cover.jpg",
content
)
self.content = SimpleUploadedFile(
"content.txt",
content
)
Materi(title="Materi 1", author="Agas", uploader=self.contributor,
publisher="Kelas SC", descriptions="Deskripsi Materi 1",
status="PENDING", cover=self.cover, content=self.content).save()
Materi(title="Materi 2", author="Agas", uploader=self.contributor,
publisher="Kelas SC", descriptions="Deskripsi Materi 1",
status="PENDING", cover=self.cover, content=self.content).save()
self.materi2 = Materi.objects.last()
self.url = f"/materi/{self.materi2.id}/view"
def sorting_by_jumlah_tampilan(self):
self.client.get(self.url)
response = self.client.get("/?sort=jumlah_tampilan")
self.assertRegex(str(response.content), rf'.*Materi 2.*Materi 1.*')
class DaftarKatalogPerKontributorTest(TestCase):
def setUp(self):
self.client = Client()
......
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