Commit 7ca39e8e2f71be611c7671a6fe3e10a0ef927f40
1 parent
0c6e462c
Exists in
master
and in
5 other branches
Adding crud forum log functions [Issue: #243]
Showing
1 changed file
with
94 additions
and
7 deletions
Show diff stats
forum/views.py
... | ... | @@ -18,7 +18,7 @@ from core.models import Action, Resource |
18 | 18 | |
19 | 19 | from .forms import ForumForm, PostForm, PostAnswerForm |
20 | 20 | |
21 | -from core.mixins import NotificationMixin | |
21 | +from core.mixins import LogMixin, NotificationMixin | |
22 | 22 | |
23 | 23 | """ |
24 | 24 | Forum Section |
... | ... | @@ -44,7 +44,12 @@ class ForumIndex(LoginRequiredMixin, generic.ListView): |
44 | 44 | |
45 | 45 | return context |
46 | 46 | |
47 | -class CreateForumView(LoginRequiredMixin, HasRoleMixin, generic.edit.CreateView, NotificationMixin): | |
47 | +class CreateForumView(LoginRequiredMixin, HasRoleMixin, generic.edit.CreateView, LogMixin, NotificationMixin): | |
48 | + log_component = "forum" | |
49 | + log_action = "create" | |
50 | + log_resource = "forum" | |
51 | + log_context = {} | |
52 | + | |
48 | 53 | allowed_roles = ['professor', 'system_admin'] |
49 | 54 | |
50 | 55 | login_url = reverse_lazy("core:home") |
... | ... | @@ -67,14 +72,36 @@ class CreateForumView(LoginRequiredMixin, HasRoleMixin, generic.edit.CreateView, |
67 | 72 | super(CreateForumView, self).createNotification("Forum "+ self.object.name + " was created", |
68 | 73 | resource_name=self.object.name, resource_link= reverse('course:forum:view', args=[self.object.slug]), |
69 | 74 | actor=self.request.user, users = self.object.topic.subject.students.all() ) |
75 | + | |
76 | + self.log_context['forum_id'] = self.object.id | |
77 | + self.log_context['forum_name'] = self.object.name | |
78 | + self.log_context['topic_id'] = self.object.topic.id | |
79 | + self.log_context['topic_name'] = self.object.topic.name | |
80 | + self.log_context['topic_slug'] = self.object.topic.slug | |
81 | + self.log_context['subject_id'] = self.object.topic.subject.id | |
82 | + self.log_context['subject_name'] = self.object.topic.subject.name | |
83 | + self.log_context['subject_slug'] = self.object.topic.subject.slug | |
84 | + self.log_context['course_id'] = self.object.topic.subject.course.id | |
85 | + self.log_context['course_name'] = self.object.topic.subject.course.name | |
86 | + self.log_context['course_slug'] = self.object.topic.subject.course.slug | |
87 | + self.log_context['course_category_id'] = self.object.topic.subject.course.category.id | |
88 | + self.log_context['course_category_name'] = self.object.topic.subject.course.category.name | |
89 | + | |
90 | + super(CreateForumView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
91 | + | |
70 | 92 | return self.success_url |
71 | 93 | |
72 | 94 | def render_forum(request, forum): |
73 | 95 | last_forum = get_object_or_404(Forum, id = forum) |
74 | 96 | |
75 | - return JsonResponse({'url': str(reverse_lazy('course:forum:view', args = (), kwargs = {'slug': last_forum.slug})), 'forum_id': str(forum), 'name': str(last_forum.name)}) | |
97 | + return JsonResponse({'url': str(reverse_lazy('course:forum:view', args = (), kwargs = {'slug': last_forum.slug})), 'forum_id': str(forum), 'name': str(last_forum.name), 'message': _('Forum created successfully!')}) | |
98 | + | |
99 | +class UpdateForumView(LoginRequiredMixin, HasRoleMixin, generic.UpdateView, LogMixin): | |
100 | + log_component = "forum" | |
101 | + log_action = "update" | |
102 | + log_resource = "forum" | |
103 | + log_context = {} | |
76 | 104 | |
77 | -class UpdateForumView(LoginRequiredMixin, HasRoleMixin, generic.UpdateView): | |
78 | 105 | allowed_roles = ['professor', 'system_admin'] |
79 | 106 | |
80 | 107 | login_url = reverse_lazy("core:home") |
... | ... | @@ -97,6 +124,22 @@ class UpdateForumView(LoginRequiredMixin, HasRoleMixin, generic.UpdateView): |
97 | 124 | |
98 | 125 | def get_success_url(self): |
99 | 126 | self.success_url = reverse('course:forum:render_edit_forum', args = (self.object.id, )) |
127 | + | |
128 | + self.log_context['forum_id'] = self.object.id | |
129 | + self.log_context['forum_name'] = self.object.name | |
130 | + self.log_context['topic_id'] = self.object.topic.id | |
131 | + self.log_context['topic_name'] = self.object.topic.name | |
132 | + self.log_context['topic_slug'] = self.object.topic.slug | |
133 | + self.log_context['subject_id'] = self.object.topic.subject.id | |
134 | + self.log_context['subject_name'] = self.object.topic.subject.name | |
135 | + self.log_context['subject_slug'] = self.object.topic.subject.slug | |
136 | + self.log_context['course_id'] = self.object.topic.subject.course.id | |
137 | + self.log_context['course_name'] = self.object.topic.subject.course.name | |
138 | + self.log_context['course_slug'] = self.object.topic.subject.course.slug | |
139 | + self.log_context['course_category_id'] = self.object.topic.subject.course.category.id | |
140 | + self.log_context['course_category_name'] = self.object.topic.subject.course.category.name | |
141 | + | |
142 | + super(UpdateForumView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
100 | 143 | |
101 | 144 | return self.success_url |
102 | 145 | |
... | ... | @@ -108,7 +151,12 @@ def render_edit_forum(request, forum): |
108 | 151 | |
109 | 152 | return render(request, 'forum/render_forum.html', context) |
110 | 153 | |
111 | -class ForumDeleteView(LoginRequiredMixin, HasRoleMixin, generic.DeleteView): | |
154 | +class ForumDeleteView(LoginRequiredMixin, HasRoleMixin, generic.DeleteView, LogMixin): | |
155 | + log_component = "forum" | |
156 | + log_action = "delete" | |
157 | + log_resource = "forum" | |
158 | + log_context = {} | |
159 | + | |
112 | 160 | allowed_roles = ['professor', 'system_admin'] |
113 | 161 | |
114 | 162 | login_url = reverse_lazy("core:home") |
... | ... | @@ -116,7 +164,6 @@ class ForumDeleteView(LoginRequiredMixin, HasRoleMixin, generic.DeleteView): |
116 | 164 | |
117 | 165 | model = Forum |
118 | 166 | pk_url_kwarg = 'pk' |
119 | - success_url = reverse_lazy('course:forum:deleted_forum') | |
120 | 167 | |
121 | 168 | def dispatch(self, *args, **kwargs): |
122 | 169 | forum = get_object_or_404(Forum, id = self.kwargs.get('pk')) |
... | ... | @@ -126,10 +173,34 @@ class ForumDeleteView(LoginRequiredMixin, HasRoleMixin, generic.DeleteView): |
126 | 173 | |
127 | 174 | return super(ForumDeleteView, self).dispatch(*args, **kwargs) |
128 | 175 | |
176 | + def get_success_url(self): | |
177 | + self.log_context['forum_id'] = self.object.id | |
178 | + self.log_context['forum_name'] = self.object.name | |
179 | + self.log_context['topic_id'] = self.object.topic.id | |
180 | + self.log_context['topic_name'] = self.object.topic.name | |
181 | + self.log_context['topic_slug'] = self.object.topic.slug | |
182 | + self.log_context['subject_id'] = self.object.topic.subject.id | |
183 | + self.log_context['subject_name'] = self.object.topic.subject.name | |
184 | + self.log_context['subject_slug'] = self.object.topic.subject.slug | |
185 | + self.log_context['course_id'] = self.object.topic.subject.course.id | |
186 | + self.log_context['course_name'] = self.object.topic.subject.course.name | |
187 | + self.log_context['course_slug'] = self.object.topic.subject.course.slug | |
188 | + self.log_context['course_category_id'] = self.object.topic.subject.course.category.id | |
189 | + self.log_context['course_category_name'] = self.object.topic.subject.course.category.name | |
190 | + | |
191 | + super(ForumDeleteView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
192 | + | |
193 | + return reverse_lazy('course:forum:deleted_forum') | |
194 | + | |
129 | 195 | def forum_deleted(request): |
130 | 196 | return HttpResponse(_("Forum deleted successfully.")) |
131 | 197 | |
132 | -class ForumDetailView(LoginRequiredMixin, generic.DetailView): | |
198 | +class ForumDetailView(LoginRequiredMixin, LogMixin, generic.DetailView): | |
199 | + log_component = "forum" | |
200 | + log_action = "viewed" | |
201 | + log_resource = "forum" | |
202 | + log_context = {} | |
203 | + | |
133 | 204 | login_url = reverse_lazy("core:home") |
134 | 205 | redirect_field_name = 'next' |
135 | 206 | |
... | ... | @@ -143,6 +214,22 @@ class ForumDetailView(LoginRequiredMixin, generic.DetailView): |
143 | 214 | if(not has_object_permission('view_forum', self.request.user, forum)): |
144 | 215 | return self.handle_no_permission() |
145 | 216 | |
217 | + self.log_context['forum_id'] = forum.id | |
218 | + self.log_context['forum_name'] = forum.name | |
219 | + self.log_context['topic_id'] = forum.topic.id | |
220 | + self.log_context['topic_name'] = forum.topic.name | |
221 | + self.log_context['topic_slug'] = forum.topic.slug | |
222 | + self.log_context['subject_id'] = forum.topic.subject.id | |
223 | + self.log_context['subject_name'] = forum.topic.subject.name | |
224 | + self.log_context['subject_slug'] = forum.topic.subject.slug | |
225 | + self.log_context['course_id'] = forum.topic.subject.course.id | |
226 | + self.log_context['course_name'] = forum.topic.subject.course.name | |
227 | + self.log_context['course_slug'] = forum.topic.subject.course.slug | |
228 | + self.log_context['course_category_id'] = forum.topic.subject.course.category.id | |
229 | + self.log_context['course_category_name'] = forum.topic.subject.course.category.name | |
230 | + | |
231 | + super(ForumDetailView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
232 | + | |
146 | 233 | return super(ForumDetailView, self).dispatch(*args, **kwargs) |
147 | 234 | |
148 | 235 | def get_context_data(self, **kwargs): | ... | ... |