Fakultas Ilmu Komputer UI

Commit 7431ad94 authored by Bunga Amalia Kurniawati's avatar Bunga Amalia Kurniawati 🌺
Browse files

Merge branch '1706022104-125' into 'master'

[#125] Material: Sorting by Comment Count

Closes #125

See merge request !98
parents b034328f e0f49fd1
Pipeline #60115 passed with stages
in 24 minutes and 43 seconds
......@@ -67,6 +67,8 @@ class DafterKatalogService:
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')
elif (get_sort == "jumlah_komentar"):
lst_materi = lst_materi.annotate(count=Count('comment__id')).order_by('-count')
return lst_materi, url
@staticmethod
......
......@@ -149,6 +149,9 @@
<li>
<a href="?sort=jumlah_tampilan">jumlah tampilan</a>
</li>
<li>
<a href="?sort=jumlah_komentar">jumlah komentar</a>
</li>
</ul>
</div>
</div>
......
......@@ -206,7 +206,48 @@ class DaftarKatalogSortingByJumlahTampilanTest(TestCase):
self.client.get(self.url)
response = self.client.get("/?sort=jumlah_tampilan")
self.assertRegex(str(response.content), rf'.*Materi 2.*Materi 1.*')
class DaftarKatalogSortingByJumlahKomentarTest(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()
url = f"/materi/{self.last_uploaded_material.id}/"
self.client.login(**self.contributor_credential_2)
self.client.post(url, {"comment": "This is new comment by Kontributor 2"})
def test_sorting_by_jumlah_komentar(self):
response = self.client.get("/?sort=jumlah_komentar")
self.assertRegex(str(response.content), rf'.*Materi 2.*Materi 1.*')
class DaftarKatalogPerKontributorTest(TestCase):
def setUp(self):
self.client = Client()
......
Markdown is supported
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