views.py 2.87 KB
Newer Older
1
2
3
4
from django.contrib.messages.views import SuccessMessageMixin
from django.views.generic import CreateView, UpdateView, DeleteView
from django.views.generic import ListView, DetailView
from django.urls import reverse_lazy
5
6
from submission.models import Submission
from submission.forms import SubmissionForm
7
from degree.models import Degree
8
from submission.analysis import main as submission_analysis
Bruno Meyer's avatar
Bruno Meyer committed
9

10
11
12
13
14
15
class SubmissionCreate(SuccessMessageMixin, CreateView):
    model = Submission
    form_class = SubmissionForm
    template_name = 'submission_create.html'
    success_url = reverse_lazy('dashboard')
    success_message = "Relatório enviado com suceso"
16

17
18
19
20
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context["hide_navbar"] = True
        return context
21

22
23
24
25
26
27
28
29
    def form_valid(self, form):
        # muda nomes dos arquivos
        form.instance.historico.name = "historico.xls"
        form.instance.matricula.name = "matricula.xls"
        # adiciona a form.instance.usuario e curso
        form.instance.author = self.request.user.educator
        degree = Degree.objects.get(code=form.instance.degree.code)
        form.instance.degree = degree
Bruno Meyer's avatar
Bruno Meyer committed
30

31
        response = super(SubmissionCreate, self).form_valid(form)
32

33
34
35
        submission_analysis.analyze(self.object, debug=False)

        return response
36

37
38
39
40
41
42
43

class SubmissionUpdate(UpdateView):
    model = Submission
    template_name = 'submission_update.html'
    context_object_name = 'submission'
    success_url = reverse_lazy('dashboard')
    fields = [
44
45
46
47
48
49
        'historico',
        'matricula',
        'relative_year',
        'relative_semester',
        'semester_status']

50
51
52
53
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context["hide_navbar"] = True
        return context
Bruno Meyer's avatar
Bruno Meyer committed
54

55
56
57
58
class SubmissionDelete(DeleteView):
    model = Submission
    template_name = 'submission_delete.html'
    success_url = reverse_lazy('dashboard')
Bruno Meyer's avatar
Bruno Meyer committed
59

60
61
62
63
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context["hide_navbar"] = True
        return context
64

65
66
67
68
class SubmissionList(ListView):
    model = Submission
    template_name = 'submission_list.html'
    context_object_name = 'submission'
69
70
71



72
73
74
75
76
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context["hide_navbar"] = True
        # context["degree_id"] = self.kwargs["degree_id"]
        return context
77

78
79
80
    def get_queryset(self):
        educator = self.request.user.educator
        return self.model.objects.filter(author=educator)
81

Bruno Meyer's avatar
Bruno Meyer committed
82

83
84
85
86
class SubmissionDetail(DetailView):
    model = Submission
    template_name = 'submission_detail.html'
    context_object_name = 'submission'
Bruno Meyer's avatar
Bruno Meyer committed
87

88
89
90
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context["hide_navbar"] = True
91
        return context