Commit cf3a3164dc80dda1839d90a1d2b0cb4dafc97443

Authored by fbormann
1 parent 330d3766

added suppor for log in file creation

Showing 1 changed file with 22 additions and 2 deletions   Show diff stats
files/views.py
... ... @@ -11,11 +11,13 @@ from .models import TopicFile
11 11 from .utils import mime_type_to_material_icons
12 12 from courses.models import Topic
13 13 from core.models import MimeType
14   -from core.mixins import NotificationMixin
  14 +from core.decorators import log_decorator
  15 +from core.mixins import NotificationMixin, LogMixin
15 16 from django.urls import reverse
16 17  
  18 +
17 19 # Create your views here.
18   -class CreateFile(LoginRequiredMixin, HasRoleMixin, NotificationMixin, generic.edit.CreateView):
  20 +class CreateFile(LoginRequiredMixin, LogMixin, HasRoleMixin, NotificationMixin, generic.edit.CreateView):
19 21 allowed_roles = ['professor', 'system_admin']
20 22 login_url = reverse_lazy("core:home")
21 23 redirect_field_name = 'next'
... ... @@ -24,6 +26,11 @@ class CreateFile(LoginRequiredMixin, HasRoleMixin, NotificationMixin, generic.ed
24 26 form_class = FileForm
25 27 success_url = reverse_lazy('course:file:render_file')
26 28  
  29 + log_component = "subject"
  30 + log_resource = "file"
  31 + log_action = "create"
  32 + log_context = {}
  33 +
27 34 def form_invalid(self, form, **kwargs):
28 35 context = super(CreateFile, self).form_invalid(form)
29 36 context.status_code = 400
... ... @@ -60,6 +67,18 @@ class CreateFile(LoginRequiredMixin, HasRoleMixin, NotificationMixin, generic.ed
60 67 # self.object.file_type = MimeType.objects.get(id = 1)
61 68  
62 69 self.object.save()
  70 + #CREATE LOG
  71 + self.log_context['topic_id'] = topic.id
  72 + self.log_context['topic_name'] = topic.name
  73 + self.log_context['topic_slug'] = topic.slug
  74 + self.log_context['subject_id'] = topic.subject.id
  75 + self.log_context['subject_name'] = topic.subject.name
  76 + self.log_context['subject_slug'] = topic.subject.slug
  77 +
  78 + super(CreateFile, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context)
  79 +
  80 +
  81 +
63 82 #CREATE NOTIFICATION
64 83 super(CreateFile, self).createNotification(message="uploaded a File "+ self.object.name, actor=self.request.user,
65 84 resource_name=self.object.name, resource_link= reverse('course:view_topic', args=[self.object.topic.slug]),
... ... @@ -84,6 +103,7 @@ class CreateFile(LoginRequiredMixin, HasRoleMixin, NotificationMixin, generic.ed
84 103  
85 104 return self.success_url
86 105  
  106 +#@log_decorator("topic","acessar","file")
87 107 def render_file(request, id):
88 108 template_name = 'files/render_file.html'
89 109 context = {
... ...