-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
78 lines (55 loc) · 2.56 KB
/
views.py
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
from django.shortcuts import render, reverse
from django.contrib import messages
from django.views import generic
from django.views.generic.base import TemplateView
from django.contrib.auth.mixins import LoginRequiredMixin
from base.models import Certificate
from base.forms import CertificateForm
from base.utils import sendTransaction, get_transaction
from .mixins import StaffAndLoginRequiredMixin
class CertificateListView(LoginRequiredMixin, generic.ListView):
template_name = 'certificates/certificate_list.html'
context_object_name = 'certificates'
def get_queryset(self):
if self.request.user.is_staff:
return Certificate.objects.all()
elif self.request.user.is_authenticated:
return Certificate.objects.filter(student=self.request.user.pk)
class CertificateCreateView(StaffAndLoginRequiredMixin, generic.CreateView):
template_name = 'certificates/certificate_create.html'
form_class = CertificateForm
def get_success_url(self) -> str:
return reverse('certificates:certificate-list')
def form_valid(self, form):
messages.success(self.request, 'You have successfuly created a certificate')
return super(CertificateCreateView, self).form_valid(form)
class CertificateDetailView(generic.DetailView):
template_name = 'certificates/certificate_detail.html'
context_object_name = 'certificates'
def get_queryset(self):
return Certificate.objects.all()
class CertificateUpdateView(StaffAndLoginRequiredMixin, generic.UpdateView):
template_name = 'certificates/certificate_update.html'
context_object_name = 'certificates'
form_class = CertificateForm
def get_success_url(self) -> str:
return reverse('certificates:certificate-list')
def get_queryset(self):
return Certificate.objects.all()
def form_valid(self, form):
form.save()
messages.info(self.request, 'You have successfuly update a certificate')
return super(CertificateUpdateView, self).form_valid(form)
class CertificateDeleteView(StaffAndLoginRequiredMixin, generic.DeleteView):
template_name = 'certificates/certificate_delete.html'
context_object_name = 'certificates'
def get_queryset(self):
return Certificate.objects.all()
def get_success_url(self) -> str:
return reverse('certificates:certificate-list')
def transaction_detail_view(request, txid):
transiction = get_transaction(txid)
context = {
"transiction": transiction
}
return render(request, "certificates/transaction_detail.html", context)