Commit 0982085f authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Update serializer to get access actions

parent 9cf0ba63
......@@ -5,7 +5,7 @@ from rest_framework import serializers
from django.utils import timezone
from datetime import timedelta
from courses.models import CourseStudent
from courses.models import CourseStudent, Classroom
from discussion.models import Comment, Topic, TopicLike, CommentLike
User = get_user_model()
......@@ -144,12 +144,14 @@ class UserStatsSerializer(serializers.ModelSerializer):
'accesses_count', 'topics', 'reactions', 'comments')
def get_last_access(self, obj):
count = obj.actor_actions.count()
return obj.actor_actions.last().timestamp if count else None
#group_id = self.context['group']
#group = Classroom.objects.get(id=group_id)
last_access_obj = obj.actor_actions.filter(verb='access').last()
return last_access_obj.timestamp if last_access_obj else ''
def get_accesses_count(self, obj):
time_delta = timezone.now() - timedelta(days=7)
return obj.actor_actions.filter(timestamp__gte=time_delta).count()
return obj.actor_actions.filter(verb='access', timestamp__gte=time_delta).count()
def get_topics(self, obj):
return Topic.objects.filter(author=obj).count()
......
......@@ -71,7 +71,7 @@ class ActionSerializer(serializers.ModelSerializer):
action_phrase = ''
action_phrase += obj.actor.name
action_phrase += obj.actor.name.split()[0]
action_phrase += (' ' + verbs.get(obj.verb))
if obj.target:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment