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 @@
<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 %}
......
......@@ -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()
......
......@@ -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"
......
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