Commit 548393a3 authored by Matheus Miranda's avatar Matheus Miranda
Browse files

[Classroom Status] Add serializer for user at reports

parent 0d7a1534
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.contrib.auth.models import Group, CourseStudent, Course, User
from rest_framework import serializers
......@@ -126,3 +126,45 @@ class UsersByClassSerializer(serializers.Serializer):
def get_groups(self, obj):
return ', '.join([group.name for group in obj.user.groups.all()])
class UserClassRoomStatsSerializer(serializers.ModelSerializer):
name = serializers.SerializerMethodField('get_full_name')
picture = serializers.SerializerMethodField('get_picture_url')
username = serializers.SerializerMethodField()
email = serializers.SerializerMethodField()
user_id = serializers.SerializerMethodField()
course_progress = serializers.SerializerMethodField('get_user_progress')
# forum_questions = serializers.SerializerMethodField('get_forum_questions')
# forum_answers = serializers.SerializerMethodField('get_forum_answers')
# lessons_stats = LessonUserStatsSerializer(many=True, allow_add_remove=False)
class Meta:
model = User
fields = ('name', 'username', 'email', 'user_id', 'course_progress', 'picture')
def get_full_name(self, obj):
return obj.get_full_name()
def get_picture_url(self, obj):
return obj.get_picture_thumb_url()
def get_username(self, obj):
return obj.username
def get_email(self, obj):
return obj.email
def get_user_id(self, obj):
return obj.id
def get_user_progress(self, obj):
return obj.percent_progress()
# def get_forum_questions(self, obj):
# return obj.forum_questions_by_lesson()
#
# def get_forum_answers(self, obj):
# return obj.forum_answers_by_lesson()
......@@ -19,6 +19,7 @@ from courses_learning_objects.models import LearningObject, Answer
from courses.reports.serializers import (
UserInDetailSerializer,
UsersByClassSerializer,
UserClassRoomStatsSerializer
)
User = get_user_model()
......@@ -309,7 +310,6 @@ class UserCourseStats(viewsets.ReadOnlyModelViewSet):
queryset = User.objects.all().order_by('name')
serializer_class = UserCourseStatsSerializer
filter_fields = ('group',)
# filter vai ser o group
permission_classes = [IsAuthenticated]
pagination_class = ReportPagination
filter_backends = [
......
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