Fakultas Ilmu Komputer UI

Commit 7b0a06ae authored by Nandhika Prayoga's avatar Nandhika Prayoga
Browse files

Merge branch '1706039912-41' into 'master'

[#41] Material: Random Material List

See merge request !52
parents fc2849fa 1b96a05c
Pipeline #58761 passed with stages
in 14 minutes and 25 seconds
...@@ -75,7 +75,9 @@ ...@@ -75,7 +75,9 @@
</div> </div>
</header> </header>
<a href="/download-history/" class="btn-history">Riwayat Unduh</a><br><br> <a href="/download-history/" class="btn-history">Riwayat Unduh</a><br><br>
<a href="?random=1" class="btn-history">Acak Materi</a><br><br>
<div class="container"> <div class="container">
<div class="row content"> <div class="row content">
......
...@@ -2274,6 +2274,49 @@ class MateriModelTest(TestCase): ...@@ -2274,6 +2274,49 @@ class MateriModelTest(TestCase):
Like.objects.create(timestamp=datetime.now(), materi=self.materi, session_id="dummysessionid2") Like.objects.create(timestamp=datetime.now(), materi=self.materi, session_id="dummysessionid2")
self.assertEqual(2, self.materi.like_count) self.assertEqual(2, self.materi.like_count)
class RandomizedMateriTest(TestCase):
def setUp(self):
self.contributor = User.objects.create(
email="kontributor@gov.id", password="passwordtest", name="kontributor", is_contributor=True
)
self.cover = SimpleUploadedFile("ExampleCover221.jpg", b"Test file")
self.content = SimpleUploadedFile("ExampleFile221.pdf", b"Test file")
self.materi = Materi.objects.create(
title="Materi 1",
author="Nandhika",
uploader=self.contributor,
publisher="Kelas SC",
descriptions="Deskripsi Materi 1",
status="APPROVE",
cover=self.cover,
content=self.content,
date_modified=datetime.now(),
date_created=datetime.now(),
)
self.materi = Materi.objects.create(
title="Materi 2",
author="Prayoga",
uploader=self.contributor,
publisher="Kelas SC",
descriptions="Deskripsi Materi 2",
status="APPROVE",
cover=self.cover,
content=self.content,
date_modified=datetime.now(),
date_created=datetime.now(),
)
def test_randomized_materi_returns_200(self):
response = Client().get("/?random=1")
self.assertEqual(response.status_code, 200)
def test_randomized_materi_remains_same_materi(self):
response = Client().get("/?random=1")
self.assertIn("Materi 1", response.content.decode())
self.assertIn("Materi 2", response.content.decode())
class YearChoicesTest(TestCase): class YearChoicesTest(TestCase):
def test_release_year_contains_the_right_current_year(self): def test_release_year_contains_the_right_current_year(self):
......
...@@ -39,6 +39,7 @@ from django.contrib import messages ...@@ -39,6 +39,7 @@ from django.contrib import messages
from pydrive.auth import GoogleAuth from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive from pydrive.drive import GoogleDrive
from pydrive.auth import AuthenticationRejected from pydrive.auth import AuthenticationRejected
import random
def permission_denied(request, exception, template_name="error_403.html"): def permission_denied(request, exception, template_name="error_403.html"):
return defaults.permission_denied(request, exception, template_name) return defaults.permission_denied(request, exception, template_name)
...@@ -96,6 +97,10 @@ class DaftarKatalog(TemplateView): ...@@ -96,6 +97,10 @@ class DaftarKatalog(TemplateView):
elif(getSort == "jumlah_unduh"): elif(getSort == "jumlah_unduh"):
lstMateri = lstMateri.annotate(count=Count('unduh__id')).order_by('-count') lstMateri = lstMateri.annotate(count=Count('unduh__id')).order_by('-count')
should_random = bool(request.GET.get("random"))
if should_random:
lstMateri = random.sample(list(lstMateri), len(lstMateri))
context["materi_list"] = lstMateri 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")
......
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