Fakultas Ilmu Komputer UI

Commit 437c99b8 authored by Saul Andre's avatar Saul Andre
Browse files

[REFACTOR] add POST success or failed message

parent 675f32bc
......@@ -127,7 +127,20 @@
<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">
{% endif %}
{% if message.level == DEFAULT_MESSAGE_LEVELS.ERROR %}
<div class="alert alert-danger" role="alert">
{% endif %}
{% endfor %}
{% endif %}
<form form id="add_form" method="POST" action="" novalidate enctype="multipart/form-data">
{% csrf_token %}
{% for field in form %}
......@@ -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):
......@@ -166,10 +164,13 @@ class UploadMateriView(TemplateView):
kateg = form.cleaned_data['categories']
for i in kateg:
messages.success(request, "Materi berhasil diunggah, periksa riwayat unggah anda")
return HttpResponseRedirect("/unggah/")
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):
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