Commit a8c5394ea1c81fc14103c68a659af6e0df274c4a
1 parent
d57aa261
Exists in
master
and in
5 other branches
Changing log view function to store time spent in page [Issue: #231]
Showing
3 changed files
with
23 additions
and
3 deletions
Show diff stats
courses/views.py
... | ... | @@ -17,13 +17,14 @@ from .forms import CourseForm, UpdateCourseForm, CategoryCourseForm, SubjectForm |
17 | 17 | from .models import Course, Subject, CourseCategory,Topic, SubjectCategory,Activity, CategorySubject |
18 | 18 | from core.decorators import log_decorator |
19 | 19 | from core.mixins import LogMixin, NotificationMixin |
20 | +from core.models import Log | |
20 | 21 | from users.models import User |
21 | 22 | from files.forms import FileForm |
22 | 23 | from files.models import TopicFile |
23 | 24 | from courses.models import Material |
24 | 25 | from django.urls import reverse |
25 | 26 | |
26 | -from datetime import date | |
27 | +from datetime import date, datetime | |
27 | 28 | |
28 | 29 | class IndexView(LoginRequiredMixin, NotificationMixin, generic.ListView): |
29 | 30 | |
... | ... | @@ -343,6 +344,9 @@ class CourseView(LogMixin, NotificationMixin, generic.DetailView): |
343 | 344 | |
344 | 345 | super(CourseView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) |
345 | 346 | |
347 | + self.request.session['time_spent'] = str(datetime.now()) | |
348 | + self.request.session['log_id'] = Log.objects.latest('id').id | |
349 | + | |
346 | 350 | category_sub = self.kwargs.get('category', None) |
347 | 351 | |
348 | 352 | if has_role(self.request.user,'system_admin'): |
... | ... | @@ -547,6 +551,9 @@ class SubjectsView(LoginRequiredMixin, LogMixin, generic.ListView): |
547 | 551 | |
548 | 552 | super(SubjectsView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) |
549 | 553 | |
554 | + self.request.session['time_spent'] = str(datetime.now()) | |
555 | + self.request.session['log_id'] = Log.objects.latest('id').id | |
556 | + | |
550 | 557 | return super(SubjectsView, self).dispatch(*args, **kwargs) |
551 | 558 | |
552 | 559 | def get_queryset(self): |
... | ... | @@ -620,6 +627,9 @@ class TopicsView(LoginRequiredMixin, LogMixin, generic.ListView): |
620 | 627 | |
621 | 628 | super(TopicsView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) |
622 | 629 | |
630 | + self.request.session['time_spent'] = str(datetime.now()) | |
631 | + self.request.session['log_id'] = Log.objects.latest('id').id | |
632 | + | |
623 | 633 | return super(TopicsView, self).dispatch(*args, **kwargs) |
624 | 634 | |
625 | 635 | def get_queryset(self): |
... | ... | @@ -635,7 +645,7 @@ class TopicsView(LoginRequiredMixin, LogMixin, generic.ListView): |
635 | 645 | activitys = Activity.objects.filter(topic__name = topic.name) |
636 | 646 | students_activit = User.objects.filter(activities__in = Activity.objects.all()) |
637 | 647 | materials = Material.objects.filter(topic = topic) |
638 | - print(materials) | |
648 | + | |
639 | 649 | context['topic'] = topic |
640 | 650 | context['subject'] = topic.subject |
641 | 651 | context['activitys'] = activitys | ... | ... |
forum/views.py
... | ... | @@ -14,12 +14,14 @@ from rolepermissions.verifications import has_object_permission |
14 | 14 | |
15 | 15 | from .models import Forum, Post, PostAnswer |
16 | 16 | from courses.models import Topic |
17 | -from core.models import Action, Resource | |
17 | +from core.models import Action, Resource, Log | |
18 | 18 | |
19 | 19 | from .forms import ForumForm, PostForm, PostAnswerForm |
20 | 20 | |
21 | 21 | from core.mixins import LogMixin, NotificationMixin |
22 | 22 | |
23 | +import datetime | |
24 | + | |
23 | 25 | """ |
24 | 26 | Forum Section |
25 | 27 | """ |
... | ... | @@ -230,6 +232,9 @@ class ForumDetailView(LoginRequiredMixin, LogMixin, generic.DetailView): |
230 | 232 | |
231 | 233 | super(ForumDetailView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) |
232 | 234 | |
235 | + self.request.session['time_spent'] = str(datetime.datetime.now()) | |
236 | + self.request.session['log_id'] = Log.objects.latest('id').id | |
237 | + | |
233 | 238 | return super(ForumDetailView, self).dispatch(*args, **kwargs) |
234 | 239 | |
235 | 240 | def get_context_data(self, **kwargs): | ... | ... |
poll/views.py
... | ... | @@ -15,6 +15,7 @@ from .forms import PollForm |
15 | 15 | from .models import Poll, Answer, AnswersStudent |
16 | 16 | from core.mixins import LogMixin, NotificationMixin |
17 | 17 | from users.models import User |
18 | +from core.models import Log | |
18 | 19 | from courses.models import Course, Topic |
19 | 20 | |
20 | 21 | import datetime |
... | ... | @@ -48,6 +49,9 @@ class ViewPoll(LoginRequiredMixin, LogMixin, generic.DetailView): |
48 | 49 | |
49 | 50 | super(ViewPoll, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) |
50 | 51 | |
52 | + self.request.session['time_spent'] = str(datetime.datetime.now()) | |
53 | + self.request.session['log_id'] = Log.objects.latest('id').id | |
54 | + | |
51 | 55 | return poll |
52 | 56 | |
53 | 57 | def get_context_data(self, **kwargs): |
... | ... | @@ -62,6 +66,7 @@ class ViewPoll(LoginRequiredMixin, LogMixin, generic.DetailView): |
62 | 66 | context['status'] = False |
63 | 67 | else: |
64 | 68 | context['status'] = answered[0].status |
69 | + | |
65 | 70 | return context |
66 | 71 | |
67 | 72 | ... | ... |