Fakultas Ilmu Komputer UI

views.py 3.43 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponseRedirect
from django.views.generic import TemplateView
from django.core.exceptions import PermissionDenied
from .models import VerificationSetting
from .forms import CategoryForm, VerificationSettingForm

from app.models import Materi, Category

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

def approve(request, pk):
    if request.user.is_authenticated == False or request.user.is_admin != True:
        raise PermissionDenied(request)
    materi =  get_object_or_404(Materi,pk=pk)
    materi.status = ('APPROVE','Diterima')
    materi.save()
    return render(request, 'verif.html')
    
def disapprove(request, pk):
    if request.user.is_authenticated == False or request.user.is_admin != True:
        raise PermissionDenied(request)
    materi =  get_object_or_404(Materi,pk=pk)
    materi.status = ('DISAPROVE','Ditolat')
    materi.save()
    return render(request, 'verif.html')

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

    def get_context_data(self, **kwargs):
        context = super(VerificationSettingView, self   ).get_context_data(**kwargs)
        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)
                
class CategorySettingView(TemplateView):
    template_name = "setting_category.html"

    def get_context_data(self, **kwargs):
        context = super(CategorySettingView, self   ).get_context_data(**kwargs)
        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)