Fakultas Ilmu Komputer UI

views.py 3.39 KB
Newer Older
1
from django.core.exceptions import PermissionDenied
2
from django.http import HttpResponseRedirect
3
from django.shortcuts import get_object_or_404, render
4
from django.views.generic import TemplateView
5
6
7

from app.models import Category, Materi

8
from .forms import CategoryForm, VerificationSettingForm
9
from .models import VerificationSetting
10
11
12
13


# Create your views here.
def verification(request):
14
15
    return render(request, "verif.html")

16
17
18
19

def approve(request, pk):
    if request.user.is_authenticated == False or request.user.is_admin != True:
        raise PermissionDenied(request)
20
21
    materi = get_object_or_404(Materi, pk=pk)
    materi.status = ("APPROVE", "Diterima")
22
    materi.save()
23
24
25
    return render(request, "verif.html")


26
27
28
def disapprove(request, pk):
    if request.user.is_authenticated == False or request.user.is_admin != True:
        raise PermissionDenied(request)
29
30
    materi = get_object_or_404(Materi, pk=pk)
    materi.status = ("DISAPROVE", "Ditolat")
31
    materi.save()
32
33
    return render(request, "verif.html")

34
35
36
37
38

class VerificationSettingView(TemplateView):
    template_name = "setting_verifikasi.html"

    def get_context_data(self, **kwargs):
39
        context = super(VerificationSettingView, self).get_context_data(**kwargs)
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
        context["verification_settings"] = VerificationSetting.objects.filter(archived=False)
        return context

    def get(self, request, *args, **kwargs):
        if request.user.is_authenticated == False or request.user.is_admin != True:
            raise PermissionDenied(request)
        else:
            context = self.get_context_data(**kwargs)
            context["form"] = VerificationSettingForm()
            return self.render_to_response(context=context)

    def post(self, request, *args, **kwargs):
        if request.user.is_authenticated == False or request.user.is_admin != True:
            raise PermissionDenied(request)
        else:
            form = VerificationSettingForm(request.POST)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect("/administration/setting/verification/")
            else:
                context = self.get_context_data(**kwargs)
                context["form"] = form
                return self.render_to_response(context)
63
64


65
66
67
68
class CategorySettingView(TemplateView):
    template_name = "setting_category.html"

    def get_context_data(self, **kwargs):
69
        context = super(CategorySettingView, self).get_context_data(**kwargs)
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
        context["category_settings"] = Category.objects.all()
        return context

    def get(self, request, *args, **kwargs):
        if request.user.is_authenticated == False or request.user.is_admin != True:
            raise PermissionDenied(request)
        else:
            context = self.get_context_data(**kwargs)
            context["form"] = CategoryForm()
            return self.render_to_response(context=context)

    def post(self, request, *args, **kwargs):
        if request.user.is_authenticated == False or request.user.is_admin != True:
            raise PermissionDenied(request)
        else:
            form = CategoryForm(request.POST)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect("/administration/setting/category/")
            else:
                context = self.get_context_data(**kwargs)
                context["form"] = form
                return self.render_to_response(context)