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

add groups to general reports

parent d77bc470
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()])
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