Commit 0d7a1534 authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Add class UserCourseStats

parent 08b818ab
......@@ -11,7 +11,7 @@ import pandas as pd
from discussion.models import Comment, CommentLike, Topic, TopicLike
from courses.models import Course, CourseStudent, StudentProgress
from courses.models import Course, CourseStudent, StudentProgress, User
from courses.classes.models import Class
from courses_learning_objects.models import LearningObject, Answer
......@@ -296,3 +296,55 @@ class UsersByClassViewSet(PandasViewSet):
def get_pandas_filename(self, request, format):
return 'Relatório de progresso dos usuários'
class ReportPagination(PageNumberPagination):
page_size = 50
page_size_query_param = 'page_size'
max_page_size = 100
class UserCourseStats(viewsets.ReadOnlyModelViewSet):
model = User
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 = [
search_fields = [
def get_queryset(self):
queryset = super(User, self).get_queryset().filter(is_active=True)
user = self.request.user
course_id = self.request.query_params.get('course')
role = None
role = self.request.user.teaching_courses.get(course__id=course_id).role
except ObjectDoesNotExist:
classes_id = self.request.query_params.getlist('classes')
# class passed as get paremeter
classes = Class.objects.filter(course=course_id)
if classes_id:
classes = classes.filter(id__in=classes_id)
queryset = queryset.filter(user__classes__in=classes)
if not ((role and role == 'coordinator') or self.request.user.is_staff or self.request.user.is_superuser):
# if user is not coordinator or admin, only show his classes
classes = classes.filter(assistants=user)
queryset = queryset.filter(user__classes__in=classes)
return queryset.select_related('user', 'course')
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