Commit 6e69b2da88682ee3e6cdbcc85cc0ed6d2c2465c5
1 parent
d9558c49
Exists in
master
and in
3 other branches
Adding file link log
Showing
2 changed files
with
89 additions
and
7 deletions
Show diff stats
file_link/views.py
@@ -9,6 +9,8 @@ from django.contrib.auth.mixins import LoginRequiredMixin | @@ -9,6 +9,8 @@ from django.contrib.auth.mixins import LoginRequiredMixin | ||
9 | 9 | ||
10 | from amadeus.permissions import has_subject_permissions, has_resource_permissions | 10 | from amadeus.permissions import has_subject_permissions, has_resource_permissions |
11 | 11 | ||
12 | +from log.mixins import LogMixin | ||
13 | + | ||
12 | from topics.models import Topic | 14 | from topics.models import Topic |
13 | 15 | ||
14 | from pendencies.forms import PendenciesForm | 16 | from pendencies.forms import PendenciesForm |
@@ -16,7 +18,12 @@ from pendencies.forms import PendenciesForm | @@ -16,7 +18,12 @@ from pendencies.forms import PendenciesForm | ||
16 | from .forms import FileLinkForm | 18 | from .forms import FileLinkForm |
17 | from .models import FileLink | 19 | from .models import FileLink |
18 | 20 | ||
19 | -class DownloadFile(LoginRequiredMixin, generic.DetailView): | 21 | +class DownloadFile(LoginRequiredMixin, LogMixin, generic.DetailView): |
22 | + log_component = 'resources' | ||
23 | + log_action = 'view' | ||
24 | + log_resource = 'file_link' | ||
25 | + log_context = {} | ||
26 | + | ||
20 | login_url = reverse_lazy("users:login") | 27 | login_url = reverse_lazy("users:login") |
21 | redirect_field_name = 'next' | 28 | redirect_field_name = 'next' |
22 | 29 | ||
@@ -46,10 +53,30 @@ class DownloadFile(LoginRequiredMixin, generic.DetailView): | @@ -46,10 +53,30 @@ class DownloadFile(LoginRequiredMixin, generic.DetailView): | ||
46 | response['Content-Disposition'] = 'attachment; filename=%s' % file_link.name | 53 | response['Content-Disposition'] = 'attachment; filename=%s' % file_link.name |
47 | response['Content-Transfer-Encoding'] = 'binary' | 54 | response['Content-Transfer-Encoding'] = 'binary' |
48 | response['Content-Length'] = str(path.getsize(file_link.file_content.path)) | 55 | response['Content-Length'] = str(path.getsize(file_link.file_content.path)) |
56 | + | ||
57 | + self.log_context['category_id'] = file_link.topic.subject.category.id | ||
58 | + self.log_context['category_name'] = file_link.topic.subject.category.name | ||
59 | + self.log_context['category_slug'] = file_link.topic.subject.category.slug | ||
60 | + self.log_context['subject_id'] = file_link.topic.subject.id | ||
61 | + self.log_context['subject_name'] = file_link.topic.subject.name | ||
62 | + self.log_context['subject_slug'] = file_link.topic.subject.slug | ||
63 | + self.log_context['topic_id'] = file_link.topic.id | ||
64 | + self.log_context['topic_name'] = file_link.topic.name | ||
65 | + self.log_context['topic_slug'] = file_link.topic.slug | ||
66 | + self.log_context['file_link_id'] = file_link.id | ||
67 | + self.log_context['file_link_name'] = file_link.name | ||
68 | + self.log_context['file_link_slug'] = file_link.slug | ||
69 | + | ||
70 | + super(DownloadFile, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | ||
49 | 71 | ||
50 | return response | 72 | return response |
51 | 73 | ||
52 | -class CreateView(LoginRequiredMixin, generic.edit.CreateView): | 74 | +class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
75 | + log_component = 'resources' | ||
76 | + log_action = 'create' | ||
77 | + log_resource = 'file_link' | ||
78 | + log_context = {} | ||
79 | + | ||
53 | login_url = reverse_lazy("users:login") | 80 | login_url = reverse_lazy("users:login") |
54 | redirect_field_name = 'next' | 81 | redirect_field_name = 'next' |
55 | 82 | ||
@@ -127,6 +154,21 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView): | @@ -127,6 +154,21 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView): | ||
127 | if not pend_form.action == "": | 154 | if not pend_form.action == "": |
128 | pend_form.save() | 155 | pend_form.save() |
129 | 156 | ||
157 | + self.log_context['category_id'] = self.object.topic.subject.category.id | ||
158 | + self.log_context['category_name'] = self.object.topic.subject.category.name | ||
159 | + self.log_context['category_slug'] = self.object.topic.subject.category.slug | ||
160 | + self.log_context['subject_id'] = self.object.topic.subject.id | ||
161 | + self.log_context['subject_name'] = self.object.topic.subject.name | ||
162 | + self.log_context['subject_slug'] = self.object.topic.subject.slug | ||
163 | + self.log_context['topic_id'] = self.object.topic.id | ||
164 | + self.log_context['topic_name'] = self.object.topic.name | ||
165 | + self.log_context['topic_slug'] = self.object.topic.slug | ||
166 | + self.log_context['file_link_id'] = self.object.id | ||
167 | + self.log_context['file_link_name'] = self.object.name | ||
168 | + self.log_context['file_link_slug'] = self.object.slug | ||
169 | + | ||
170 | + super(CreateView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | ||
171 | + | ||
130 | return redirect(self.get_success_url()) | 172 | return redirect(self.get_success_url()) |
131 | 173 | ||
132 | def get_context_data(self, **kwargs): | 174 | def get_context_data(self, **kwargs): |
@@ -147,7 +189,12 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView): | @@ -147,7 +189,12 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView): | ||
147 | 189 | ||
148 | return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) | 190 | return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) |
149 | 191 | ||
150 | -class UpdateView(LoginRequiredMixin, generic.UpdateView): | 192 | +class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): |
193 | + log_component = 'resources' | ||
194 | + log_action = 'update' | ||
195 | + log_resource = 'file_link' | ||
196 | + log_context = {} | ||
197 | + | ||
151 | login_url = reverse_lazy("users:login") | 198 | login_url = reverse_lazy("users:login") |
152 | redirect_field_name = 'next' | 199 | redirect_field_name = 'next' |
153 | 200 | ||
@@ -221,6 +268,21 @@ class UpdateView(LoginRequiredMixin, generic.UpdateView): | @@ -221,6 +268,21 @@ class UpdateView(LoginRequiredMixin, generic.UpdateView): | ||
221 | if not pend_form.action == "": | 268 | if not pend_form.action == "": |
222 | pend_form.save() | 269 | pend_form.save() |
223 | 270 | ||
271 | + self.log_context['category_id'] = self.object.topic.subject.category.id | ||
272 | + self.log_context['category_name'] = self.object.topic.subject.category.name | ||
273 | + self.log_context['category_slug'] = self.object.topic.subject.category.slug | ||
274 | + self.log_context['subject_id'] = self.object.topic.subject.id | ||
275 | + self.log_context['subject_name'] = self.object.topic.subject.name | ||
276 | + self.log_context['subject_slug'] = self.object.topic.subject.slug | ||
277 | + self.log_context['topic_id'] = self.object.topic.id | ||
278 | + self.log_context['topic_name'] = self.object.topic.name | ||
279 | + self.log_context['topic_slug'] = self.object.topic.slug | ||
280 | + self.log_context['file_link_id'] = self.object.id | ||
281 | + self.log_context['file_link_name'] = self.object.name | ||
282 | + self.log_context['file_link_slug'] = self.object.slug | ||
283 | + | ||
284 | + super(UpdateView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | ||
285 | + | ||
224 | return redirect(self.get_success_url()) | 286 | return redirect(self.get_success_url()) |
225 | 287 | ||
226 | def get_context_data(self, **kwargs): | 288 | def get_context_data(self, **kwargs): |
@@ -241,7 +303,12 @@ class UpdateView(LoginRequiredMixin, generic.UpdateView): | @@ -241,7 +303,12 @@ class UpdateView(LoginRequiredMixin, generic.UpdateView): | ||
241 | 303 | ||
242 | return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) | 304 | return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) |
243 | 305 | ||
244 | -class DeleteView(LoginRequiredMixin, generic.DeleteView): | 306 | +class DeleteView(LoginRequiredMixin, LogMixin, generic.DeleteView): |
307 | + log_component = 'resources' | ||
308 | + log_action = 'delete' | ||
309 | + log_resource = 'file_link' | ||
310 | + log_context = {} | ||
311 | + | ||
245 | login_url = reverse_lazy("users:login") | 312 | login_url = reverse_lazy("users:login") |
246 | redirect_field_name = 'next' | 313 | redirect_field_name = 'next' |
247 | 314 | ||
@@ -261,4 +328,19 @@ class DeleteView(LoginRequiredMixin, generic.DeleteView): | @@ -261,4 +328,19 @@ class DeleteView(LoginRequiredMixin, generic.DeleteView): | ||
261 | def get_success_url(self): | 328 | def get_success_url(self): |
262 | messages.success(self.request, _('The File Link "%s" was removed successfully from virtual environment "%s"!')%(self.object.name, self.object.topic.subject.name)) | 329 | messages.success(self.request, _('The File Link "%s" was removed successfully from virtual environment "%s"!')%(self.object.name, self.object.topic.subject.name)) |
263 | 330 | ||
331 | + self.log_context['category_id'] = self.object.topic.subject.category.id | ||
332 | + self.log_context['category_name'] = self.object.topic.subject.category.name | ||
333 | + self.log_context['category_slug'] = self.object.topic.subject.category.slug | ||
334 | + self.log_context['subject_id'] = self.object.topic.subject.id | ||
335 | + self.log_context['subject_name'] = self.object.topic.subject.name | ||
336 | + self.log_context['subject_slug'] = self.object.topic.subject.slug | ||
337 | + self.log_context['topic_id'] = self.object.topic.id | ||
338 | + self.log_context['topic_name'] = self.object.topic.name | ||
339 | + self.log_context['topic_slug'] = self.object.topic.slug | ||
340 | + self.log_context['file_link_id'] = self.object.id | ||
341 | + self.log_context['file_link_name'] = self.object.name | ||
342 | + self.log_context['file_link_slug'] = self.object.slug | ||
343 | + | ||
344 | + super(DeleteView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | ||
345 | + | ||
264 | return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) | 346 | return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) |
265 | \ No newline at end of file | 347 | \ No newline at end of file |
students_group/views.py
@@ -53,7 +53,7 @@ class IndexView(LoginRequiredMixin, generic.ListView): | @@ -53,7 +53,7 @@ class IndexView(LoginRequiredMixin, generic.ListView): | ||
53 | class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | 53 | class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
54 | log_component = 'students_group' | 54 | log_component = 'students_group' |
55 | log_action = 'create' | 55 | log_action = 'create' |
56 | - log_resource = 'students group' | 56 | + log_resource = 'students_group' |
57 | log_context = {} | 57 | log_context = {} |
58 | 58 | ||
59 | login_url = reverse_lazy("users:login") | 59 | login_url = reverse_lazy("users:login") |
@@ -144,7 +144,7 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | @@ -144,7 +144,7 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | ||
144 | class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): | 144 | class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): |
145 | log_component = 'students_group' | 145 | log_component = 'students_group' |
146 | log_action = 'update' | 146 | log_action = 'update' |
147 | - log_resource = 'students group' | 147 | + log_resource = 'students_group' |
148 | log_context = {} | 148 | log_context = {} |
149 | 149 | ||
150 | login_url = reverse_lazy("users:login") | 150 | login_url = reverse_lazy("users:login") |
@@ -196,7 +196,7 @@ class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): | @@ -196,7 +196,7 @@ class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): | ||
196 | class DeleteView(LoginRequiredMixin, LogMixin, generic.DeleteView): | 196 | class DeleteView(LoginRequiredMixin, LogMixin, generic.DeleteView): |
197 | log_component = 'students_group' | 197 | log_component = 'students_group' |
198 | log_action = 'delete' | 198 | log_action = 'delete' |
199 | - log_resource = 'students group' | 199 | + log_resource = 'students_group' |
200 | log_context = {} | 200 | log_context = {} |
201 | 201 | ||
202 | login_url = reverse_lazy("users:login") | 202 | login_url = reverse_lazy("users:login") |