Commit c45e457749ebd8e18100ca1a8eefd917042acb06
1 parent
16befc88
Exists in
master
and in
5 other branches
Add subject view log [Issue: #247]
Showing
1 changed file
with
28 additions
and
1 deletions
Show diff stats
courses/views.py
@@ -15,6 +15,7 @@ from rolepermissions.verifications import has_object_permission | @@ -15,6 +15,7 @@ from rolepermissions.verifications import has_object_permission | ||
15 | from django.http import HttpResponseRedirect, JsonResponse | 15 | from django.http import HttpResponseRedirect, JsonResponse |
16 | from .forms import CourseForm, UpdateCourseForm, CategoryCourseForm, SubjectForm,TopicForm,ActivityForm | 16 | from .forms import CourseForm, UpdateCourseForm, CategoryCourseForm, SubjectForm,TopicForm,ActivityForm |
17 | from .models import Course, Subject, CourseCategory,Topic, SubjectCategory,Activity, CategorySubject | 17 | from .models import Course, Subject, CourseCategory,Topic, SubjectCategory,Activity, CategorySubject |
18 | +from core.decorators import log_decorator | ||
18 | from core.mixins import LogMixin, NotificationMixin | 19 | from core.mixins import LogMixin, NotificationMixin |
19 | from users.models import User | 20 | from users.models import User |
20 | from files.forms import FileForm | 21 | from files.forms import FileForm |
@@ -397,12 +398,23 @@ class DeleteView(LoginRequiredMixin, HasRoleMixin, NotificationMixin, generic.De | @@ -397,12 +398,23 @@ class DeleteView(LoginRequiredMixin, HasRoleMixin, NotificationMixin, generic.De | ||
397 | return self.response_class(request=self.request, template=self.get_template_names(), context=context, using=self.template_engine) | 398 | return self.response_class(request=self.request, template=self.get_template_names(), context=context, using=self.template_engine) |
398 | 399 | ||
399 | @login_required | 400 | @login_required |
401 | +@log_decorator("course", "subscribe", "course") | ||
400 | def subscribe_course(request, slug): | 402 | def subscribe_course(request, slug): |
401 | course = get_object_or_404(Course, slug = slug) | 403 | course = get_object_or_404(Course, slug = slug) |
402 | 404 | ||
403 | course.students.add(request.user) | 405 | course.students.add(request.user) |
404 | 406 | ||
405 | if request.user in course.students.all(): | 407 | if request.user in course.students.all(): |
408 | + | ||
409 | + log_context = {} | ||
410 | + log_context['course_id'] = course.id | ||
411 | + log_context['course_name'] = course.name | ||
412 | + log_context['course_slug'] = course.slug | ||
413 | + log_context['course_category_id'] = course.category.id | ||
414 | + log_context['course_category_name'] = course.category.name | ||
415 | + | ||
416 | + request.log_context = log_context | ||
417 | + | ||
406 | return JsonResponse({"status": "ok", "message": _("Successfully subscribed to the course!")}) | 418 | return JsonResponse({"status": "ok", "message": _("Successfully subscribed to the course!")}) |
407 | else: | 419 | else: |
408 | return JsonResponse({"status": "erro", "message": _("An error has occured. Could not subscribe to this course, try again later")}) | 420 | return JsonResponse({"status": "erro", "message": _("An error has occured. Could not subscribe to this course, try again later")}) |
@@ -504,7 +516,11 @@ class DeleteCatView(LoginRequiredMixin, HasRoleMixin, generic.DeleteView): | @@ -504,7 +516,11 @@ class DeleteCatView(LoginRequiredMixin, HasRoleMixin, generic.DeleteView): | ||
504 | messages.success(self.request, _('Category deleted successfully!')) | 516 | messages.success(self.request, _('Category deleted successfully!')) |
505 | return reverse_lazy('course:manage_cat') | 517 | return reverse_lazy('course:manage_cat') |
506 | 518 | ||
507 | -class SubjectsView(LoginRequiredMixin, generic.ListView): | 519 | +class SubjectsView(LoginRequiredMixin, LogMixin, generic.ListView): |
520 | + log_component = "course" | ||
521 | + log_resource = "subject" | ||
522 | + log_action = "viewed" | ||
523 | + log_context = {} | ||
508 | 524 | ||
509 | login_url = reverse_lazy("core:home") | 525 | login_url = reverse_lazy("core:home") |
510 | redirect_field_name = 'next' | 526 | redirect_field_name = 'next' |
@@ -518,6 +534,17 @@ class SubjectsView(LoginRequiredMixin, generic.ListView): | @@ -518,6 +534,17 @@ class SubjectsView(LoginRequiredMixin, generic.ListView): | ||
518 | if(not has_object_permission('view_subject', self.request.user, subject)): | 534 | if(not has_object_permission('view_subject', self.request.user, subject)): |
519 | return self.handle_no_permission() | 535 | return self.handle_no_permission() |
520 | 536 | ||
537 | + self.log_context['subject_id'] = subject.id | ||
538 | + self.log_context['subject_name'] = subject.name | ||
539 | + self.log_context['subject_slug'] = subject.slug | ||
540 | + self.log_context['course_id'] = subject.course.id | ||
541 | + self.log_context['course_name'] = subject.course.name | ||
542 | + self.log_context['course_slug'] = subject.course.slug | ||
543 | + self.log_context['course_category_id'] = subject.course.category.id | ||
544 | + self.log_context['course_category_name'] = subject.course.category.name | ||
545 | + | ||
546 | + super(SubjectsView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | ||
547 | + | ||
521 | return super(SubjectsView, self).dispatch(*args, **kwargs) | 548 | return super(SubjectsView, self).dispatch(*args, **kwargs) |
522 | 549 | ||
523 | def get_queryset(self): | 550 | def get_queryset(self): |