Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
PMPL
Class Project
DIGIPUS
Commits
c44206a0
Commit
c44206a0
authored
Jun 04, 2020
by
Mika dabelza abi
Committed by
Samuel Dimas Partogi
Jun 04, 2020
Browse files
Pbi 6 halaman katalog
parent
5d0409ac
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/templates/app/katalog_materi.html
View file @
c44206a0
...
...
@@ -108,7 +108,16 @@
</h2>
</div>
<div
id=
"collapseTwo"
class=
"collapse"
aria-labelledby=
"headingTwo"
data-parent=
"#accordionExample"
>
<div
class=
"card-body"
>
<div
class=
"card-body"
>
<li>
<a
href=
"?sort=terbaru"
>
terbaru
</a>
</li>
<li>
<a
href=
"?sort=terlama"
>
terlama
</a>
</li>
<li>
<a
href=
"?sort=terpopuler"
>
terpopuler
</a>
</li>
<li>
<a
href=
"?sort=judul"
>
judul
</a>
</li>
...
...
@@ -150,15 +159,15 @@
</br>
{% if materi_list.has_previous %}
<a
href=
"?page=1"
>
«
first
</a>
<a
href=
"?page={{ materi_list.previous_page_number }}"
>
previous
</a>
<a
href=
"?page=1
{{url}}
"
>
«
first
</a>
<a
href=
"?page={{ materi_list.previous_page_number
}}{{url
}}"
>
previous
</a>
{% endif %}
{% if materi_list.has_next %}
<a
href=
"?page={{ materi_list.next_page_number }}"
>
next
</a>
<a
href=
"?page={{ materi_list.paginator.num_pages }}"
>
last
»
</a>
<a
href=
"?page={{ materi_list.next_page_number
}}{{url
}}"
>
next
</a>
<a
href=
"?page={{ materi_list.paginator.num_pages
}}{{url
}}"
>
last
»
</a>
{% endif %}
</span>
</div>
...
...
app/views.py
View file @
c44206a0
...
...
@@ -7,7 +7,7 @@ from django.contrib import messages
from
django.core
import
serializers
from
django.core.exceptions
import
PermissionDenied
,
ValidationError
from
django.core.paginator
import
Paginator
,
EmptyPage
,
PageNotAnInteger
from
django.db.models
import
Q
from
django.db.models
import
Q
,
Count
from
django.http
import
(
Http404
,
HttpResponse
,
HttpResponseRedirect
,
JsonResponse
)
from
django.shortcuts
import
get_object_or_404
,
redirect
,
render
...
...
@@ -38,33 +38,49 @@ class DaftarKatalog(TemplateView):
except
:
context
[
"materi_list"
]
=
None
list
=
Materi
.
objects
.
filter
(
status
=
"APPROVE"
)
url
=
""
getSearch
=
request
.
GET
.
get
(
'search'
)
if
getSearch
:
list
=
Materi
.
objects
.
filter
(
url
=
url
+
"&search={0}"
.
format
(
getSearch
)
list
=
list
.
filter
(
Q
(
title__icontains
=
getSearch
)
|
Q
(
author__icontains
=
getSearch
)
|
Q
(
uploader__name__icontains
=
getSearch
)
|
Q
(
descriptions__icontains
=
getSearch
)
|
Q
(
publisher__icontains
=
getSearch
)
).
distinct
()
context
[
"materi_list"
]
=
list
.
filter
(
status
=
"APPROVE"
)
getKategori
=
request
.
GET
.
get
(
"kategori"
)
if
getKategori
:
pkGet
=
request
.
GET
.
get
(
"kategori"
)
kategori
=
Category
.
objects
.
get
(
pk
=
pkGet
)
list
=
Materi
.
objects
.
filter
(
categories
=
kategori
.
pk
)
context
[
"materi_list"
]
=
list
.
filter
(
status
=
"APPROVE"
)
url
=
url
+
"&kategori={0}"
.
format
(
getKategori
)
kategori
=
Category
.
objects
.
get
(
pk
=
getKategori
)
list
=
list
.
filter
(
categories
=
kategori
.
pk
)
getSort
=
request
.
GET
.
get
(
"sort"
)
if
getSort
:
list
=
Materi
.
objects
.
all
().
filter
(
status
=
"APPROVE"
)
url
=
url
+
"&sort={0}"
.
format
(
getSort
)
if
(
getSort
==
"judul"
):
context
[
"materi_
list
"
]
=
list
.
order_by
(
'title'
)
list
=
list
.
order_by
(
'title'
)
elif
(
getSort
==
"penulis"
):
context
[
"materi_
list
"
]
=
list
.
order_by
(
'author'
)
list
=
list
.
order_by
(
'author'
)
elif
(
getSort
==
"pengunggah"
):
context
[
"materi_list"
]
=
list
.
order_by
(
'uploader'
)
list
=
list
.
order_by
(
'uploader'
)
elif
(
getSort
==
"terbaru"
):
list
=
list
.
order_by
(
'-date_created'
)
elif
(
getSort
==
"terlama"
):
list
=
list
.
order_by
(
'date_created'
)
elif
(
getSort
==
"terpopuler"
):
list
=
list
.
annotate
(
count
=
Count
(
'like__id'
)).
order_by
(
'-count'
)
context
[
"materi_list"
]
=
list
paginator
=
Paginator
(
context
[
"materi_list"
],
15
)
page_number
=
request
.
GET
.
get
(
'page'
)
page_obj
=
paginator
.
get_page
(
page_number
)
context
[
"materi_list"
]
=
page_obj
context
[
"url"
]
=
url
paginator
=
Paginator
(
context
[
"materi_list"
],
15
)
page_number
=
request
.
GET
.
get
(
'page'
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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