Commit a80746e7920a858d80f56f8a47f930287620558f

Authored by fbormann
1 parent 8a84e6f7

added support for topicsview and createtopic #248

Showing 1 changed file with 32 additions and 2 deletions   Show diff stats
courses/views.py
@@ -586,7 +586,12 @@ class UploadMaterialView(LoginRequiredMixin, generic.edit.CreateView): @@ -586,7 +586,12 @@ class UploadMaterialView(LoginRequiredMixin, generic.edit.CreateView):
586 586
587 return self.success_url 587 return self.success_url
588 588
589 -class TopicsView(LoginRequiredMixin, generic.ListView): 589 +class TopicsView(LoginRequiredMixin, LogMixin, generic.ListView):
  590 +
  591 + log_component = "subject"
  592 + log_resource = "topic"
  593 + log_action = "viewed"
  594 + log_context = {}
590 595
591 login_url = reverse_lazy("core:home") 596 login_url = reverse_lazy("core:home")
592 redirect_field_name = 'next' 597 redirect_field_name = 'next'
@@ -623,10 +628,24 @@ class TopicsView(LoginRequiredMixin, generic.ListView): @@ -623,10 +628,24 @@ class TopicsView(LoginRequiredMixin, generic.ListView):
623 context['materials'] = materials 628 context['materials'] = materials
624 context['form'] = ActivityForm 629 context['form'] = ActivityForm
625 630
  631 + self.log_context['subject_id'] = topic.subject.id
  632 + self.log_context['subject_name'] = topic.subject.name
  633 + self.log_context['subject_slug'] = topic.subject.slug
  634 + self.log_context['topic_id'] = topic.id
  635 + self.log_context['topic_name'] = topic.name
  636 + self.log_context['topic_slug'] = topic.slug
  637 +
  638 + super(TopicsView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context)
  639 +
  640 +
626 return context 641 return context
627 642
628 643
629 -class CreateTopicView(LoginRequiredMixin, HasRoleMixin, NotificationMixin, generic.edit.CreateView): 644 +class CreateTopicView(LoginRequiredMixin, LogMixin, HasRoleMixin, NotificationMixin, generic.edit.CreateView):
  645 + log_component = "subject"
  646 + log_resource = "topic"
  647 + log_action = "created"
  648 + log_context = {}
630 649
631 allowed_roles = ['professor', 'system_admin'] 650 allowed_roles = ['professor', 'system_admin']
632 login_url = reverse_lazy("core:home") 651 login_url = reverse_lazy("core:home")
@@ -643,6 +662,8 @@ class CreateTopicView(LoginRequiredMixin, HasRoleMixin, NotificationMixin, gener @@ -643,6 +662,8 @@ class CreateTopicView(LoginRequiredMixin, HasRoleMixin, NotificationMixin, gener
643 context['course'] = subject.course 662 context['course'] = subject.course
644 context['subject'] = subject 663 context['subject'] = subject
645 context['subjects'] = subject.course.subjects.all() 664 context['subjects'] = subject.course.subjects.all()
  665 +
  666 +
646 return context 667 return context
647 668
648 def form_valid(self, form): 669 def form_valid(self, form):
@@ -656,7 +677,16 @@ class CreateTopicView(LoginRequiredMixin, HasRoleMixin, NotificationMixin, gener @@ -656,7 +677,16 @@ class CreateTopicView(LoginRequiredMixin, HasRoleMixin, NotificationMixin, gener
656 super(CreateTopicView, self).createNotification("Topic "+ self.object.name + " was created", 677 super(CreateTopicView, self).createNotification("Topic "+ self.object.name + " was created",
657 resource_name=self.object.name, resource_link= reverse('course:view_topic',args=[self.object.slug]), 678 resource_name=self.object.name, resource_link= reverse('course:view_topic',args=[self.object.slug]),
658 actor=self.request.user, users = self.object.subject.course.students.all() ) 679 actor=self.request.user, users = self.object.subject.course.students.all() )
  680 +
659 681
  682 + self.log_context['subject_id'] = subject.id
  683 + self.log_context['subject_name'] = subject.name
  684 + self.log_context['subject_slug'] = subject.slug
  685 + self.log_context['topic_id'] = self.object.id
  686 +
  687 + super(CreateTopicView, self).createLog(self.request.user, self.log_component,
  688 + self.log_action, self.log_resource, self.log_context)
  689 +
660 return super(CreateTopicView, self).form_valid(form) 690 return super(CreateTopicView, self).form_valid(form)
661 691
662 class UpdateTopicView(LoginRequiredMixin, HasRoleMixin, generic.UpdateView): 692 class UpdateTopicView(LoginRequiredMixin, HasRoleMixin, generic.UpdateView):