Skip to content
Snippets Groups Projects
  • robinwilliam.hundt's avatar
    074f4c33
    First step towards REST + Vue Student Page · 074f4c33
    robinwilliam.hundt authored
    Backend
    - Added isStudent permission
    - Added serializers apropriate for StudentPage
    - Added api-endpoint urls
    - Added views regarding StudentPage
    - Migrated the Django Session Authentication to djangorestframework-jwt authentication
    
    Frontend
    - Migrated from vue-resource to axios because of better documentation & features
    - Added Login Component
    - Added First Part of StudentPage containing overview of exam and subissions
    
    Closes #41
    References #39
    074f4c33
    History
    First step towards REST + Vue Student Page
    robinwilliam.hundt authored
    Backend
    - Added isStudent permission
    - Added serializers apropriate for StudentPage
    - Added api-endpoint urls
    - Added views regarding StudentPage
    - Migrated the Django Session Authentication to djangorestframework-jwt authentication
    
    Frontend
    - Migrated from vue-resource to axios because of better documentation & features
    - Added Login Component
    - Added First Part of StudentPage containing overview of exam and subissions
    
    Closes #41
    References #39
serializers.py 1.38 KiB
from rest_framework import serializers
from core.models import Student, Submission, Feedback, ExamType

from core.models import Feedback, Student, Submission
=======
from rest_framework import serializers
from core.models import Student, Submission, Feedback, ExamType


class ExamSerializer(serializers.ModelSerializer):
    class Meta:
        model = ExamType
        fields = ('module_reference', 'total_score', 'pass_score', 'pass_only',)
>>>>>>> First step towards REST + Vue Student Page


class FeedbackSerializer(serializers.ModelSerializer):
    class Meta:
        model = Feedback
        fields = ('text', 'score')


class SubmissionSerializer(serializers.ModelSerializer):
    feedback = serializers.ReadOnlyField(source='feedback.text')
    score = serializers.ReadOnlyField(source='feedback.score')
    type = serializers.ReadOnlyField(source='type.name')
    full_score = serializers.ReadOnlyField(source='type.full_score')

    class Meta:
        model = Submission
        fields = ('type', 'text', 'feedback', 'score', 'full_score')


class StudentSerializer(serializers.ModelSerializer):
    name = serializers.ReadOnlyField(source='user.fullname')
    user = serializers.ReadOnlyField(source='user.username')
    exam = ExamSerializer()
    submissions = SubmissionSerializer(many=True)

    class Meta:
        model = Student
        fields = ('name', 'user', 'exam', 'submissions')