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
b8c8464f
Commit
b8c8464f
authored
May 18, 2020
by
Saul Andre
Committed by
Samuel Dimas Partogi
May 18, 2020
Browse files
Pbi 3 unggah materi new
parent
4768a55b
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/templates/unggah.html
View file @
b8c8464f
...
...
@@ -127,16 +127,27 @@
<div
class=
"col-20"
>
<h1
class=
"mt-2"
>
Upload Materi
</h1>
<hr
class=
"mt-0 mb-4"
>
{% if messages %}
{% for message in messages %}
{% if message.level == DEFAULT_MESSAGE_LEVELS.SUCCESS %}
<div
class=
"alert alert-success"
role=
"alert"
>
{{message}}
</div>
{% endif %}
{% if message.level == DEFAULT_MESSAGE_LEVELS.ERROR %}
<div
class=
"alert alert-danger"
role=
"alert"
>
{{message}}
</div>
{% endif %}
{% endfor %}
{% endif %}
<form
form
id=
"add_form"
method=
"POST"
action=
""
novalidate
enctype=
"multipart/form-data"
>
{% csrf_token %}
{% for field in form
%}
{% for field in form%}
<div
class=
"col-md-6"
>
<div
class=
"fieldWrapper"
>
{{ field.label_tag }} {{ field }}
<p>
</p>
{{ field.errors }}
<p>
</p>
{% if field.help_text %}
<p
class=
"help"
>
{{ field.help_text|safe }}
</p>
{% endif %}
...
...
app/tests.py
View file @
b8c8464f
...
...
@@ -17,6 +17,9 @@ from .views import (DaftarKatalog, DashboardKontributorView, DetailMateri,
SuksesLoginKontributorView
,
SuntingProfilView
,
ProfilAdminView
)
from
app.views
import
UploadMateriHTML
,
UploadMateriView
from
authentication.models
import
User
class
DaftarKatalogTest
(
TestCase
):
def
test_daftar_katalog_url_exist
(
self
):
...
...
@@ -238,7 +241,6 @@ class UploadPageTest(TestCase):
# Negative tests
self
.
assertNotContains
(
response
,
"anything"
)
class
DashboardKontributorViewTest
(
TestCase
):
def
setUp
(
self
):
self
.
client
=
Client
()
...
...
app/views.py
View file @
b8c8464f
...
...
@@ -3,6 +3,7 @@ import os
from
django.conf
import
settings
from
django.contrib.auth.models
import
AnonymousUser
from
django.contrib
import
messages
from
django.core
import
serializers
from
django.core.exceptions
import
PermissionDenied
from
django.db.models
import
Q
...
...
@@ -11,12 +12,9 @@ from django.http import (Http404, HttpResponse, HttpResponseRedirect,
from
django.shortcuts
import
get_object_or_404
,
redirect
,
render
from
django.template
import
loader
from
django.views.generic
import
TemplateView
,
ListView
from
authentication.models
import
User
from
.forms
import
SuntingProfilForm
,
UploadMateriForm
from
.models
import
Category
,
Comment
,
Materi
from
django.core.paginator
import
Paginator
,
EmptyPage
,
PageNotAnInteger
class
DaftarKatalog
(
TemplateView
):
...
...
@@ -131,7 +129,6 @@ def download_materi(request, pk):
else
:
raise
Http404
(
"File tidak dapat ditemukan."
)
def
view_materi
(
request
,
pk
):
materi
=
get_object_or_404
(
Materi
,
pk
=
pk
)
path
=
materi
.
content
.
path
...
...
@@ -146,7 +143,6 @@ def view_materi(request, pk):
else
:
raise
Http404
(
"File tidak dapat ditemukan."
)
class
UploadMateriView
(
TemplateView
):
template_name
=
"unggah.html"
context
=
{}
...
...
@@ -166,10 +162,13 @@ class UploadMateriView(TemplateView):
kateg
=
form
.
cleaned_data
[
'categories'
]
for
i
in
kateg
:
materi
.
categories
.
add
(
i
)
messages
.
success
(
request
,
"Materi berhasil diunggah, periksa riwayat unggah anda"
)
return
HttpResponseRedirect
(
"/unggah/"
)
else
:
context
=
self
.
get_context_data
(
**
kwargs
)
context
[
"form"
]
=
form
messages
.
error
(
request
,
"Terjadi kesalahan pada pengisian data"
)
return
self
.
render_to_response
(
context
)
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
@@ -183,7 +182,6 @@ class UploadMateriView(TemplateView):
class
UploadMateriHTML
(
TemplateView
):
template_name
=
"unggah.html"
context
=
{}
def
get_template_names
(
self
):
if
self
.
request
.
path
==
"/unggah/"
:
template_name
=
"unggah.html"
...
...
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