示例#1
0
    def list(self, request, *args, **kwargs):
        """
            获取用户收藏列表
        :param request:
        :param args:
        :param kwargs:{
	        "target_id": 6,
	        "target_type": "student"
        }
        :return:
        """
        customer = request.customer
        if not customer:
            raise TokenException('用户验证失败')
        queryset = self.get_queryset()
        if customer.customer_type == 1:
            # 当用户角色为教师时,获取他收藏的学生
            queryset = queryset.filter(customer_id=customer.id,
                                       target_type='student')
        elif customer.customer_type == 2:
            # 当用户角色为学生时,获取他收藏的教师
            queryset = queryset.filter(customer_id=customer.id,
                                       target_type='teacher')
        else:
            # 用户为注册
            return Response({'status': 0, 'msg': '用户未注册'})
        serializer = self.get_serializer(queryset, many=True)
        return Response(serializer.data)
示例#2
0
    def create(self, request, *args, **kwargs):
        """
            创建教师    
        :param request:    
        :param args:    
        :param kwargs:{                    
            customer: 5             用户id          
            last_name: 谷           教师姓氏          
            city: 1                 城市id         
            school: 1               学校id         
            phone: '15201170495'    教师电话               
            sex: 1                  性别    /0:女 1:男           
            learn: 1                学历id             
            profession: 计算机       专业          
            high_score: 500         高考分数            
            money: 100              期望薪资 /默认单位:小时          
            head_image: ''          头像地址             
            subjects: [                 
                {"subject": 1},              
                {"subject": 2}                    
            ],                      擅长科目id list            
            teacher_types: [          
                {'teacher_type': 1},           
                {'teacher_type': 2}                   
            ],                      教师特点id list          
            self_introduction: 自我介绍          
        }          
                  
        :return:{           
                status: 0/1         返回状态  目前0失败,1成功          
                teacher_id: 1       新增的教师id           
            }         
        """
        # 序列化参数
        data = request.data
        customer = request.customer
        if not customer:
            raise TokenException('用户验证失败')
        serializer = self.get_serializer(data=data)
        serializer.is_valid(raise_exception=True)
        params = serializer.validated_data
        params['customer'] = customer
        logger.info(u'start create teacher info %s' % params)

        # 添加教师
        status, msg = teacher_models.Teacher.add_teacher(**params)
        if status:
            print('add teacher %s success' % msg)
            return Response({'status': 1, 'teacher_id': msg})
        logger.info('add teacher %s error msg %s' % (params, msg))
        return Response({'status': 0, 'msg': msg})
示例#3
0
 def create(self, request, *args, **kwargs):
     """
         添加学生    
     :param request:    
     :param args:    
     :param kwargs:{    
             "customer": "1",            用户id    
             "name": "小学生",            家长姓氏    
             "city": "1",                城市id    
             "level": "1",               年级id    
             "phone": "15201170495",     电话    
             "times": 1,                 学习次数,1:一周一次, 2:一周2次,依次内推,最大7次, 0: 面议    
             "basis": "1",               学习基础id    
             "sex": 0,                   性别,0:女 1:男    
             "money": 100,               薪水    
             "require": "211高校",        教师资质    
             "teacher_sex": 1,           教师性别    
             "subject": 6,               科目id    
             "address": "上课地点都行",   上课地点    
             "teacher_types": [    
                 {'teacher_type': 1},    
                 {'teacher_type': 2}    
             ],                          教师特点id list    
             "student_types": [    
                 {'student_type': 1},    
                 {'student_type': 2}      
             ],                          学生不足id        
             "extra": "其他"              其他        
         }            
          
     :return:{           
             status: 0/1         返回状态  目前0失败,1成功              
             student_id: 1       新增的学生id             
         }             
     """
     data = request.data
     serializer = self.get_serializer(data=data)
     serializer.is_valid(raise_exception=True)
     params = serializer.validated_data
     customer = request.customer
     if not customer:
         raise TokenException('用户验证失败')
     params['customer'] = customer
     logger.info('start create student info %s' % params)
     # 新增student
     status, msg = student_models.Student.add_student(**params)
     if status:
         print('add student %s success' % msg)
         return Response({'status': 1, 'student_id': msg})
     logger.info('add student %s error msg %s' % (params, msg))
     return Response({'status': 0, 'msg': msg})
示例#4
0
 def destroy(self, request, pk=None):
     """
         删除 收藏
     :param request:
     :param pk: 收藏id
     :return:
     """
     logger.info('start delete customer follower %s' % pk)
     customer_fav = operation_models.CustomerFavorite.objects.get(id=pk)
     if request.customer != customer_fav.customer:
         raise TokenException('用户验证失败')
     customer_fav.delete_favorite()
     logger.info('customer %s delete favorite %s success' %
                 (customer_fav.customer_id, pk))
     return Response({'status': 1, 'id': pk})
示例#5
0
 def destroy(self, request, pk=None):
     """
         删除 收藏
     :param request:
     :param pk: 收藏id
     :return:
     """
     logger.info('start delete customer apply %s' % pk)
     customer_apply = operation_models.CustomerApply.objects.get(id=pk)
     if request.customer != customer_apply.customer_apply:
         raise TokenException('用户验证失败')
     customer_apply.delete_apply()
     logger.info('customer %s delete apply %s success' %
                 (customer_apply.customer_apply_id, pk))
     return Response({'status': 1, 'id': pk})
示例#6
0
 def destroy(self, request, pk=None):
     """
         删除学生
     :param request:        
     :param pk: 学生id      
     :return:       
     """
     logger.info('start delete student %s' % pk)
     if request.customer.student_set.filter(
             is_valid=True).first().id != int(pk):
         raise TokenException('用户验证失败')
     student = student_models.Student.objects.get(id=pk)
     student.delete_student()
     logger.info('delete student %s success' % pk)
     return Response({'status': 1, 'student_id': pk})
示例#7
0
 def destroy(self, request, pk=None):
     """
         删除老师          
     :param request:       
     :param pk: 教师id         
     :return:            
     """
     logger.info('start delete teacher %s' % pk)
     if request.customer.teacher_set.filter(
             is_valid=True).first().id != int(pk):
         raise TokenException('用户验证失败')
     teacher = teacher_models.Teacher.objects.get(id=pk)
     teacher.delete_teacher()
     logger.info('delete teacher %s success' % pk)
     return Response({'status': 1, 'teacher_id': pk})
示例#8
0
    def retrieve(self, request, pk=None):
        """

        :param request:
        :param pk:
        :return:
        """
        customer = request.customer
        if not customer:
            raise TokenException('用户验证失败')
        student = student_models.Student.objects.get(id=pk)
        serializer = student_serializers.StudentSerializer(student)
        student_info = serializer.data
        student_info['customer_is_follower'] = student.customer_is_follower(
            customer_id=customer.id)
        student_info['customer_is_apply'] = student.customer_is_apply(
            customer_id=customer.id)
        return Response(student_info)
示例#9
0
 def update(self, request, pk=None):
     """
         修改学生
     :param request:
     :param args:
     :param kwargs:
     :return:
     """
     data = request.data
     if request.customer.student_set.filter(
             is_valid=True).first().id != int(pk):
         raise TokenException('用户验证失败')
     serializer = self.get_serializer(data=data)
     serializer.is_valid(raise_exception=True)
     params = serializer.validated_data
     logger.info('update student params %s' % params)
     update_student = student_models.Student.objects.get(id=pk)
     update_student.update_student(**params)
     return Response({'status': 1, 'student_id': pk})
示例#10
0
 def update(self, request, pk=None):
     """
         修改教师         
     :param request:         
     :param pk:         
     :return:           
     """
     data = request.data
     # 验证用户
     if request.customer.teacher_set.filter(
             is_valid=True).first().id != int(pk):
         raise TokenException('用户验证失败')
     serializer = self.get_serializer(data=data)
     serializer.is_valid(raise_exception=True)
     params = serializer.validated_data
     logger.info('update teacher params %s' % params)
     update_teacher = teacher_models.Teacher.objects.get(id=pk)
     update_teacher.update_teacher(**params)
     return Response({'status': 1, 'teacher_id': pk})
示例#11
0
 def create(self, request, *args, **kwargs):
     """
         意见反馈,投诉
     :param request:
     :param args:
     :param kwargs:
     :return:
     """
     data = request.data
     if not request.customer:
         raise TokenException('用户验证失败')
     serializer = self.get_serializer(data=data)
     serializer.is_valid(raise_exception=True)
     params = serializer.validated_data
     params['customer'] = request.customer
     logger.info("create suggestion_id params %s" % params)
     suggestion_id = customer_models.CustomerSuggestion.add_suggestion(
         **params)
     if suggestion_id:
         return Response({'status': 1, 'suggestion_id': suggestion_id})
     logger.info("add suggestion error, is already exists. params")
     return Response({'status': 0, 'msg': '投诉异常'})
示例#12
0
 def create(self, request, *args, **kwargs):
     """
         增加 申请
     :param request:
     :param args:
     :param kwargs:
     :return:
     """
     data = request.data
     customer = request.customer
     if not customer:
         raise TokenException('用户验证失败')
     serializer = self.get_serializer(data=data)
     serializer.is_valid(raise_exception=True)
     params = serializer.validated_data
     params['customer'] = customer
     logger.info("customer %s add apply params %s" % (customer.id, params))
     fav_id, msg = operation_models.CustomerApply.add_apply(**params)
     if fav_id:
         return Response({'status': 1, 'fav_id': fav_id})
     logger.info("add apply error %s params: %s" % (msg, params))
     return Response({'status': 0, 'msg': msg})
示例#13
0
    def retrieve(self, request, pk=None):
        """

        :param request:
        :param pk:
        :return:
        """
        customer = request.customer
        if not customer:
            raise TokenException('用户验证失败')
        teacher = teacher_models.Teacher.objects.get(id=pk)
        serializer = teacher_serializers.TeacherSerializer(teacher)
        teacher_info = serializer.data
        teacher_info['customer_is_follower'] = teacher.customer_is_follower(
            customer_id=customer.id)
        teacher_info['customer_is_apply'] = teacher.customer_is_apply(
            customer_id=customer.id)
        return Response(teacher_info)


# class TeacherFollowerViewset(viewsets.ModelViewSet):
#     """
#         教师收藏api
#     """
#
#     def get_queryset(self):
#         return teacher_models.TeacherFollowers.objects.filter(is_valid=True)
#
#     def get_serializer_class(self):
#         """
#             获取序列化
#         :return:
#         """
#         if self.action == 'create':
#             return teacher_serializers.CreateTeacherFollowerSerializer
#         else:
#             return teacher_serializers.CreateTeacherFollowerSerializer
#
#     def create(self, request, *args, **kwargs):
#         """
#             点击收藏  教师
#         :param request:
#         :param args:
#         :param kwargs:{
#               "teacher": ",             被收藏教师id
#               "customer": 1             操作的用户id
#             }
#         :return: {
#             'status': 0/1,              返回状态  目前0失败,1成功
#             'teacher_follower_id': 1    收藏id,
#             'msg': '收藏失败'            失败时信息
#         }
#         """
#         data = request.data
#         serializer = self.get_serializer(data=data)
#         serializer.is_valid(raise_exception=True)
#         params = serializer.validated_data
#         customer = request.customer
#         if not customer:
#             raise TokenException('用户验证失败')
#         params['customer'] = customer
#         logger.info('start add teacher followers info %s' % params)
#         teacher_follower_id, msg = teacher_models.TeacherFollowers.add_teacher_follower(**params)
#         if teacher_follower_id:
#             return Response({'status': 1, 'teacher_follower_id': teacher_follower_id})
#         logger.info("add teacher follower error, is already exists. params: %s" % params)
#         return Response({'status': 0, 'msg': msg})
#
#     def destroy(self, request, pk=None):
#         """
#             删除 教师 的收藏
#         :param request:
#         :param pk: 收藏id
#         :return:
#         """
#         logger.info('start delete teacher follower %s' % pk)
#         teacher_follower = teacher_models.TeacherFollowers.objects.get(id=pk)
#         if request.customer != teacher_follower.customer:
#             raise TokenException('用户验证失败')
#         teacher_follower.delete_teacher_follower()
#         logger.info('delete teacher follower %s success' % pk)
#         return Response({'status': 1, 'teacher_id': pk})
#
#
# class TeacherApplyViewset(viewsets.ModelViewSet):
#     """
#         申请教师
#     """
#
#     def get_queryset(self):
#         return teacher_models.TeacherApply.objects.filter(is_valid=True)
#
#     def get_serializer_class(self):
#         """
#             获取序列化
#         :return:
#         """
#         if self.action == 'create':
#             return teacher_serializers.CreateTeacherApplySerializer
#         else:
#             return teacher_serializers.CreateTeacherApplySerializer
#
#     def create(self, request, *args, **kwargs):
#         """
#             向 教师 发送申请
#         :param request:
#         :param args:
#         :param kwargs:
#         :return:
#         """
#         data = request.data
#         customer = request.customer
#
#         return Response({})