summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradityacp2020-11-07 18:54:15 +0530
committeradityacp2020-11-07 18:54:15 +0530
commitd09ff51b6c957137e705fee73f1808c6333eed7f (patch)
treea6e01c49a980809b1de0255aef040703f8ccde5c
parenteed832d8a67ab9c2cef874b43f73d14a48cd0c71 (diff)
downloadonline_test-d09ff51b6c957137e705fee73f1808c6333eed7f.tar.gz
online_test-d09ff51b6c957137e705fee73f1808c6333eed7f.tar.bz2
online_test-d09ff51b6c957137e705fee73f1808c6333eed7f.zip
Add additional model to store last access for lesson
-rw-r--r--stats/models.py13
-rw-r--r--stats/templates/view_lesson_tracking.html8
-rw-r--r--stats/views.py6
3 files changed, 22 insertions, 5 deletions
diff --git a/stats/models.py b/stats/models.py
index f2f1bce..95def40 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -13,12 +13,23 @@ class TrackLesson(models.Model):
lesson = models.ForeignKey(Lesson, on_delete=models.CASCADE)
current_time = models.CharField(max_length=100, default="00:00:00")
video_duration = models.CharField(max_length=100, default="00:00:00")
- last_access_time = models.DateTimeField(default=timezone.now)
creation_time = models.DateTimeField(auto_now_add=True)
class Meta:
unique_together = ('user', 'course', 'lesson')
+ def get_last_access_time_and_vists(self):
+ lesson_logs = self.lessonlog_set
+ last_access_time = None
+ if lesson_logs.exists():
+ last_access_time = lesson_logs.last().last_access_time
+ return last_access_time, lesson_logs.count()
+
def __str__(self):
return (f"Track {self.lesson} in {self.course} "
f"for {self.user.get_full_name()}")
+
+
+class LessonLog(models.Model):
+ track = models.ForeignKey(TrackLesson, on_delete=models.CASCADE)
+ last_access_time = models.DateTimeField(default=timezone.now)
diff --git a/stats/templates/view_lesson_tracking.html b/stats/templates/view_lesson_tracking.html
index fa891e3..7962410 100644
--- a/stats/templates/view_lesson_tracking.html
+++ b/stats/templates/view_lesson_tracking.html
@@ -47,20 +47,24 @@
<th>Student Name&nbsp;<i class="fa fa-sort"></i></th>
<th>Last access on&nbsp;<i class="fa fa-sort"></i></th>
<th>Started on&nbsp;<i class="fa fa-sort"></i></th>
- <th>Current Time&nbsp;<i class="fa fa-sort"></i></th>
+ <th>Current Duration&nbsp;<i class="fa fa-sort"></i></th>
<th>Video Duration&nbsp;<i class="fa fa-sort"></i></th>
<th>Percentage watched&nbsp;<i class="fa fa-sort"></i></th>
+ <th>Total visits&nbsp;<i class="fa fa-sort"></i></th>
</tr>
</thead>
{% for track in trackings %}
<tr>
<td>{{ forloop.counter0|add:objects.start_index }}</td>
<td>{{track.user.get_full_name}}</td>
- <td>{{track.last_access_time}}</td>
+ {% with track.get_last_access_time_and_vists as time_and_visits %}
+ <td>{{time_and_visits.0}}</td>
<td>{{track.creation_time}}</td>
<td>{{track.current_time}}</td>
<td>{{track.video_duration}}</td>
<td></td>
+ <td>{{time_and_visits.1}}</td>
+ {% endwith %}
</tr>
{% endfor %}
</table>
diff --git a/stats/views.py b/stats/views.py
index 3bfe9c3..f7c028f 100644
--- a/stats/views.py
+++ b/stats/views.py
@@ -7,7 +7,7 @@ from django.core.paginator import Paginator
from django.http import Http404
# Local Imports
-from stats.models import TrackLesson
+from stats.models import TrackLesson, LessonLog
from yaksh.models import Course
from yaksh.decorators import email_verified
@@ -27,7 +27,9 @@ def add_tracker(request, tracker_id):
if current_time:
track.current_time = current_time
track.video_duration = video_duration
- track.last_access_time = timezone.now()
+ LessonLog.objects.create(
+ track_id=track.id, last_access_time=timezone.now()
+ )
track.save()
success = True
else: