Commit d9558c49784fdc00b8a8b7b53f6ac3dc9ad8ab64
1 parent
3525260d
Exists in
master
and in
3 other branches
Adding webpages log
Showing
1 changed file
with
121 additions
and
6 deletions
Show diff stats
webpage/views.py
... | ... | @@ -7,6 +7,10 @@ from django.contrib.auth.mixins import LoginRequiredMixin |
7 | 7 | |
8 | 8 | from amadeus.permissions import has_subject_permissions, has_resource_permissions |
9 | 9 | |
10 | +import time | |
11 | +from log.models import Log | |
12 | +from log.mixins import LogMixin | |
13 | + | |
10 | 14 | from topics.models import Topic |
11 | 15 | |
12 | 16 | from pendencies.forms import PendenciesForm |
... | ... | @@ -14,7 +18,12 @@ from pendencies.forms import PendenciesForm |
14 | 18 | from .forms import WebpageForm |
15 | 19 | from .models import Webpage |
16 | 20 | |
17 | -class NewWindowView(LoginRequiredMixin, generic.DetailView): | |
21 | +class NewWindowView(LoginRequiredMixin, LogMixin, generic.DetailView): | |
22 | + log_component = 'resources' | |
23 | + log_action = 'view' | |
24 | + log_resource = 'webpage' | |
25 | + log_context = {} | |
26 | + | |
18 | 27 | login_url = reverse_lazy("users:login") |
19 | 28 | redirect_field_name = 'next' |
20 | 29 | |
... | ... | @@ -31,7 +40,35 @@ class NewWindowView(LoginRequiredMixin, generic.DetailView): |
31 | 40 | |
32 | 41 | return super(NewWindowView, self).dispatch(request, *args, **kwargs) |
33 | 42 | |
34 | -class InsideView(LoginRequiredMixin, generic.DetailView): | |
43 | + def get_context_data(self, **kwargs): | |
44 | + context = super(NewWindowView, self).get_context_data(**kwargs) | |
45 | + | |
46 | + self.log_context['category_id'] = self.object.topic.subject.category.id | |
47 | + self.log_context['category_name'] = self.object.topic.subject.category.name | |
48 | + self.log_context['category_slug'] = self.object.topic.subject.category.slug | |
49 | + self.log_context['subject_id'] = self.object.topic.subject.id | |
50 | + self.log_context['subject_name'] = self.object.topic.subject.name | |
51 | + self.log_context['subject_slug'] = self.object.topic.subject.slug | |
52 | + self.log_context['topic_id'] = self.object.topic.id | |
53 | + self.log_context['topic_name'] = self.object.topic.name | |
54 | + self.log_context['topic_slug'] = self.object.topic.slug | |
55 | + self.log_context['webpage_id'] = self.object.id | |
56 | + self.log_context['webpage_name'] = self.object.name | |
57 | + self.log_context['webpage_slug'] = self.object.slug | |
58 | + self.log_context['timestamp_start'] = str(int(time.time())) | |
59 | + | |
60 | + super(NewWindowView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
61 | + | |
62 | + self.request.session['log_id'] = Log.objects.latest('id').id | |
63 | + | |
64 | + return context | |
65 | + | |
66 | +class InsideView(LoginRequiredMixin, LogMixin, generic.DetailView): | |
67 | + log_component = 'resources' | |
68 | + log_action = 'view' | |
69 | + log_resource = 'webpage' | |
70 | + log_context = {} | |
71 | + | |
35 | 72 | login_url = reverse_lazy("users:login") |
36 | 73 | redirect_field_name = 'next' |
37 | 74 | |
... | ... | @@ -56,9 +93,32 @@ class InsideView(LoginRequiredMixin, generic.DetailView): |
56 | 93 | context['topic'] = self.object.topic |
57 | 94 | context['subject'] = self.object.topic.subject |
58 | 95 | |
96 | + self.log_context['category_id'] = self.object.topic.subject.category.id | |
97 | + self.log_context['category_name'] = self.object.topic.subject.category.name | |
98 | + self.log_context['category_slug'] = self.object.topic.subject.category.slug | |
99 | + self.log_context['subject_id'] = self.object.topic.subject.id | |
100 | + self.log_context['subject_name'] = self.object.topic.subject.name | |
101 | + self.log_context['subject_slug'] = self.object.topic.subject.slug | |
102 | + self.log_context['topic_id'] = self.object.topic.id | |
103 | + self.log_context['topic_name'] = self.object.topic.name | |
104 | + self.log_context['topic_slug'] = self.object.topic.slug | |
105 | + self.log_context['webpage_id'] = self.object.id | |
106 | + self.log_context['webpage_name'] = self.object.name | |
107 | + self.log_context['webpage_slug'] = self.object.slug | |
108 | + self.log_context['timestamp_start'] = str(int(time.time())) | |
109 | + | |
110 | + super(InsideView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
111 | + | |
112 | + self.request.session['log_id'] = Log.objects.latest('id').id | |
113 | + | |
59 | 114 | return context |
60 | 115 | |
61 | -class CreateView(LoginRequiredMixin, generic.edit.CreateView): | |
116 | +class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | |
117 | + log_component = 'resources' | |
118 | + log_action = 'create' | |
119 | + log_resource = 'webpage' | |
120 | + log_context = {} | |
121 | + | |
62 | 122 | login_url = reverse_lazy("users:login") |
63 | 123 | redirect_field_name = 'next' |
64 | 124 | |
... | ... | @@ -134,7 +194,22 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView): |
134 | 194 | pend_form.resource = self.object |
135 | 195 | |
136 | 196 | if not pend_form.action == "": |
137 | - pend_form.save() | |
197 | + pend_form.save() | |
198 | + | |
199 | + self.log_context['category_id'] = self.object.topic.subject.category.id | |
200 | + self.log_context['category_name'] = self.object.topic.subject.category.name | |
201 | + self.log_context['category_slug'] = self.object.topic.subject.category.slug | |
202 | + self.log_context['subject_id'] = self.object.topic.subject.id | |
203 | + self.log_context['subject_name'] = self.object.topic.subject.name | |
204 | + self.log_context['subject_slug'] = self.object.topic.subject.slug | |
205 | + self.log_context['topic_id'] = self.object.topic.id | |
206 | + self.log_context['topic_name'] = self.object.topic.name | |
207 | + self.log_context['topic_slug'] = self.object.topic.slug | |
208 | + self.log_context['webpage_id'] = self.object.id | |
209 | + self.log_context['webpage_name'] = self.object.name | |
210 | + self.log_context['webpage_slug'] = self.object.slug | |
211 | + | |
212 | + super(CreateView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
138 | 213 | |
139 | 214 | return redirect(self.get_success_url()) |
140 | 215 | |
... | ... | @@ -165,7 +240,12 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView): |
165 | 240 | |
166 | 241 | return success_url |
167 | 242 | |
168 | -class UpdateView(LoginRequiredMixin, generic.UpdateView): | |
243 | +class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): | |
244 | + log_component = 'resources' | |
245 | + log_action = 'update' | |
246 | + log_resource = 'webpage' | |
247 | + log_context = {} | |
248 | + | |
169 | 249 | login_url = reverse_lazy("users:login") |
170 | 250 | redirect_field_name = 'next' |
171 | 251 | |
... | ... | @@ -237,6 +317,21 @@ class UpdateView(LoginRequiredMixin, generic.UpdateView): |
237 | 317 | |
238 | 318 | if not pend_form.action == "": |
239 | 319 | pend_form.save() |
320 | + | |
321 | + self.log_context['category_id'] = self.object.topic.subject.category.id | |
322 | + self.log_context['category_name'] = self.object.topic.subject.category.name | |
323 | + self.log_context['category_slug'] = self.object.topic.subject.category.slug | |
324 | + self.log_context['subject_id'] = self.object.topic.subject.id | |
325 | + self.log_context['subject_name'] = self.object.topic.subject.name | |
326 | + self.log_context['subject_slug'] = self.object.topic.subject.slug | |
327 | + self.log_context['topic_id'] = self.object.topic.id | |
328 | + self.log_context['topic_name'] = self.object.topic.name | |
329 | + self.log_context['topic_slug'] = self.object.topic.slug | |
330 | + self.log_context['webpage_id'] = self.object.id | |
331 | + self.log_context['webpage_name'] = self.object.name | |
332 | + self.log_context['webpage_slug'] = self.object.slug | |
333 | + | |
334 | + super(UpdateView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
240 | 335 | |
241 | 336 | return redirect(self.get_success_url()) |
242 | 337 | |
... | ... | @@ -267,7 +362,12 @@ class UpdateView(LoginRequiredMixin, generic.UpdateView): |
267 | 362 | |
268 | 363 | return success_url |
269 | 364 | |
270 | -class DeleteView(LoginRequiredMixin, generic.DeleteView): | |
365 | +class DeleteView(LoginRequiredMixin, LogMixin, generic.DeleteView): | |
366 | + log_component = 'resources' | |
367 | + log_action = 'delete' | |
368 | + log_resource = 'webpage' | |
369 | + log_context = {} | |
370 | + | |
271 | 371 | login_url = reverse_lazy("users:login") |
272 | 372 | redirect_field_name = 'next' |
273 | 373 | |
... | ... | @@ -287,4 +387,19 @@ class DeleteView(LoginRequiredMixin, generic.DeleteView): |
287 | 387 | def get_success_url(self): |
288 | 388 | messages.success(self.request, _('The webpage "%s" was removed successfully from virtual environment "%s"!')%(self.object.name, self.object.topic.subject.name)) |
289 | 389 | |
390 | + self.log_context['category_id'] = self.object.topic.subject.category.id | |
391 | + self.log_context['category_name'] = self.object.topic.subject.category.name | |
392 | + self.log_context['category_slug'] = self.object.topic.subject.category.slug | |
393 | + self.log_context['subject_id'] = self.object.topic.subject.id | |
394 | + self.log_context['subject_name'] = self.object.topic.subject.name | |
395 | + self.log_context['subject_slug'] = self.object.topic.subject.slug | |
396 | + self.log_context['topic_id'] = self.object.topic.id | |
397 | + self.log_context['topic_name'] = self.object.topic.name | |
398 | + self.log_context['topic_slug'] = self.object.topic.slug | |
399 | + self.log_context['webpage_id'] = self.object.id | |
400 | + self.log_context['webpage_name'] = self.object.name | |
401 | + self.log_context['webpage_slug'] = self.object.slug | |
402 | + | |
403 | + super(DeleteView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
404 | + | |
290 | 405 | return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) |
291 | 406 | \ No newline at end of file | ... | ... |