Skip to content

Commit

Permalink
fix: added backend files
Browse files Browse the repository at this point in the history
  • Loading branch information
EwoutV committed May 2, 2024
1 parent 1bdb668 commit 195f93f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
5 changes: 3 additions & 2 deletions backend/api/serializers/group_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
from api.permissions.role_permissions import is_student
from api.models.group import Group
from api.models.student import Student
from api.serializers.project_serializer import ProjectSerializer
from api.serializers.student_serializer import StudentIDSerializer


class GroupSerializer(serializers.ModelSerializer):
project = serializers.HyperlinkedRelatedField(
many=False, read_only=True, view_name="project-detail"
project = ProjectSerializer(
read_only=True,
)

students = serializers.HyperlinkedIdentityField(
Expand Down
45 changes: 38 additions & 7 deletions backend/api/serializers/project_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from api.models.course import Course
from api.models.group import Group
from api.models.project import Project
from api.models.submission import Submission
from api.serializers.checks_serializer import StructureCheckSerializer
from api.serializers.course_serializer import CourseSerializer
from api.serializers.submission_serializer import SubmissionSerializer
Expand All @@ -15,9 +16,45 @@
from rest_framework.exceptions import ValidationError


class SubmissionStatusSerializer(serializers.Serializer):
non_empty_groups = serializers.IntegerField(read_only=True)
groups_submitted = serializers.IntegerField(read_only=True)
submissions_passed = serializers.IntegerField(read_only=True)

def to_representation(self, instance: Project):
"""Return the submission status of the project"""
if not isinstance(instance, Project):
raise ValidationError(gettext("project.errors.invalid_instance"))

non_empty_groups = instance.groups.filter(students__isnull=False).count()
groups_submitted = Submission.objects.filter(group__project=instance).count()
submissions_passed = Submission.objects.filter(group__project=instance, is_valid=True).count()

return {
"non_empty_groups": non_empty_groups,
"groups_submitted": groups_submitted,
"submissions_passed": submissions_passed,
}

class Meta:
fields = [
"non_empty_groups",
"groups_submitted",
"submissions_passed",
]


class ProjectSerializer(serializers.ModelSerializer):
# We want the course to be eager loaded
course = CourseSerializer(read_only=True)
course = CourseSerializer(
read_only=True
)

# We want the status to be eager loaded
status = SubmissionStatusSerializer(
source="*",
read_only=True
)

structure_checks = serializers.HyperlinkedIdentityField(
view_name="project-structure-checks",
Expand Down Expand Up @@ -131,12 +168,6 @@ class TeacherCreateGroupSerializer(serializers.Serializer):
number_groups = serializers.IntegerField(min_value=1)


class SubmissionStatusSerializer(serializers.Serializer):
non_empty_groups = serializers.IntegerField(read_only=True)
groups_submitted = serializers.IntegerField(read_only=True)
submissions_passed = serializers.IntegerField(read_only=True)


class SubmissionAddSerializer(SubmissionSerializer):
def validate(self, data):

Expand Down

0 comments on commit 195f93f

Please sign in to comment.