-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathviews.py
178 lines (141 loc) · 5.96 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
from django.shortcuts import render
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.shortcuts import render, get_object_or_404
from django.views.generic import (
ListView,
DetailView,
CreateView,
UpdateView,
DeleteView
)
from .models import *
from django.contrib.auth.models import User
from exercises.models import *
from videos.models import *
from users.models import *
class TopicListView(ListView):
model = Topic
template_name = 'lessons/topics.html' # <app>/<model>_<viewtype>.html
context_object_name = 'lessons'
ordering = ['-date_posted']
paginate_by = 1
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['accounts'] = Account.objects.all()
context['classes'] = Class.objects.all()
context['subjects'] = Subject.objects.all()
context['topics'] = Topic.objects.all()
context['videos'] = Video.objects.all()
context['lessons'] = Lesson.objects.all()
context['exercises'] = Exercise.objects.filter(status=1).order_by("-created_on")
context['results'] = Exercise_question.objects.all()
return context
class TopicDetailView(DetailView):
model = Topic
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['accounts'] = Account.objects.all()
context['classes'] = Class.objects.all()
context['subjects'] = Subject.objects.all()
context['topics'] = Topic.objects.all()
context['videos'] = Video.objects.all()
context['lessons'] = Lesson.objects.all()
context['exercises'] = Exercise.objects.filter(status=1).order_by("-created_on")
context['results'] = Exercise_question.objects.all()
return context
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['Lessons'] = Lesson.objects.all()
context['topics'] = Topic.objects.all()
return context
class LessonListView(ListView):
model = Lesson
template_name = 'lessons/lessons.html' # <app>/<model>_<viewtype>.html
context_object_name = 'lessons'
ordering = ['-date_posted']
paginate_by = 1
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['accounts'] = Account.objects.all()
context['classes'] = Class.objects.all()
context['subjects'] = Subject.objects.all()
context['topics'] = Topic.objects.all()
context['videos'] = Video.objects.all()
context['lessons'] = Lesson.objects.all()
context['exercises'] = Exercise.objects.filter(status=1).order_by("-created_on")
context['results'] = Exercise_question.objects.all()
return context
class LessonDetailView(DetailView):
model = Lesson
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['accounts'] = Account.objects.all()
context['classes'] = Class.objects.all()
context['subjects'] = Subject.objects.all()
context['topics'] = Topic.objects.all()
context['videos'] = Video.objects.all()
context['lessons'] = Lesson.objects.all()
context['exercises'] = Exercise.objects.filter(status=1).order_by("-created_on")
context['results'] = Exercise_question.objects.all()
return context
class TeacherLessonListView(ListView):
model = Lesson
template_name = 'lessons//teacher_lessons.html' # <app>/<model>_<viewtype>.html
context_object_name = 'lessons'
paginate_by = 5
def get_queryset(self):
user = get_object_or_404(User, username=self.kwargs.get('username'))
return Post.objects.filter(created_by=user).order_by('-date_posted')
class LessonCreateView(LoginRequiredMixin, CreateView):
model = Lesson
fields = '__all__'
def form_valid(self, form):
form.instance.created_by = self.request.user
return super().form_valid(form)
class LessonUpdateView(LoginRequiredMixin, UserPassesTestMixin, UpdateView):
model = Lesson
fields = '__all__'
def form_valid(self, form):
form.instance.created_by = self.request.user
return super().form_valid(form)
def test_func(self):
post = self.get_object()
if self.request.user == lesson.created_by:
return True
return False
class LessonDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):
model = Lesson
success_url = '/'
def test_func(self):
post = self.get_object()
if self.request.user == lesson.created_by:
return True
return False
class Lesson_exerciseListView(ListView):
model = Lesson_exercise
template_name = 'lessons/lesson_exercises.html' # <app>/<model>_<viewtype>.html
context_object_name = 'lessson_exercises'
ordering = ['-date_posted']
paginate_by = 5
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['classes'] = Class.objects.all()
context['subjects'] = Subject.objects.all()
context['Topics'] = Topic.objects.all()
context['lessons'] = Lesson.objects.all()
context['lesson_exercises'] = Lesson_exercise.objects.all()
context['results'] = Exercise_question.objects.all()
return context
class Lesson_exerciseDetailView(DetailView):
model = Lesson_exercise
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['classes'] = Class.objects.all()
context['subjects'] = Subject.objects.all()
context['Topics'] = Topic.objects.all()
context['lessons'] = Lesson.objects.all()
context['lesson_exercises'] = Lesson_exercise.objects.all()
context['results'] = Exercise_question.objects.all()
return context