Fakultas Ilmu Komputer UI

Commit b8c8464f authored by Saul Andre's avatar Saul Andre Committed by Samuel Dimas Partogi
Browse files

Pbi 3 unggah materi new

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