Commit 8c6e0171 authored by Laury Bueno's avatar Laury Bueno
Browse files

[Reports] Exclude inactive users from SummaryViewSet results

parent 752b0569
......@@ -40,7 +40,7 @@ class SummaryViewSet(viewsets.ViewSet):
for course in courses:
stats[course.slug] = {
'name': course.name,
'user_count': course.course_students.count(),
'user_count': course.course_students.filter(user__is_active=True).count(),
'user_finished_course_count': 0,
'classes' : []
}
......@@ -54,7 +54,7 @@ class SummaryViewSet(viewsets.ViewSet):
activities[course.slug] = le_activities.count()
aux = Answer.objects \
.filter(activity__in=le_activities)\
.filter(activity__in=le_activities, user__is_active=True)\
.values('user')\
.order_by('user')\
.annotate(Count('user'))
......@@ -63,7 +63,7 @@ class SummaryViewSet(viewsets.ViewSet):
aux = StudentProgress.objects\
.exclude(complete=None) \
.filter(unit__lesson__course=course)\
.filter(unit__lesson__course=course, user__is_active=True)\
.values('user')\
.order_by('user').\
annotate(Count('user'))
......@@ -97,11 +97,11 @@ class SummaryViewSet(viewsets.ViewSet):
classes = Class.objects.filter(course__in=courses).prefetch_related('students').select_related('course')
for cclass in classes:
certified = cclass.get_students.filter(certificate__type='certificate').select_related('course', 'user')
not_certified = cclass.get_students.exclude(certificate__type='certificate').select_related('course', 'user')
certified = cclass.get_students.filter(certificate__type='certificate', user__is_active=True).select_related('course', 'user')
not_certified = cclass.get_students.exclude(certificate__type='certificate', user__is_active=False).select_related('course', 'user')
cclass_stats = {
'name': cclass.name,
'user_count': cclass.get_students.count(),
'user_count': cclass.get_students.filter(user__is_active=True).count(),
'certificate_count': certified.count(),
'user_finished': 0
}
......@@ -122,16 +122,17 @@ class SummaryViewSet(viewsets.ViewSet):
stats = list(stats.values())
users_director_total = User.objects.filter(groups__name='Diretor Escolar').count()
users_director_login = User.objects.filter(groups__name='Diretor Escolar').exclude(last_login=None).count()
users_coordinator_total = User.objects.filter(groups__name='Coordenação Pedagógica').count()
users_coordinator_login = User.objects.filter(groups__name='Coordenação Pedagógica').exclude(last_login=None).count()
users_technical_total = User.objects.filter(groups__name='Equipe Técnica').count()
users_technical_login = User.objects.filter(groups__name='Equipe Técnica').exclude(last_login=None).count()
users_formadores_total = User.objects.filter(groups__name='Formadores').count()
users_formadores_login = User.objects.filter(groups__name='Formadores').exclude(last_login=None).count()
users_apoio_total = User.objects.filter(groups__name='Apoio Pedagógico').count()
users_apoio_login = User.objects.filter(groups__name='Apoio Pedagógico').exclude(last_login=None).count()
users_active = User.objects.filter(is_active=True)
users_director_total = users_active.filter(groups__name='Diretor Escolar').count()
users_director_login = users_active.filter(groups__name='Diretor Escolar').exclude(last_login=None).count()
users_coordinator_total = users_active.filter(groups__name='Coordenação Pedagógica').count()
users_coordinator_login = users_active.filter(groups__name='Coordenação Pedagógica').exclude(last_login=None).count()
users_technical_total = users_active.filter(groups__name='Equipe Técnica').count()
users_technical_login = users_active.filter(groups__name='Equipe Técnica').exclude(last_login=None).count()
users_formadores_total = users_active.filter(groups__name='Formadores').count()
users_formadores_login = users_active.filter(groups__name='Formadores').exclude(last_login=None).count()
users_apoio_total = users_active.filter(groups__name='Apoio Pedagógico').count()
users_apoio_login = users_active.filter(groups__name='Apoio Pedagógico').exclude(last_login=None).count()
response = Response({
'users_director_total': users_director_total,
......@@ -144,10 +145,11 @@ class SummaryViewSet(viewsets.ViewSet):
'users_formadores_login': users_formadores_login,
'users_apoio_total': users_apoio_total,
'users_apoio_login': users_apoio_login,
'user_count': User.objects.count(),
'total_number_of_topics': Topic.objects.count(),
'total_number_of_comments': Comment.objects.count(),
'total_number_of_likes': TopicLike.objects.count() + CommentLike.objects.count(),
'user_count': User.objects.filter(is_active=True).count(),
'user_inactive_count': User.objects.filter(is_active=False).count(),
'total_number_of_topics': Topic.objects.filter(author__is_active=True).count(),
'total_number_of_comments': Comment.objects.filter(author__is_active=True).count(),
'total_number_of_likes': TopicLike.objects.filter(user__is_active=True).count() + CommentLike.objects.filter(user__is_active=True).count(),
'statistics_per_course': stats})
return response
......@@ -239,7 +241,7 @@ class UsersByGroupViewSet(PandasViewSet):
return pd.DataFrame.from_dict(response)
def get_pandas_filename(self, request, format):
return 'Relatório de atividades dos usuários'
......@@ -292,5 +294,5 @@ class UsersByClassViewSet(PandasViewSet):
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