Exemplo n.º 1
0
 def get(self,user_id):
     '''获取用户所在班级信息'''
     response['code']=200
     user_type = int(request.args.get('user_type'))
     items = []
     if user_type == 1:
         members = Member.objects(Q(user=ObjectId(user_id)) & Q(user_type=user_type) & Q(status=1))
         for member in members:
             clazzs = Clazz.objects(id=member.clazz_id).all()
             for clazz in clazzs:
                 item  = clazz.json()
                 item['is_creator']=member.is_creator
                 del item['creator']
                 items.append(item)
     else:
         students = Student.objects(user=ObjectId(user_id)).all()
         for student in students:
             members = Member.objects(Q(user=ObjectId(user_id)) & Q(student=student.id) & Q(status=1))
             clazzs_json = []
             for member in members:
                 clazzs = Clazz.objects(id=member.clazz_id).all()
                 for clazz in clazzs:
                     clazz_json  = clazz.json()
                     del clazz_json['creator']
                     clazz_json['is_creator']=member.is_creator
                     clazzs_json.append(clazz_json)
             if len(clazzs_json) > 0:
                 student_json = student.json()
                 del student_json['user']
                 student_json['clazzs'] = clazzs_json
                 items.append(student_json)
     response['data']=items
     return response
Exemplo n.º 2
0
            def put(self,member_id,clazz_id):
                '''同意或拒接加班申请'''
                is_agree = int(request.form.get('is_agree'))
                response['code']=200
                if is_agree == 1:
                    Member.objects(id=member_id).update(status=1)
                    Clazz.objects(id=clazz_id).update(inc__member_count=1)
                    response['msg']='老师同意申请加班'
                    threading.Thread(target=send_agree_join_class_push, args=(clazz_id,member_id)).start()

                else:
                    threading.Thread(target=send_refuse_join_class_push, args=(clazz_id,member_id)).start()
                    response['msg']='老师拒绝申请加班'
                return response
Exemplo n.º 3
0
            def get(self,clazz_id):
                '''获取班级信息'''
                response['code']=200
                clazz = Clazz.objects(id=clazz_id).all().first()

                response['data']=clazz.json()
                response['msg']='获取班级信息成功'
                return response
Exemplo n.º 4
0
            def get(self):
                '''查找班级'''
                response['code']=200
                phone = request.args.get('phone','')
                clazzes = Clazz.objects(creator=User.objects(phone=phone).first()).all()
                clazzes_json = []
                for clazz in clazzes:
                    clazzes_json.append(clazz.json())

                response['data']=clazzes_json
                response['msg']='查找班级成功'
                return response
Exemplo n.º 5
0
def send_join_class_push(clazz_id,member):
    redis_helper = RedisOperation()
    clazz = Clazz.objects(id=clazz_id).first()
    redis_helper.set_channel('class')
    redis_helper.set_push_type(101)
    push_ids = []
    push_ids.append(str(clazz.creator.id))
    redis_helper.set_push_ids(push_ids)
    push_content_json={}
    push_content_json['classId']=str(clazz.id)
    push_content_json['memberId']=str(member.id)
    push_content_json['content']=member.user.name + "申请加入" + clazz.clazz_name
    redis_helper.set_push_content(push_content_json)
    redis_helper.push()