예제 #1
0
#!usr/bin/env python
# -*- coding:utf-8 -*-
# 内置模块
# 第三方模块
from rest_framework.response import Response
from rest_framework import serializers
# 本地库
from utils.base_modelview import get_base_modelviewset
# from ..models import StudentRecord
from rbac.models import UserInfo
from rbac.serializers.rbac import UserinfoSerializer
from utils.base_auth import BaseAuth
from utils.base_permission import ProvePermission

view_class = get_base_modelviewset(UserInfo)


class StudentListView(view_class):
    serializer_class = UserinfoSerializer
    authentication_classes = [
        BaseAuth,
    ]
    permission_classes = [
        ProvePermission,
    ]

    def list(self, request):
        teacher = request.user
        queryset = UserInfo.objects.filter(teacher=teacher)
        ser = self.serializer_class(queryset, many=True)
        return Response(ser.data)
예제 #2
0
#!usr/bin/env python
# -*- coding:utf-8 -*-
# 内置模块
# 第三方模块
from rest_framework.response import Response
from rest_framework import serializers
# 本地库
from utils.base_modelview import get_base_modelviewset
from student.models import Question
from rbac.models import UserInfo
from utils.base_auth import BaseAuth
from utils.base_permission import ProvePermission

view_class = get_base_modelviewset(Question)


class BaseSerializer(serializers.ModelSerializer):
    student_name = serializers.CharField(read_only=True,source='student.username')
    question_status = serializers.CharField(write_only=True)
    question_status_info = serializers.CharField(source="get_question_status_display",read_only=True)

    class Meta:
        model = Question
        fields = ['id','title','content','answer','question_status','student','teacher','student_name','question_status_info']





class TeacherAnswerView(view_class):
    serializer_class=BaseSerializer
예제 #3
0
#!usr/bin/env python
# -*- coding:utf-8 -*-
# 内置模块
# 第三方模块
from rest_framework.response import Response
from rest_framework import serializers
# 本地库
from utils.base_modelview import get_base_modelviewset
from student.models import Order
from rbac.models import UserInfo
from utils.base_pagination import BasePagination
from utils.base_auth import BaseAuth
from utils.base_permission import ProvePermission

view_class = get_base_modelviewset(Order)


class OrderView(view_class):
    pagination_class = BasePagination
    authentication_classes = [
        BaseAuth,
    ]
    permission_classes = [
        ProvePermission,
    ]
예제 #4
0
#!usr/bin/env python
# -*- coding:utf-8 -*-
# 内置模块
# 第三方模块
from rest_framework.response import Response
from rest_framework import serializers
# 本地库
from utils.base_modelview import get_base_modelviewset
from ..models import Article
from rbac.models import UserInfo
from utils.base_auth import BaseAuth
from utils.base_permission import ProvePermission

view_class = get_base_modelviewset(Article)


def get_serializer(model_class):
    class ModelSerializer(serializers.ModelSerializer):
        teacher_info = serializers.SerializerMethodField(read_only=True)
        teacher_name = serializers.CharField(source='teacher.username',
                                             read_only=True)

        def get_teacher_info(self, obj):
            qs = UserInfo.objects.filter(roles__in=[2])
            return [{
                'id': teacher.id,
                'username': teacher.username,
            } for teacher in qs]

        class Meta:
            model = model_class
예제 #5
0
#!usr/bin/env python
# -*- coding:utf-8 -*-
# 内置模块
# 第三方模块
from rest_framework.response import Response
from rest_framework import serializers
# 本地库
from utils.base_modelview import get_base_modelviewset
from ..models import StudentRecord
from rbac.models import UserInfo
from utils.base_auth import BaseAuth
from utils.base_permission import ProvePermission

view_class = get_base_modelviewset(StudentRecord)


class BaseSerializer(serializers.ModelSerializer):
    student_name = serializers.CharField(read_only=True,
                                         source='student.username')

    class Meta:
        model = StudentRecord
        fields = ['id', 'note', 'teacher', 'student', 'student_name', 'date']


class StudentRecordView(view_class):
    serializer_class = BaseSerializer
    authentication_classes = [
        BaseAuth,
    ]
    permission_classes = [
예제 #6
0
#!usr/bin/env python
# -*- coding:utf-8 -*-
# 内置模块
# 第三方模块
from rest_framework.response import Response
from rest_framework import serializers
# 本地库
from utils.base_modelview import get_base_modelviewset
from student.models import Course
from rbac.models import UserInfo

view_class = get_base_modelviewset(Course)


def get_serializer(model_class):
    class ModelSerializer(serializers.ModelSerializer):
        price_policy = serializers.SerializerMethodField(read_only=True)
        course_detail_id = serializers.IntegerField(source='coursedetail.pk',
                                                    read_only=True)

        def get_price_policy(self, obj):
            qs = obj.price_policy.all().order_by('price')
            return [{
                "id": obj.id,
                "price": obj.price,
                'valid_period': obj.get_valid_period_display()
            } for obj in qs]

        class Meta:
            model = model_class
            fields = [
# -*- coding:utf-8 -*-
# 内置模块
# 第三方模块
from rest_framework.response import Response
from rest_framework import serializers
from rest_framework.views import APIView
# 本地库
from utils.base_modelview import get_base_modelviewset
from teacher.models import Homework, HomeworkRecord
from rbac.models import UserInfo
from utils.base_response import BaseResponse
from ..forms.teacher_correction import HomeworkRecordForm
from utils.base_auth import BaseAuth
from utils.base_permission import ProvePermission

view_class = get_base_modelviewset(HomeworkRecord)


class BaseSerializer(serializers.ModelSerializer):
    student_name = serializers.CharField(read_only=True,
                                         source='student.username')
    homework_status = serializers.CharField(write_only=True)
    file = serializers.CharField(read_only=True)
    homework_status_info = serializers.CharField(
        source="get_homework_status_display", read_only=True)
    title = serializers.CharField(source="homework.title", read_only=True)

    class Meta:
        model = HomeworkRecord
        fields = [
            'id', 'title', 'student_name', 'homework_status', 'file',
예제 #8
0
#!usr/bin/env python
# -*- coding:utf-8 -*-
# 内置模块
# 第三方模块
from rest_framework.response import Response
from rest_framework import serializers
# 本地库
from utils.base_modelview import get_base_modelviewset
from student.models import Category
from rbac.models import UserInfo

view_class = get_base_modelviewset(Category)


class CategoryView(view_class):
    pass