def test_activity_summary(self): self.assertEqual( Answer.activity_summary(self.pltp, self.user)[State.NOT_STARTED], ['100.0', '2']) Answer.objects.create(pl=self.pltp.indexed_pl()[0], user=self.user, grade=10) self.assertEqual( Answer.activity_summary(self.pltp, self.user)[State.PART_SUCC], ['50.0', '1'])
def course_summary(self, request, activity): user = request.user activity_model = apps.get_model("activity", "Activity") activities = activity_model.objects.filter(teacher=user, parent=activity) students = list() for st in activity.student.all().distinct(): tp = list() for a in activities: if a.is_student(st): summary = Answer.activity_summary(a, user) tp.append({ 'state': [{ 'percent': summary[i][0], 'count': summary[i][1], 'class': i.template } for i in summary ], 'name': a.activity_data['title'], 'activity_name': a.name, 'id': a.id, }) students.append({ 'lastname': st.last_name, 'object': st, 'id': st.id, 'activities': tp, }) students = sorted(students, key=lambda k: k['lastname']) return render(request, 'activity/activity_type/course/teacher_dashboard.html', { 'state': [i for i in State if i != State.ERROR], 'name': activity.name, 'student': students, 'range_tp': range(len(activities)), 'course_id': activity.id, })