class ProfessorMessageSerializer(serializers.ModelSerializer):

    professor = TimtecUserSerializer(read_only=True)
    users_details = TimtecUserSerializer(many=True, source='users', read_only=True)

    class Meta:
        model = ProfessorMessage
        fields = ('id', 'users', 'users_details', 'users_that_read', 'course', 'subject', 'message', 'date', 'professor')
Beispiel #2
0
class ProfessorMessageSerializer(serializers.ModelSerializer):

    professor = TimtecUserSerializer(read_only=True)
    users_details = TimtecUserSerializer(many=True,
                                         source='users',
                                         read_only=True)
    users_that_read = TimtecUserSerializer(many=True, required=False)
    users_that_delete = TimtecUserSerializer(many=True, required=False)
    answers = MessageAnswerSerializer(many=True, read_only=True)

    class Meta:
        model = ProfessorMessage
        fields = ('id', 'users', 'users_details', 'users_that_read',
                  'users_that_delete', 'course', 'subject', 'message', 'date',
                  'professor', 'answers', 'get_absolute_url')
Beispiel #3
0
class CourseProfessorSerializer(serializers.ModelSerializer):

    user = serializers.PrimaryKeyRelatedField(
        queryset=get_user_model().objects.all(), required=False)
    user_info = TimtecUserSerializer(source='user', read_only=True)
    course_info = CourseSerializer(source='course', read_only=True)
    get_name = serializers.CharField(read_only=True)
    get_biography = serializers.CharField(read_only=True)
    get_picture_url = serializers.CharField(read_only=True)
    current_user_classes = ClassSerializer(source='get_current_user_classes',
                                           read_only=True,
                                           many=True)

    class Meta:
        fields = (
            'id',
            'course',
            'course_info',
            'user',
            'name',
            'biography',
            'picture',
            'user_info',
            'get_name',
            'get_biography',
            'get_picture_url',
            'role',
            'current_user_classes',
            'is_course_author',
        )
        model = CourseProfessor
Beispiel #4
0
class CourseProfessorSerializer(serializers.ModelSerializer):
    user_info = TimtecUserSerializer(source='user', read_only=True)
    course_info = CourseSerializer(source='course', read_only=True)
    get_name = serializers.Field()
    get_biography = serializers.Field()
    get_picture_url = serializers.Field()
    current_user_classes = ClassSerializer(source='get_current_user_classes',
                                           read_only=True)

    class Meta:
        fields = (
            'id',
            'course',
            'course_info',
            'user',
            'name',
            'biography',
            'picture',
            'user_info',
            'get_name',
            'get_biography',
            'get_picture_url',
            'role',
            'current_user_classes',
            'is_course_author',
        )
        model = CourseProfessor
Beispiel #5
0
class CourseStudentSerializer(serializers.ModelSerializer):
    user = TimtecUserSerializer(read_only=True)

    course_finished = serializers.BooleanField(source='course_finished')
    can_emmit_receipt = serializers.BooleanField(source='can_emmit_receipt')
    percent_progress = serializers.IntegerField(source='percent_progress')
    min_percent_to_complete = serializers.IntegerField(
        source='min_percent_to_complete')

    current_class = BaseClassSerializer(source='get_current_class')
    course = BaseCourseSerializer()
    certificate = CourseCertificationSerializer()

    class Meta:
        model = CourseStudent
        fields = (
            'id',
            'user',
            'course',
            'course_finished',
            'course',
            'certificate',
            'can_emmit_receipt',
            'percent_progress',
            'current_class',
            'min_percent_to_complete',
        )
class StudentProgressSerializer(serializers.ModelSerializer):
    complete = serializers.DateTimeField(required=False)
    user = TimtecUserSerializer(read_only=True, required=False)

    class Meta:
        model = StudentProgress
        fields = ('unit', 'complete', 'user',)
Beispiel #7
0
 def get_user(self, obj):
     if obj:
         from accounts.serializers import TimtecUserSerializer
         tus = TimtecUserSerializer(obj.user)
         return tus.data
     else:
         return u''
class ClassSerializer(serializers.ModelSerializer):
    students_detail = CourseStudentClassSerializer(source='get_students', many=True, read_only=True)
    processes = CertificationProcessSerializer(read_only=True, many=True)
    evaluations = EvaluationSerializer(read_only=True, many=True)
    course = CourseSerializer(read_only=True)
    assistant_detail = TimtecUserSerializer(read_only=True, source='assistant')

    class Meta:
        model = Class
Beispiel #9
0
class CourseAuthorSerializer(serializers.ModelSerializer):
    user_info = TimtecUserSerializer(source='user', read_only=True)
    course_info = CourseSerializer(source='course', read_only=True)
    get_name = serializers.Field()
    get_biography = serializers.Field()
    get_picture_url = serializers.Field()

    class Meta:
        fields = ('id', 'course', 'course_info', 'user', 'name', 'biography', 'picture', 'user_info',
                  'get_name', 'get_biography', 'get_picture_url', 'position')
        model = CourseAuthor
class CourseAuthorSerializer(serializers.ModelSerializer):
    user_info = TimtecUserSerializer(source='user', read_only=True)
    course_info = CourseSerializer(source='course', read_only=True)
    user = serializers.PrimaryKeyRelatedField(queryset=get_user_model().objects.all(), allow_null=True)
    get_name = serializers.ReadOnlyField()
    get_biography = serializers.ReadOnlyField()
    get_picture_url = serializers.ReadOnlyField()

    class Meta:
        fields = ('id', 'course', 'course_info', 'user', 'name', 'biography', 'picture', 'user_info',
                  'get_name', 'get_biography', 'get_picture_url', 'position')
        model = CourseAuthor
Beispiel #11
0
class CourseProfessorSerializer(serializers.ModelSerializer):
    user_info = TimtecUserSerializer(source='user', read_only=True)

    class Meta:
        fields = (
            'id',
            'course',
            'user',
            'user_info',
            'biography',
            'role',
        )
        model = CourseProfessor
Beispiel #12
0
class ClassSerializer(serializers.ModelSerializer):
    students = CourseStudentClassSerializer(source='get_students',
                                            many=True,
                                            read_only=True)
    processes = CertificationProcessSerializer(read_only=True, many=True)
    evaluations = EvaluationSerializer(read_only=True, many=True)
    course = CourseSerializer(read_only=True)
    assistant = TimtecUserSerializer(read_only=True)
    students_management = serializers.PrimaryKeyRelatedField(many=True,
                                                             read_only=False,
                                                             source='students')
    assistant_management = serializers.PrimaryKeyRelatedField(
        read_only=False, source='assistant', required=False)

    class Meta:
        model = Class
Beispiel #13
0
class ClassSerializer(serializers.ModelSerializer):
    students_details = CourseStudentClassSerializer(source='get_students',
                                                    many=True,
                                                    read_only=True)
    processes = CertificationProcessSerializer(read_only=True, many=True)
    evaluations = EvaluationSerializer(read_only=True, many=True)
    course = CourseSerializer(read_only=True)
    assistants = TimtecUserSerializer(read_only=True, many=True)

    class Meta:
        model = Class

    def update(self, instance, validated_data, **kwargs):
        assistants = self.context['request'].data.get('assistants', None)
        updated_class = super(ClassSerializer,
                              self).update(instance, validated_data)
        # If there are assistans to be associated with the class, do it now
        for assistant in assistants:
            updated_class.assistants.add(assistant['id'])
        return updated_class
Beispiel #14
0
class CourseSerializer(serializers.ModelSerializer):
    intro_video = VideoSerializer(required=False)
    thumbnail_url = serializers.Field(source='get_thumbnail_url')

    # TODO timtec theme specific: remove "professor_name" and "professor_names"
    professor_name = serializers.SerializerMethodField()
    professors_names = serializers.SerializerMethodField()

    has_started = serializers.Field()
    professors = TimtecUserSerializer(source="professors", read_only=True)
    home_thumbnail_url = serializers.SerializerMethodField()
    is_user_assistant = serializers.SerializerMethodField()
    is_user_coordinator = serializers.SerializerMethodField()
    is_assistant_or_coordinator = serializers.SerializerMethodField()

    class Meta:
        model = Course
        fields = (
            "id",
            "slug",
            "name",
            "intro_video",
            "application",
            "requirement",
            "abstract",
            "structure",
            "workload",
            "pronatec",
            "status",
            "thumbnail_url",
            "home_thumbnail_url",
            "home_position",
            "start_date",
            "home_published",
            "authors_names",
            "has_started",
            "min_percent_to_complete",
            "is_user_assistant",
            "is_user_coordinator",
            # TODO timtec theme specific: remove "professor_name" and "professor_names"
            "professor_name",
            "professor_names",
            "is_assistant_or_coordinator",
        )

    @staticmethod
    def get_professor_name(obj):
        if obj.professors.all():
            return obj.professors.all()[0]
        return ''

    @staticmethod
    def get_professors_names(obj):
        professors = obj.get_video_professors()
        if professors:
            if len(professors) > 1:
                return '{0} e {1}'.format(professors[0].user,
                                          professors[1].user)
            else:
                return professors[0].user
        return ''

    @staticmethod
    def get_home_thumbnail_url(obj):
        if obj.home_thumbnail:
            return obj.home_thumbnail.url
        return ''

    def get_is_user_assistant(self, obj):
        return obj.is_course_assistant(self.context['request'].user)

    def get_is_user_coordinator(self, obj):
        return obj.is_course_coordinator(self.context['request'].user)

    def get_is_assistant_or_coordinator(self, obj):
        return obj.is_assistant_or_coordinator(self.context['request'].user)
Beispiel #15
0
class CourseSerializer(serializers.ModelSerializer):
    # BUGFIX: intro_video needs to be read_only=False. This is a little workaround to make other modules work
    intro_video = VideoSerializer(required=False, allow_null=True)
    thumbnail_url = serializers.ReadOnlyField(source='get_thumbnail_url')

    has_started = serializers.ReadOnlyField()
    professors = TimtecUserSerializer(source='authors',
                                      many=True,
                                      read_only=True)
    course_professors = CourseProfessorAssistantSerializer(many=True,
                                                           read_only=True)
    home_thumbnail_url = serializers.SerializerMethodField()
    is_user_assistant = serializers.SerializerMethodField()
    is_user_coordinator = serializers.SerializerMethodField()
    is_assistant_or_coordinator = serializers.SerializerMethodField()

    class Meta:
        model = Course
        fields = ("id", "slug", "name", "intro_video", "application",
                  "requirement", "abstract", "structure", "workload",
                  "pronatec", "status", "thumbnail_url", "home_thumbnail_url",
                  "home_position", "start_date", "home_published",
                  "authors_names", "has_started", "min_percent_to_complete",
                  "is_user_assistant", "is_user_coordinator", 'professors',
                  "is_assistant_or_coordinator", 'welcome_email',
                  'total_hours', 'course_professors')

    def create(self, validated_data):
        intro_video = validated_data.pop('intro_video', None)
        new_course = super(CourseSerializer, self).create(validated_data)
        intro_video.save()
        new_course.intro_video = intro_video
        new_course.save()
        return new_course

    def update(self, instance, validated_data, **kwargs):
        intro_video = validated_data.pop('intro_video', None)
        updated_course = super(CourseSerializer,
                               self).update(instance, validated_data, **kwargs)
        if intro_video:
            try:
                intro_video, created = Video.objects.get_or_create(
                    **intro_video)
            except Video.MultipleObjectsReturned:
                intro_video = Video.objects.filter(**intro_video).first()

        updated_course.intro_video = intro_video
        updated_course.save()
        return updated_course

    @staticmethod
    def get_professor_name(obj):
        if obj.course_authors.all():
            return [author.get_name() for author in obj.course_authors.all()]
        return ''

    @staticmethod
    def get_professors_names(obj):
        professors = obj.get_video_professors()
        if professors:
            if len(professors) > 1:
                return '{0} e {1}'.format(professors[0].user,
                                          professors[1].user)
            else:
                return professors[0].user
        return ''

    @staticmethod
    def get_home_thumbnail_url(obj):
        if obj.home_thumbnail:
            return obj.home_thumbnail.url
        return ''

    def get_is_user_assistant(self, obj):
        return obj.is_course_assistant(self.context['request'].user)

    def get_is_user_coordinator(self, obj):
        return obj.is_course_coordinator(self.context['request'].user)

    def get_is_assistant_or_coordinator(self, obj):
        return obj.is_assistant_or_coordinator(self.context['request'].user)
Beispiel #16
0
class CourseStudentSerializer(serializers.ModelSerializer):
    user = TimtecUserSerializer()

    class Meta:
        model = CourseStudent