Exemplo n.º 1
0
    def extra(self, request, detail):
        response = True
        params = request.data
        curriculum = detail['curriculum']

        try:
            if 'lid' in params:
                curri = Curriculum.objects.filter(cls=curriculum.cls,
                                                  lesson=params['lid'])

                if curri.exists():
                    return ResponseContent(code=401,
                                           token=request.auth,
                                           description=10142,
                                           error=10142)

                courses = ClsCourse.objects.filter(
                    cls=params['oid'],
                    course__LessonCourse=params['lid'],
                    teacher=request.user.id)
                if not courses.exists():
                    return ResponseContent(code=401,
                                           token=request.auth,
                                           description=10601,
                                           error=10601)

        except Exception as e:
            return ResponseContent(code=604,
                                   token=request.auth,
                                   description=10523,
                                   error=e.__str__())

        return response
Exemplo n.º 2
0
    def post(self, request, *args, **kwargs):
        response = ResponseContent(mark=False,
                                   code=200,
                                   token=request.auth,
                                   description=12002)
        state = status.HTTP_200_OK

        detail = self.readiness(request)
        if isinstance(detail, ResponseContent):
            return Response(detail.content(),
                            status=status.HTTP_406_NOT_ACCEPTABLE)

        serializer = UserSerializer(
            detail['user'],
            data={'password': request.data['password']},
            partial=True)
        if serializer.is_valid():
            serializer.save()
        else:
            response.refresh(code=601,
                             description=12002,
                             error=serializer.errors)
            state = status.HTTP_501_NOT_IMPLEMENTED

        return Response(response.content(), status=state)
Exemplo n.º 3
0
 def exist_mao_record(self, params):
     response = ResponseContent(code=401, description=10149, error=10149)
     try:
         record = MaoRecord.objects.filter(id=params['mrcid'])
         if record.exists():
             response = record.first()
     except Exception as e:
         response.refresh(code=602, description=10817, error=e.__str__())
     return response
Exemplo n.º 4
0
 def exist_enroll(self, params):
     response = ResponseContent(code=401, description=10116, error=10116)
     try:
         enroll = ClsStudent.objects.filter(id=params['eid'])
         if enroll.exists():
             response = enroll.first()
     except Exception as e:
         response.refresh(code=602, description=10812, error=e.__str__())
     return response
Exemplo n.º 5
0
    def extra(self, request, detail):
        response = True
        params = request.data

        question = detail['question']
        homework = question.homework
        gametype = question.gametype
        gcid = question.gcid
        gsid = question.gsid
        idx = question.idx

        if 'gametype' in params:
            gametype = params['gametype']
        if 'gcid' in params:
            gcid = params['gcid']
        # if 'gsid' in params:
        #     gsid = params['gsid']
        if 'idx' in params:
            idx = params['idx']

        try:
            question = HomeworkDetail.objects.filter(
                id=params['qid'],
                homework__curriculum__lesson__course__ClsCourseCourse__teacher=
                request.user.id)

            if not question.exists():
                return ResponseContent(code=401,
                                       token=request.auth,
                                       description=10602,
                                       error=10602)

            # if 'gametype' in params or 'gcid' in params or 'gsid' in params:
            if 'gametype' in params or 'gcid' in params:
                condition = Q(homework=homework) & Q(gametype=gametype) & Q(
                    gcid=gcid)
                question = HomeworkDetail.objects.filter(condition)

                if question.exists():
                    return ResponseContent(code=401,
                                           token=request.auth,
                                           description=10143,
                                           error=10143)

            if 'idx' in params:
                condition = Q(homework=homework) & Q(idx=idx)
                question = HomeworkDetail.objects.filter(condition)

                if question.exists():
                    return ResponseContent(code=401,
                                           token=request.auth,
                                           description=10600,
                                           error=10600)
        except Exception as e:
            return ResponseContent(code=602,
                                   description=10542,
                                   error=e.__str__())
Exemplo n.º 6
0
 def exist_homework(self, params):
     response = ResponseContent(code=401, description=10114, error=10114)
     try:
         homework = Homework.objects.filter(id=params['hid'])
         if homework.exists():
             response = homework.first()
     except Exception as e:
         response.refresh(code=602, description=10810, error=e.__str__())
     return response
Exemplo n.º 7
0
 def exist_question(self, params):
     response = ResponseContent(code=401, description=10118, error=10118)
     try:
         question = HomeworkDetail.objects.filter(id=params['qid'])
         if question.exists():
             response = question.first()
     except Exception as e:
         response.refresh(code=602, description=10814, error=e.__str__())
     return response
Exemplo n.º 8
0
 def exist_comment(self, params):
     response = ResponseContent(code=401, description=10120, error=10120)
     try:
         comment = Comment.objects.filter(id=params['comment'])
         if comment.exists():
             response = comment.first()
     except Exception as e:
         response.refresh(code=602, description=10816, error=e.__str__())
     return response
Exemplo n.º 9
0
 def exist_lesson(self, params):
     response = ResponseContent(code=401, description=10113, error=10113)
     try:
         lesson = Lesson.objects.filter(id=params['lid'])
         if lesson.exists():
             response = lesson.first()
     except Exception as e:
         response.refresh(code=602, description=10809, error=e.__str__())
     return response
Exemplo n.º 10
0
    def exist_example(self, params):
        response = ResponseContent(code=401, description=10119, error=10119)
        try:
            example = LessonDetail.objects.filter(id=params['leid'])
            if example.exists():
                response = example.first()
        except Exception as e:
            response.refresh(code=602, description=10815, error=e.__str__())

        return response
Exemplo n.º 11
0
    def exist_curriculum(self, params):
        response = ResponseContent(code=401, description=10117, error=10117)
        try:
            curriculum = Curriculum.objects.filter(id=params['curid'])
            if curriculum.exists():
                response = curriculum.first()
        except Exception as e:
            response.refresh(code=602, description=10813, error=e.__str__())

        return response
Exemplo n.º 12
0
    def exist_course(self, params):
        response = ResponseContent(code=401, description=10112, error=10112)
        try:
            course = Course.objects.filter(id=params['cid'])
            if course.exists():
                response = course.first()
        except Exception as e:
            response.refresh(code=602, description=10808, error=e.__str__())

        return response
Exemplo n.º 13
0
    def exist_class(self, params):
        response = ResponseContent(code=401, description=10111, error=10111)
        try:
            organization = Cls.objects.filter(id=params['oid'])
            if organization.exists():
                response = organization.first()
        except Exception as e:
            response.refresh(code=602, description=10807, error=e.__str__())

        return response
Exemplo n.º 14
0
    def exist_user(self, params):
        response = ResponseContent(code=401, description=10104, error=10104)
        try:
            user = User.objects.filter(id=params['user'])
            if user.exists():
                response = user.first()
        except Exception as e:
            response.refresh(code=602, description=10558, error=e.__str__())

        return response
Exemplo n.º 15
0
    def exist_plan(self, params):
        response = ResponseContent(code=401, description=10115, error=10115)
        try:
            plan = ClsCourse.objects.filter(id=params['pid'])
            if plan.exists():
                response = plan.first()
        except Exception as e:
            response.refresh(code=602, description=10811, error=e.__str__())

        return response
Exemplo n.º 16
0
    def match_scene(self, params):
        response = True
        scene = int(params['scene'])
        profile = UserTeachingProfile.objects.filter(phone=params['phone'])

        if scene == 1 and profile.exists():
            response = ResponseContent(code=401, description=10105, error=10105)
        if scene != 1 and (not profile.exists()):
            response = ResponseContent(code=401, description=10104, error=10104)

        return response
Exemplo n.º 17
0
    def post(self, request, *args, **kwargs):
        response = ResponseContent(code=200, description=12054)
        state = status.HTTP_200_OK

        logout(request)
        jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
        jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER
        payload = jwt_payload_handler(request.user)
        token = jwt_encode_handler(payload)

        return Response(response.content(), status=state)
Exemplo n.º 18
0
    def get_list(self, request, pk=None):
        response = ResponseContent(code=200,
                                   token=request.auth,
                                   description=self.success_code['get'])
        state = status.HTTP_200_OK

        instance = self.get_object()
        serializer = self.get_serializer(instance, many=True)
        response.data = serializer.data

        return Response(response.content(), status=state)
Exemplo n.º 19
0
    def post(self, request, *args, **kwargs):
        response = ResponseContent(code=200,
                                   token=request.auth,
                                   description=12046)
        state = status.HTTP_200_OK
        params = request.data

        detail = self.readiness(request)
        if isinstance(detail, ResponseContent):
            return Response(detail.content(),
                            status=status.HTTP_406_NOT_ACCEPTABLE)

        try:
            enroll = ClsStudent.objects.filter(
                cls=params['oid'],
                cls__clscourse__teacher=request.user.id,
            )
            score = MaoScore.objects.filter(stage__chapter=params['gcid'])
            stage = MaoGameStage.objects.filter(
                chapter=params['gcid']).order_by('idx')
            response.data['student'] = EnrollSerializer(enroll, many=True).data
            response.data['score'] = HighScoreSerializer(score, many=True).data
            response.data['stage'] = MaoGameStageSerializer(stage,
                                                            many=True).data
        except Exception as e:
            response.refresh(code=604, description=10544, error=e.__str__())
            state = status.HTTP_500_INTERNAL_SERVER_ERROR

        return Response(response.content(), status=state)
Exemplo n.º 20
0
    def post(self, request, *args, **kwargs):
        response = ResponseContent(code=200,
                                   token=request.auth,
                                   description=12053)
        state = status.HTTP_200_OK
        params = request.data

        detail = self.readiness(request)
        if isinstance(detail, ResponseContent):
            return Response(detail.content(),
                            status=status.HTTP_406_NOT_ACCEPTABLE)

        openStatus = False

        try:
            enroll = ClsStudent.objects.filter(
                cls=params['oid'],
                cls__clscourse__teacher=request.user.id,
            )
            if enroll.exists():
                for item in enroll:
                    result = mao_chapter_unlock(item.student, params['gcid'])
                    if result:
                        openStatus = result
            else:
                response.refresh(code=11001, description=10153, error=10153)
        except Exception as e:
            response.refresh(code=602, description=10560, error=e.__str__())
            state = status.HTTP_500_INTERNAL_SERVER_ERROR

        response.data = openStatus

        return Response(response.content(), status=state)
Exemplo n.º 21
0
    def add_instance(self, request, pk=None):
        response = ResponseContent(code=200,
                                   token=request.auth,
                                   description=self.success_code['post'])
        state = status.HTTP_200_OK

        serializer = self.get_serializer(data=request.data, partial=True)
        if serializer.is_valid():
            serializer.save()
        else:
            response.refresh(code=604,
                             description=self.fail_code['post'],
                             error=serializer.errors)
            state = status.HTTP_500_INTERNAL_SERVER_ERROR

        return Response(response.content(), status=state)
Exemplo n.º 22
0
    def exist_student(self, params):
        response = ResponseContent(code=401, description=10106, error=10106)
        try:
            stundent = None
            if 'student' in params:
                stundent = params['student']
            if 'sid' in params:
                stundent = params['sid']

            student = UserTeachingProfile.objects.filter(user=stundent, role=0)
            if student.exists():
                response = student.first()
        except Exception as e:
            response.refresh(code=602, description=10806, error=e.__str__())

        return response
Exemplo n.º 23
0
    def post(self, request, *args, **kwargs):
        response = ResponseContent(code=200,
                                   token=request.auth,
                                   description=12053)
        state = status.HTTP_200_OK
        params = request.data

        detail = self.readiness(request)
        if isinstance(detail, ResponseContent):
            return Response(detail.content(),
                            status=status.HTTP_406_NOT_ACCEPTABLE)

        student = detail['student']
        result = mao_chapter_unlock(student.user, params['gcid'])
        response.data = result

        return Response(response.content(), status=state)
Exemplo n.º 24
0
    def post(self, request, *args, **kwargs):
        response = ResponseContent(code=200, description=12003)
        state = status.HTTP_200_OK

        detail = self.readiness(request)
        if isinstance(detail, ResponseContent):
            return Response(detail.content(),
                            status=status.HTTP_406_NOT_ACCEPTABLE)

        sms_captcha = SMSCaptcha()
        result = sms_captcha.send(request.data['phone'],
                                  int(request.data['scene']))
        if isinstance(result, ResponseContent):
            response = result
        if response.code > 300 or response.status == 'sms':
            state = status.HTTP_200_OK
        return Response(response.content(), status=state)
Exemplo n.º 25
0
    def exist_teacher(self, params):
        response = ResponseContent(code=401, description=10108, error=10108)
        # manager = UserTeachingProfile.objects.filter(id=params['mid']).exclude(Q(role=0) | Q(role=1) | Q(role=2)).first()
        try:
            teacher = None
            if 'teacher' in params:
                teacher = params['teacher']
            if 'tid' in params:
                teacher = params['tid']

            teacher = UserTeachingProfile.objects.filter(user=teacher).exclude(role=0)
            if teacher.exists():
                response = teacher.first()
        except Exception as e:
            response.refresh(code=602, description=10805, error=e.__str__())

        return response
Exemplo n.º 26
0
    def post(self, request, *args, **kwargs):
        response = ResponseContent(code=200,
                                   token=request.auth,
                                   description=12033)
        state = status.HTTP_200_OK

        detail = self.readiness(request)
        if isinstance(detail, ResponseContent):
            return Response(detail.content(),
                            status=status.HTTP_406_NOT_ACCEPTABLE)

        serializer = HomeworkSerializer(data=self.formatData(request),
                                        partial=True)
        if serializer.is_valid():
            serializer.save()
            serializer = CurriculumSerializer(detail['curriculum'],
                                              data=self.formatData(request),
                                              partial=True)
            if serializer.is_valid():
                serializer.save()
            else:
                response.refresh(code=11001,
                                 description=11001,
                                 error=serializer.errors)
                state = status.HTTP_501_NOT_IMPLEMENTED
        else:
            response.refresh(code=11001,
                             description=10531,
                             error=serializer.errors)
            state = status.HTTP_501_NOT_IMPLEMENTED

        return Response(response.content(), status=state)
Exemplo n.º 27
0
    def post(self, request, *args, **kwargs):
        detail = self.readiness(request)
        if isinstance(detail, ResponseContent):
            return Response(detail.content(),
                            status=status.HTTP_406_NOT_ACCEPTABLE)

        token = self.get_jwt_token(detail['user'])
        response = self.auth(request, detail['user'])
        if isinstance(response, ResponseContent):
            return Response(response.content(),
                            status=status.HTTP_401_UNAUTHORIZED)

        serializer = UserProfileSerializer(detail['profile'])
        response = ResponseContent(code=200,
                                   description=12000,
                                   token=token,
                                   data=serializer.data)
        return Response(response.content(), status=status.HTTP_200_OK)
Exemplo n.º 28
0
    def extra(self, request, detail):
        response = True
        params = request.data

        try:
            courses = ClsCourse.objects.filter(cls=params['oid'],
                                               course=params['cid'],
                                               teacher=request.user.id)
            if not courses.exists():
                return ResponseContent(code=401,
                                       description=10601,
                                       error=10601)
        except Exception as e:
            return ResponseContent(code=602,
                                   description=10559,
                                   error=e.__str__())

        return response
Exemplo n.º 29
0
    def auth(self, request, user, password):
        response = True

        user = authenticate(username=user.username, password=password)
        if user is None:
            response = ResponseContent(code=401,
                                       description=10103,
                                       error=10103)
        elif user is not None:
            login_init(user)
            if user.is_active:
                login(request, user)
            else:
                response = ResponseContent(code=601,
                                           description=10150,
                                           error=10150)

        return response
Exemplo n.º 30
0
 def match_params(self, params):
     response = True
     for key, value in self.check_list.items():
         if key in params:
             match = getattr(self, value)
             if not match(params[key]):
                 response = ResponseContent(code=401, description=10101, error=key + '不正确')
                 break
     return response