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
a61d7887
Commit
a61d7887
authored
Jun 03, 2020
by
Mika dabelza abi
Committed by
igor lestin sianipar
Jun 03, 2020
Browse files
Coldfix pbi 3 unggah materi restriksi
parent
0c606bd1
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/views.py
View file @
a61d7887
...
...
@@ -5,7 +5,7 @@ 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.core.exceptions
import
PermissionDenied
,
ValidationError
from
django.core.paginator
import
Paginator
,
EmptyPage
,
PageNotAnInteger
from
django.db.models
import
Q
from
django.http
import
(
Http404
,
HttpResponse
,
HttpResponseRedirect
,
...
...
@@ -199,6 +199,12 @@ class UploadMateriView(TemplateView):
if
form
.
is_valid
():
materi
=
form
.
save
(
commit
=
False
)
materi
.
uploader
=
request
.
user
konten
=
form
.
cleaned_data
[
'content'
]
try
:
self
.
validate_file_extension
(
konten
)
except
ValidationError
:
messages
.
error
(
request
,
"Materi gagal diunggah, format file tidak sesuai"
)
return
HttpResponseRedirect
(
"/unggah/"
)
materi
.
save
()
kateg
=
form
.
cleaned_data
[
'categories'
]
for
i
in
kateg
:
...
...
@@ -217,6 +223,12 @@ class UploadMateriView(TemplateView):
context
=
self
.
get_context_data
(
**
kwargs
)
context
[
"form"
]
=
UploadMateriForm
return
self
.
render_to_response
(
context
)
def
validate_file_extension
(
self
,
value
):
ext
=
os
.
path
.
splitext
(
value
.
name
)[
1
]
# [0] returns path+filename
valid_extensions
=
[
'.pdf'
,
'.doc'
,
'.docx'
,
'.jpg'
,
'.png'
,
'.xlsx'
,
'.xls'
,
'.mp4'
,
'.mp3'
]
if
not
ext
.
lower
()
in
valid_extensions
:
raise
ValidationError
(
'Unsupported file extension.'
)
class
UploadMateriHTML
(
TemplateView
):
...
...
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