Commit a90179619012e56a7692c33550eccc57dac4bdb0

Authored by Zambom
1 parent f88db7da

Adding goals logs

Showing 1 changed file with 199 additions and 7 deletions   Show diff stats
goals/views.py
... ... @@ -6,6 +6,11 @@ from django.utils.translation import ugettext_lazy as _
6 6 from django.contrib.auth.mixins import LoginRequiredMixin
7 7 from django.forms import formset_factory, modelformset_factory
8 8  
  9 +from log.models import Log
  10 +from log.mixins import LogMixin
  11 +from log.decorators import log_decorator, log_decorator_ajax
  12 +import time
  13 +
9 14 from amadeus.permissions import has_subject_permissions, has_resource_permissions
10 15  
11 16 from topics.models import Topic
... ... @@ -52,7 +57,12 @@ class AnsweredReport(LoginRequiredMixin, generic.ListView):
52 57  
53 58 return context
54 59  
55   -class InsideView(LoginRequiredMixin, generic.ListView):
  60 +class InsideView(LoginRequiredMixin, LogMixin, generic.ListView):
  61 + log_component = "resources"
  62 + log_action = "view"
  63 + log_resource = "my_goals"
  64 + log_context = {}
  65 +
56 66 login_url = reverse_lazy("users:login")
57 67 redirect_field_name = 'next'
58 68  
... ... @@ -89,9 +99,32 @@ class InsideView(LoginRequiredMixin, generic.ListView):
89 99 context['topic'] = goals.topic
90 100 context['subject'] = goals.topic.subject
91 101  
  102 + self.log_context['category_id'] = goals.topic.subject.category.id
  103 + self.log_context['category_name'] = goals.topic.subject.category.name
  104 + self.log_context['category_slug'] = goals.topic.subject.category.slug
  105 + self.log_context['subject_id'] = goals.topic.subject.id
  106 + self.log_context['subject_name'] = goals.topic.subject.name
  107 + self.log_context['subject_slug'] = goals.topic.subject.slug
  108 + self.log_context['topic_id'] = goals.topic.id
  109 + self.log_context['topic_name'] = goals.topic.name
  110 + self.log_context['topic_slug'] = goals.topic.slug
  111 + self.log_context['goals_id'] = goals.id
  112 + self.log_context['goals_name'] = goals.name
  113 + self.log_context['goals_slug'] = goals.slug
  114 + self.log_context['timestamp_start'] = str(int(time.time()))
  115 +
  116 + super(InsideView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context)
  117 +
  118 + self.request.session['log_id'] = Log.objects.latest('id').id
  119 +
92 120 return context
93 121  
94   -class NewWindowSubmit(LoginRequiredMixin, generic.edit.CreateView):
  122 +class NewWindowSubmit(LoginRequiredMixin, LogMixin, generic.edit.CreateView):
  123 + log_component = "resources"
  124 + log_action = "submit"
  125 + log_resource = "goals"
  126 + log_context = {}
  127 +
95 128 login_url = reverse_lazy("users:login")
96 129 redirect_field_name = 'next'
97 130  
... ... @@ -121,6 +154,28 @@ class NewWindowSubmit(LoginRequiredMixin, generic.edit.CreateView):
121 154  
122 155 MyGoalsFormset = formset_factory(MyGoalsForm, extra = 0)
123 156 my_goals_formset = MyGoalsFormset(initial = [{'item': x.id, 'value': x.ref_value} for x in goals.item_goal.all()])
  157 +
  158 + self.log_action = "view"
  159 +
  160 + self.log_context['category_id'] = goals.topic.subject.category.id
  161 + self.log_context['category_name'] = goals.topic.subject.category.name
  162 + self.log_context['category_slug'] = goals.topic.subject.category.slug
  163 + self.log_context['subject_id'] = goals.topic.subject.id
  164 + self.log_context['subject_name'] = goals.topic.subject.name
  165 + self.log_context['subject_slug'] = goals.topic.subject.slug
  166 + self.log_context['topic_id'] = goals.topic.id
  167 + self.log_context['topic_name'] = goals.topic.name
  168 + self.log_context['topic_slug'] = goals.topic.slug
  169 + self.log_context['goals_id'] = goals.id
  170 + self.log_context['goals_name'] = goals.name
  171 + self.log_context['goals_slug'] = goals.slug
  172 + self.log_context['timestamp_start'] = str(int(time.time()))
  173 +
  174 + super(NewWindowSubmit, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context)
  175 +
  176 + self.request.session['log_id'] = Log.objects.latest('id').id
  177 +
  178 + self.log_context = {}
124 179  
125 180 return self.render_to_response(self.get_context_data(my_goals_formset = my_goals_formset))
126 181  
... ... @@ -173,9 +228,29 @@ class NewWindowSubmit(LoginRequiredMixin, generic.edit.CreateView):
173 228  
174 229 success_url = reverse_lazy('goals:view', kwargs = {'slug': slug})
175 230  
  231 + self.log_context['category_id'] = goals.topic.subject.category.id
  232 + self.log_context['category_name'] = goals.topic.subject.category.name
  233 + self.log_context['category_slug'] = goals.topic.subject.category.slug
  234 + self.log_context['subject_id'] = goals.topic.subject.id
  235 + self.log_context['subject_name'] = goals.topic.subject.name
  236 + self.log_context['subject_slug'] = goals.topic.subject.slug
  237 + self.log_context['topic_id'] = goals.topic.id
  238 + self.log_context['topic_name'] = goals.topic.name
  239 + self.log_context['topic_slug'] = goals.topic.slug
  240 + self.log_context['goals_id'] = goals.id
  241 + self.log_context['goals_name'] = goals.name
  242 + self.log_context['goals_slug'] = goals.slug
  243 +
  244 + super(NewWindowSubmit, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context)
  245 +
176 246 return success_url
177 247  
178   -class SubmitView(LoginRequiredMixin, generic.edit.CreateView):
  248 +class SubmitView(LoginRequiredMixin, LogMixin, generic.edit.CreateView):
  249 + log_component = "resources"
  250 + log_action = "submit"
  251 + log_resource = "goals"
  252 + log_context = {}
  253 +
179 254 login_url = reverse_lazy("users:login")
180 255 redirect_field_name = 'next'
181 256  
... ... @@ -205,6 +280,28 @@ class SubmitView(LoginRequiredMixin, generic.edit.CreateView):
205 280  
206 281 MyGoalsFormset = formset_factory(MyGoalsForm, extra = 0)
207 282 my_goals_formset = MyGoalsFormset(initial = [{'item': x.id, 'value': x.ref_value} for x in goals.item_goal.all()])
  283 +
  284 + self.log_action = "view"
  285 +
  286 + self.log_context['category_id'] = goals.topic.subject.category.id
  287 + self.log_context['category_name'] = goals.topic.subject.category.name
  288 + self.log_context['category_slug'] = goals.topic.subject.category.slug
  289 + self.log_context['subject_id'] = goals.topic.subject.id
  290 + self.log_context['subject_name'] = goals.topic.subject.name
  291 + self.log_context['subject_slug'] = goals.topic.subject.slug
  292 + self.log_context['topic_id'] = goals.topic.id
  293 + self.log_context['topic_name'] = goals.topic.name
  294 + self.log_context['topic_slug'] = goals.topic.slug
  295 + self.log_context['goals_id'] = goals.id
  296 + self.log_context['goals_name'] = goals.name
  297 + self.log_context['goals_slug'] = goals.slug
  298 + self.log_context['timestamp_start'] = str(int(time.time()))
  299 +
  300 + super(SubmitView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context)
  301 +
  302 + self.request.session['log_id'] = Log.objects.latest('id').id
  303 +
  304 + self.log_context = {}
208 305  
209 306 return self.render_to_response(self.get_context_data(my_goals_formset = my_goals_formset))
210 307  
... ... @@ -259,9 +356,29 @@ class SubmitView(LoginRequiredMixin, generic.edit.CreateView):
259 356  
260 357 success_url = reverse_lazy('goals:view', kwargs = {'slug': slug})
261 358  
  359 + self.log_context['category_id'] = goals.topic.subject.category.id
  360 + self.log_context['category_name'] = goals.topic.subject.category.name
  361 + self.log_context['category_slug'] = goals.topic.subject.category.slug
  362 + self.log_context['subject_id'] = goals.topic.subject.id
  363 + self.log_context['subject_name'] = goals.topic.subject.name
  364 + self.log_context['subject_slug'] = goals.topic.subject.slug
  365 + self.log_context['topic_id'] = goals.topic.id
  366 + self.log_context['topic_name'] = goals.topic.name
  367 + self.log_context['topic_slug'] = goals.topic.slug
  368 + self.log_context['goals_id'] = goals.id
  369 + self.log_context['goals_name'] = goals.name
  370 + self.log_context['goals_slug'] = goals.slug
  371 +
  372 + super(SubmitView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context)
  373 +
262 374 return success_url
263 375  
264   -class UpdateSubmit(LoginRequiredMixin, generic.UpdateView):
  376 +class UpdateSubmit(LoginRequiredMixin, LogMixin, generic.UpdateView):
  377 + log_component = "resources"
  378 + log_action = "update"
  379 + log_resource = "my_goals"
  380 + log_context = {}
  381 +
265 382 login_url = reverse_lazy("users:login")
266 383 redirect_field_name = 'next'
267 384  
... ... @@ -347,9 +464,29 @@ class UpdateSubmit(LoginRequiredMixin, generic.UpdateView):
347 464  
348 465 success_url = reverse_lazy('goals:view', kwargs = {'slug': slug})
349 466  
  467 + self.log_context['category_id'] = goals.topic.subject.category.id
  468 + self.log_context['category_name'] = goals.topic.subject.category.name
  469 + self.log_context['category_slug'] = goals.topic.subject.category.slug
  470 + self.log_context['subject_id'] = goals.topic.subject.id
  471 + self.log_context['subject_name'] = goals.topic.subject.name
  472 + self.log_context['subject_slug'] = goals.topic.subject.slug
  473 + self.log_context['topic_id'] = goals.topic.id
  474 + self.log_context['topic_name'] = goals.topic.name
  475 + self.log_context['topic_slug'] = goals.topic.slug
  476 + self.log_context['goals_id'] = goals.id
  477 + self.log_context['goals_name'] = goals.name
  478 + self.log_context['goals_slug'] = goals.slug
  479 +
  480 + super(UpdateSubmit, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context)
  481 +
350 482 return success_url
351 483  
352   -class CreateView(LoginRequiredMixin, generic.edit.CreateView):
  484 +class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView):
  485 + log_component = "resources"
  486 + log_action = "create"
  487 + log_resource = "goals"
  488 + log_context = {}
  489 +
353 490 login_url = reverse_lazy("users:login")
354 491 redirect_field_name = 'next'
355 492  
... ... @@ -452,6 +589,21 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView):
452 589  
453 590 g_order += 1
454 591  
  592 + self.log_context['category_id'] = self.object.topic.subject.category.id
  593 + self.log_context['category_name'] = self.object.topic.subject.category.name
  594 + self.log_context['category_slug'] = self.object.topic.subject.category.slug
  595 + self.log_context['subject_id'] = self.object.topic.subject.id
  596 + self.log_context['subject_name'] = self.object.topic.subject.name
  597 + self.log_context['subject_slug'] = self.object.topic.subject.slug
  598 + self.log_context['topic_id'] = self.object.topic.id
  599 + self.log_context['topic_name'] = self.object.topic.name
  600 + self.log_context['topic_slug'] = self.object.topic.slug
  601 + self.log_context['goals_id'] = self.object.id
  602 + self.log_context['goals_name'] = self.object.name
  603 + self.log_context['goals_slug'] = self.object.slug
  604 +
  605 + super(CreateView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context)
  606 +
455 607 return redirect(self.get_success_url())
456 608  
457 609 def get_context_data(self, **kwargs):
... ... @@ -481,7 +633,12 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView):
481 633  
482 634 return success_url
483 635  
484   -class UpdateView(LoginRequiredMixin, generic.UpdateView):
  636 +class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView):
  637 + log_component = "resources"
  638 + log_action = "update"
  639 + log_resource = "goals"
  640 + log_context = {}
  641 +
485 642 login_url = reverse_lazy("users:login")
486 643 redirect_field_name = 'next'
487 644  
... ... @@ -567,6 +724,21 @@ class UpdateView(LoginRequiredMixin, generic.UpdateView):
567 724  
568 725 g_order += 1
569 726  
  727 + self.log_context['category_id'] = self.object.topic.subject.category.id
  728 + self.log_context['category_name'] = self.object.topic.subject.category.name
  729 + self.log_context['category_slug'] = self.object.topic.subject.category.slug
  730 + self.log_context['subject_id'] = self.object.topic.subject.id
  731 + self.log_context['subject_name'] = self.object.topic.subject.name
  732 + self.log_context['subject_slug'] = self.object.topic.subject.slug
  733 + self.log_context['topic_id'] = self.object.topic.id
  734 + self.log_context['topic_name'] = self.object.topic.name
  735 + self.log_context['topic_slug'] = self.object.topic.slug
  736 + self.log_context['goals_id'] = self.object.id
  737 + self.log_context['goals_name'] = self.object.name
  738 + self.log_context['goals_slug'] = self.object.slug
  739 +
  740 + super(UpdateView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context)
  741 +
570 742 return redirect(self.get_success_url())
571 743  
572 744 def get_context_data(self, **kwargs):
... ... @@ -596,7 +768,12 @@ class UpdateView(LoginRequiredMixin, generic.UpdateView):
596 768  
597 769 return success_url
598 770  
599   -class DeleteView(LoginRequiredMixin, generic.DeleteView):
  771 +class DeleteView(LoginRequiredMixin, LogMixin, generic.DeleteView):
  772 + log_component = "resources"
  773 + log_action = "delete"
  774 + log_resource = "goals"
  775 + log_context = {}
  776 +
600 777 login_url = reverse_lazy("users:login")
601 778 redirect_field_name = 'next'
602 779  
... ... @@ -616,4 +793,19 @@ class DeleteView(LoginRequiredMixin, generic.DeleteView):
616 793 def get_success_url(self):
617 794 messages.success(self.request, _('The Goals specification of the thopic %s was removed successfully!')%(self.object.topic.name))
618 795  
  796 + self.log_context['category_id'] = self.object.topic.subject.category.id
  797 + self.log_context['category_name'] = self.object.topic.subject.category.name
  798 + self.log_context['category_slug'] = self.object.topic.subject.category.slug
  799 + self.log_context['subject_id'] = self.object.topic.subject.id
  800 + self.log_context['subject_name'] = self.object.topic.subject.name
  801 + self.log_context['subject_slug'] = self.object.topic.subject.slug
  802 + self.log_context['topic_id'] = self.object.topic.id
  803 + self.log_context['topic_name'] = self.object.topic.name
  804 + self.log_context['topic_slug'] = self.object.topic.slug
  805 + self.log_context['goals_id'] = self.object.id
  806 + self.log_context['goals_name'] = self.object.name
  807 + self.log_context['goals_slug'] = self.object.slug
  808 +
  809 + super(DeleteView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context)
  810 +
619 811 return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug})
620 812 \ No newline at end of file
... ...