Fakultas Ilmu Komputer UI

Commit a61d7887 authored by Mika dabelza abi's avatar Mika dabelza abi Committed by igor lestin sianipar
Browse files

Coldfix pbi 3 unggah materi restriksi

parent 0c606bd1
......@@ -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']
except ValidationError:
messages.error(request, "Materi gagal diunggah, format file tidak sesuai")
return HttpResponseRedirect("/unggah/")
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):
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