Commit b45e6281 authored by Bruno Martin's avatar Bruno Martin
Browse files

Merge branch 'develop'

parents f4a9b1ff b556cf22
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from rest_framework import serializers
......@@ -18,6 +19,7 @@ class UserInDetailSerializer(serializers.ModelSerializer):
'institution',
'city',
'occupation',
'groups',
'courses',
'date_joined',
'last_login',
......@@ -30,6 +32,7 @@ class UserInDetailSerializer(serializers.ModelSerializer):
topics_created = serializers.SerializerMethodField()
number_of_likes = serializers.SerializerMethodField()
courses = serializers.SerializerMethodField()
groups = serializers.SerializerMethodField()
def get_comments_created(self, obj):
return obj.comment_author.count()
......@@ -43,7 +46,7 @@ class UserInDetailSerializer(serializers.ModelSerializer):
# 'has_certificate': x.certificate.type == 'certificate',
'has_certificate': False,
'class_name': x.get_current_class().name
} for x in obj.course_students.all()]
} for x in obj.coursestudent_set.all()]
return needed_stuff
def get_topics_created(self, obj):
......@@ -52,6 +55,9 @@ class UserInDetailSerializer(serializers.ModelSerializer):
def get_number_of_likes(self, obj):
return obj.topiclike_set.count() + obj.commentlike_set.count()
def get_groups(self, obj):
return ', '.join([group.name for group in obj.groups.all()])
class UsersByClassSerializer(serializers.Serializer):
class Meta:
......@@ -69,6 +75,7 @@ class UsersByClassSerializer(serializers.Serializer):
'occupation',
# 'institution',
# 'has_certificate',
'groups',
))
cpf = serializers.SerializerMethodField()
......@@ -82,6 +89,7 @@ class UsersByClassSerializer(serializers.Serializer):
city = serializers.SerializerMethodField()
occupation = serializers.SerializerMethodField()
# institution = serializers.SerializerMethodField()
groups = serializers.SerializerMethodField()
def get_city(self, obj):
return obj.user.city
......@@ -115,3 +123,6 @@ class UsersByClassSerializer(serializers.Serializer):
def get_class_name(self, obj):
return obj.get_current_class().name
def get_groups(self, obj):
return ', '.join([group.name for group in obj.user.groups.all()])
......@@ -212,7 +212,7 @@ class UsersByGroupViewSet(PandasViewSet):
if groups is not None:
self.queryset = self.queryset.filter(groups__name__in=groups.split(','))
self.queryset = self.queryset.prefetch_related('groups', 'course_students')
self.queryset = self.queryset.prefetch_related('groups', 'coursestudent_set')
return self.queryset
......@@ -222,7 +222,7 @@ class UsersByGroupViewSet(PandasViewSet):
serializer = UserInDetailSerializer(queryset, many=True)
# in order to get the data in the wanted column form, I'll need to make some transformations
return Response(self.transform_data(serializer.data))
return self.update_pandas_headers(Response(self.transform_data(serializer.data)))
def transform_data(self, data):
response = []
......@@ -238,6 +238,10 @@ class UsersByGroupViewSet(PandasViewSet):
response.append(user)
return pd.DataFrame.from_dict(response)
def get_pandas_filename(self, request, format):
return 'Relatório de atividades dos usuários'
class UsersByClassViewSet(PandasViewSet):
......@@ -270,8 +274,8 @@ class UsersByClassViewSet(PandasViewSet):
queryset = self.get_queryset()
serializer = UsersByClassSerializer(queryset, many=True)
return Response(pd.DataFrame
.from_dict(self.transform_data(serializer.data)))
return self.update_pandas_headers(Response(pd.DataFrame
.from_dict(self.transform_data(serializer.data))))
# .set_index('cpf'))
def transform_data(self, data):
......@@ -286,3 +290,7 @@ class UsersByClassViewSet(PandasViewSet):
})
coursestudent.pop('percent_progress_by_lesson', None)
return data
def get_pandas_filename(self, request, format):
return 'Relatório de progresso dos usuários'
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