示例#1
0
            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
示例#2
0
            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
示例#3
0
 def put(self,message_id):
     '''设置消息已读'''
     args = set_message_read_parser.parse_args()
     message = Message.objects(id=message_id).first()
     if message.publisher_id == args['user_id']:
         return {'code':200}
     user = User.objects(id=args['user_id']).first()
     if user not in  message.read_users :
         message.read_users.append(user)
     message.update(set__read_users=message.read_users)
     return {'code':200}
示例#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
示例#5
0
 def get(self):
     '''用户登录'''
     _phone = request.args.get('phone', '')
     _password = request.args.get('password', '')
     response = {'code': 200,'msg': '', 'data': ''}
     user = User.objects(phone = _phone).exclude('password').first()
     if user == None:
         response['code'] = 201
         response['msg'] = '手机号未注册'
     else:
         if  User.objects(phone = _phone).only('password').first().password != _password:
             response['code'] = 202
             response['msg'] = '密码错误'
         else:
             response['code'] = 200
             dicdata = json.loads(user.to_json())
             dicdata['user_id'] = dicdata['_id']['$oid']
             del dicdata['_id']
             dicdata['login_time'] = int(time.time()*1000)
             response['data'] =dicdata
             response['msg']  = '登录成功'
     return response
示例#6
0
 def put(self,message_id):
     '''发布评论'''
     args = add_comment_parser.parse_args()
     message = Message.objects(id=message_id).first()
     user = User.objects(id=args['user_id']).first()
     comment = Comment()
     comment.comment_id = str(ObjectId.from_datetime(generation_time=datetime.datetime.now()))
     comment.content = args['content']
     comment.publisher = user.name
     comment.publisher_id = str(user.id)
     comment.publish_time = time.time() * 1000
     message.comments.append(comment)
     message.update(comments = message.comments)
     return {'code':200,'msg':'发布评论成功'}
示例#7
0
 def post(self):
     '''用户注册'''
     user = User()
     user.name = request.form['name']
     user.phone = request.form['phone']
     user.password = request.form['password']
     user.save()
     response['code'] = 200
     dicdata = json.loads(user.to_json())
     dicdata['user_id'] = dicdata['_id']['$oid']
     del dicdata['_id']
     response['data'] =dicdata
     response['msg']  = '注册成功'
     return response
示例#8
0
            def put(self,user_id):
                '''更新用户信息'''
                role_type = request.form.get('role_type')
                name = request.form.get('name')
                user = User.objects(id=user_id).first()
                if role_type != None:
                    user.role_type = role_type
                    user.update(role_type=role_type)
                if name!= None:
                    user.name = name
                    user.update(name=name)

                response['code']=200
                response['msg']='更新成功'
                response['data']= json.loads(user.to_json())
                return response
示例#9
0
            def post(self):
                '''添加孩子'''
                student = Student()

                user_id = request.form.get('user_id')
                identify = request.form.get('identify')
                student_name = request.form.get('student_name')
                user = User.objects(id=user_id).first()

                student.user = user
                student.identify = identify
                student.student_name = student_name
                student.save()
                response['code']=200
                response['msg']='创建孩子成功'
                response['data']=student.json()
                return response
示例#10
0
            def post(self):
                '''发布消息'''
                response = {}
                args = publish_message_parser.parse_args()
                message = Message()
                message.content = args['content']
                message.title = args['title']

                user = User.objects(id=args['user_id']).only('name').first()
                message.publisher = user.name
                message.publisher_id = args['user_id']
                message.clazz_id = args['clazz_id']
                message.create_time = time.time()*1000

                members = Member.objects(Q(clazz_id=args['clazz_id']) & Q(status=1)).only('user')
                unread_users = []
                for member in members:
                    if str(member.user.id) != args['user_id']:
                        unread_users.append(member.user)
                message.unread_users = unread_users
                if args['attachments'] != None:
                    items = eval(args['attachments'])
                    mongo_attachments = []
                    for item in items:
                        attachment = Attachment()
                        attachment.width = item['width']
                        attachment.height = item['height']
                        attachment.url = "http://qiniu1.com/" + item['key']
                        mongo_attachments.append(attachment)
                    message.attachments = mongo_attachments
                message.save()
                response['code']=200
                response['msg']='发送消息成功'
                response['data']=message.json(False)


                threading.Thread(target=send_publish_message_push, args=(unread_users,message.id)).start()
                return response