def post(self,clazz_id): '''申请加班''' user_id = request.form.get('user_id') user_type = int(request.form.get('user_type')) student_id = request.form.get('student_id') response['code']=200 response['msg']='申请加班成功' if user_type == 1: member = Member.objects(Q(clazz_id=clazz_id) & Q(user=ObjectId(user_id)) & Q(status=2)).first() if member: threading.Thread(target=send_join_class_push, args=(clazz_id,member)).start() return response else: member = Member.objects(Q(clazz_id=clazz_id) & Q(user=ObjectId(user_id)) & Q(student=ObjectId(student_id)) & Q(status=2)).first() if member: threading.Thread(target=send_join_class_push, args=(clazz_id,member)).start() return response member = Member() member.user = User.objects(id=user_id).first() member.clazz_id = clazz_id member.user_type = user_type member.status = 2 if student_id != None: member.student = Student.objects(id=student_id).first() member.is_creator=False member.save() threading.Thread(target=send_join_class_push, args=(clazz_id,member)).start() return response
def post(self): '''创建班级 ''' user_id = request.form.get('user_id') clazz_name = request.form.get('clazz_name') clazz = Clazz.objects.order_by('-clazz_num').first() if clazz == None: clazz = Clazz() clazz.creator = User.objects(id=user_id).first() clazz.clazz_name = clazz_name clazz.create_time = time.time()*1000 clazz.save() ##添加成员 member = Member() member.clazz_id = str(clazz.id) member.user = clazz.creator member.user_type = 1 member.is_creator = True member.status = 1 member.save() response['code']=200 response['msg']='创建班级成功' response['data']=clazz.json() else: clazz_new = Clazz() clazz_new.creator = User.objects(id=user_id).first() clazz_new.clazz_name = clazz_name clazz_new.clazz_num = clazz.clazz_num + 1 clazz_new.create_time = time.time()*1000 clazz_new.save() ##添加成员 member = Member() member.clazz_id = str(clazz_new.id) member.user = clazz_new.creator member.user_type = 1 member.is_creator = True member.status = 1 member.save() response['code']=200 response['msg']='创建班级成功' response['data']=clazz_new.json() return response