Commit 0c6e462c6737d2437e94ae962e437238b11a3427
1 parent
3f4869fc
Exists in
master
and in
5 other branches
Adding topic crud log functions [Issue: #248]
Showing
1 changed file
with
62 additions
and
6 deletions
Show diff stats
courses/views.py
... | ... | @@ -588,7 +588,11 @@ class UploadMaterialView(LoginRequiredMixin, generic.edit.CreateView): |
588 | 588 | |
589 | 589 | return self.success_url |
590 | 590 | |
591 | -class TopicsView(LoginRequiredMixin, generic.ListView): | |
591 | +class TopicsView(LoginRequiredMixin, LogMixin, generic.ListView): | |
592 | + log_component = "course" | |
593 | + log_resource = "topic" | |
594 | + log_action = "viewed" | |
595 | + log_context = {} | |
592 | 596 | |
593 | 597 | login_url = reverse_lazy("core:home") |
594 | 598 | redirect_field_name = 'next' |
... | ... | @@ -602,6 +606,20 @@ class TopicsView(LoginRequiredMixin, generic.ListView): |
602 | 606 | if(not has_object_permission('view_topic', self.request.user, topic)): |
603 | 607 | return self.handle_no_permission() |
604 | 608 | |
609 | + self.log_context['topic_id'] = topic.id | |
610 | + self.log_context['topic_name'] = topic.name | |
611 | + self.log_context['topic_slug'] = topic.slug | |
612 | + self.log_context['subject_id'] = topic.subject.id | |
613 | + self.log_context['subject_name'] = topic.subject.name | |
614 | + self.log_context['subject_slug'] = topic.subject.slug | |
615 | + self.log_context['course_id'] = topic.subject.course.id | |
616 | + self.log_context['course_name'] = topic.subject.course.name | |
617 | + self.log_context['course_slug'] = topic.subject.course.slug | |
618 | + self.log_context['course_category_id'] = topic.subject.course.category.id | |
619 | + self.log_context['course_category_name'] = topic.subject.course.category.name | |
620 | + | |
621 | + super(TopicsView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
622 | + | |
605 | 623 | return super(TopicsView, self).dispatch(*args, **kwargs) |
606 | 624 | |
607 | 625 | def get_queryset(self): |
... | ... | @@ -624,13 +642,15 @@ class TopicsView(LoginRequiredMixin, generic.ListView): |
624 | 642 | context['students_activit'] = students_activit |
625 | 643 | context['materials'] = materials |
626 | 644 | context['form'] = ActivityForm |
627 | - | |
628 | - | |
629 | 645 | |
630 | 646 | return context |
631 | 647 | |
632 | 648 | |
633 | -class CreateTopicView(LoginRequiredMixin, HasRoleMixin, NotificationMixin, generic.edit.CreateView): | |
649 | +class CreateTopicView(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin, generic.edit.CreateView): | |
650 | + log_component = "course" | |
651 | + log_resource = "topic" | |
652 | + log_action = "create" | |
653 | + log_context = {} | |
634 | 654 | |
635 | 655 | allowed_roles = ['professor', 'system_admin'] |
636 | 656 | login_url = reverse_lazy("core:home") |
... | ... | @@ -660,10 +680,28 @@ class CreateTopicView(LoginRequiredMixin, HasRoleMixin, NotificationMixin, gener |
660 | 680 | super(CreateTopicView, self).createNotification("Topic "+ self.object.name + " was created", |
661 | 681 | resource_name=self.object.name, resource_link= reverse('course:view_topic',args=[self.object.slug]), |
662 | 682 | actor=self.request.user, users = self.object.subject.course.students.all() ) |
683 | + | |
684 | + self.log_context['topic_id'] = self.object.id | |
685 | + self.log_context['topic_name'] = self.object.name | |
686 | + self.log_context['topic_slug'] = self.object.slug | |
687 | + self.log_context['subject_id'] = self.object.subject.id | |
688 | + self.log_context['subject_name'] = self.object.subject.name | |
689 | + self.log_context['subject_slug'] = self.object.subject.slug | |
690 | + self.log_context['course_id'] = self.object.subject.course.id | |
691 | + self.log_context['course_name'] = self.object.subject.course.name | |
692 | + self.log_context['course_slug'] = self.object.subject.course.slug | |
693 | + self.log_context['course_category_id'] = self.object.subject.course.category.id | |
694 | + self.log_context['course_category_name'] = self.object.subject.course.category.name | |
695 | + | |
696 | + super(CreateTopicView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
663 | 697 | |
664 | 698 | return super(CreateTopicView, self).form_valid(form) |
665 | 699 | |
666 | -class UpdateTopicView(LoginRequiredMixin, HasRoleMixin, generic.UpdateView): | |
700 | +class UpdateTopicView(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.UpdateView): | |
701 | + log_component = "course" | |
702 | + log_resource = "topic" | |
703 | + log_action = "create" | |
704 | + log_context = {} | |
667 | 705 | |
668 | 706 | allowed_roles = ['professor','system_admin'] |
669 | 707 | login_url = reverse_lazy("core:home") |
... | ... | @@ -693,6 +731,25 @@ class UpdateTopicView(LoginRequiredMixin, HasRoleMixin, generic.UpdateView): |
693 | 731 | context['subjects'] = topic.subject.course.subjects.all() |
694 | 732 | return context |
695 | 733 | |
734 | + def form_valid(self, form): | |
735 | + self.object = form.save() | |
736 | + | |
737 | + self.log_context['topic_id'] = self.object.id | |
738 | + self.log_context['topic_name'] = self.object.name | |
739 | + self.log_context['topic_slug'] = self.object.slug | |
740 | + self.log_context['subject_id'] = self.object.subject.id | |
741 | + self.log_context['subject_name'] = self.object.subject.name | |
742 | + self.log_context['subject_slug'] = self.object.subject.slug | |
743 | + self.log_context['course_id'] = self.object.subject.course.id | |
744 | + self.log_context['course_name'] = self.object.subject.course.name | |
745 | + self.log_context['course_slug'] = self.object.subject.course.slug | |
746 | + self.log_context['course_category_id'] = self.object.subject.course.category.id | |
747 | + self.log_context['course_category_name'] = self.object.subject.course.category.name | |
748 | + | |
749 | + super(UpdateTopicView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
750 | + | |
751 | + return super(UpdateTopicView, self).form_valid(form) | |
752 | + | |
696 | 753 | class CreateSubjectView(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin, generic.edit.CreateView): |
697 | 754 | log_component = "course" |
698 | 755 | log_resource = "subject" |
... | ... | @@ -855,7 +912,6 @@ def subscribe_subject(request, slug): |
855 | 912 | |
856 | 913 | request.log_context = log_context |
857 | 914 | |
858 | - | |
859 | 915 | return JsonResponse({"status": "ok", "message": _("Successfully subscribed to the subject!")}) |
860 | 916 | else: |
861 | 917 | return JsonResponse({"status": "erro", "message": _("An error has occured. Could not subscribe to this subject, try again later")}) | ... | ... |