-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
59 lines (43 loc) · 1.78 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
from django.db.models import Q
from django.urls import reverse_lazy
from django.views.generic import ListView
from django.views.generic import DetailView
from django.views.generic.edit import CreateView
from django.views.generic.edit import UpdateView
from django.views.generic.edit import DeleteView
from .models import Information as ProjectInformation
# Create your views here.
class MainView(ListView):
template_name = 'projects/pages/main.html'
model = ProjectInformation
context_object_name = 'projects'
def get_queryset(self):
user = self.request.user
return ProjectInformation.objects.filter(
Q(secure_level=1) |
Q(directors__exact=user, secure_level=2) |
Q(project_manager=user)
).distinct()
class InformationView(DetailView):
model = ProjectInformation
context_object_name = 'project'
class InformationCreateView(CreateView):
template_name = 'projects/forms/information.html'
model = ProjectInformation
fields = ('name', 'description', 'secure_level', 'budget')
def form_valid(self, form):
form.instance.project_manager = self.request.user
return super(InformationCreateView, self).form_valid(form)
class InformationUpdateView(UpdateView):
template_name = 'projects/forms/information.html'
model = ProjectInformation
fields = ('name', 'description', 'secure_level', 'budget')
class InformationDirectorsUpdateView(UpdateView):
template_name = 'projects/forms/information_directors.html'
model = ProjectInformation
fields = ('directors',)
class InformationDeleteView(DeleteView):
template_name = 'projects/forms/information_delete.html'
model = ProjectInformation
context_object_name = 'project'
success_url = reverse_lazy('projects-main')