Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
PMPL
Class Project
DIGIPUS
Commits
4caec5a5
Commit
4caec5a5
authored
Oct 09, 2020
by
Erithiana Sisijoan Koesnadi
Browse files
[56] Fitur Sort by Jumlah Unduh (Download)
parent
32b762dd
Changes
4
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
4caec5a5
...
...
@@ -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.
...
...
app/templates/app/katalog_materi.html
View file @
4caec5a5
...
...
@@ -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>
...
...
app/tests.py
View file @
4caec5a5
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
):
...
...
app/views.py
View file @
4caec5a5
...
...
@@ -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
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment