Exemplo n.º 1
0
 def get(self,clazz_id):
     '''根据时间戳获取班级消息列表'''
     time = int(request.args.get('time','0'))
     messages = None
     if time:
         messages = Message.objects(Q(create_time__lt=time) & Q(clazz_id=clazz_id)).order_by('-create_time')[:5]
     else:
         messages = Message.objects(clazz_id=clazz_id).order_by('-create_time')[:10]
     response={}
     response['code']=200
     messages_json=[]
     for message in messages:
         messages_json.append(message.json(False))
     response['data']=messages_json
     return  response
Exemplo n.º 2
0
 def get(self,message_id):
     '''获取单条消息'''
     response={}
     response['code']=200
     mode = int(request.args.get('mode'))
     if mode==0:
         message = Message.objects(id=message_id).first()
         response['data']=message.json(False)
     elif mode==1:
         message = Message.objects(id=message_id).first()
         response['data']=message.json(True)
     else:
         message = Message.objects(id=message_id).only('read_users').only('comments').first()
         response_data = {}
         response_data['read_users_count']=len(message.read_users)
         response_data['comments_count']=len(message.comments)
         response['data']=response_data
     return response
Exemplo n.º 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}
Exemplo n.º 4
0
 def delete(self,message_id):
     '''删除一条消息'''
     response={}
     user_id = request.args.get('user_id')
     message = Message.objects(id=message_id).first()
     if str(message.publisher_id)==user_id:
         message.delete()
         response['msg']='删除成功'
         response['code']=200
     else:
         response['msg']='只有消息发布者才能删除'
         response['code']=208;
     return response
Exemplo n.º 5
0
 def delete(self,message_id,comment_id):
     '''删除评论'''
     message = Message.objects(id=message_id).first()
     message.comments.remove(message.comments.get(comment_id=comment_id))
     message.comments.save()
     # index = 0
     # for comment in message.comments:
     #     if comment.comment_id == comment_id:
     #         break
     #     index+=1
     # del message.comments[index]
     # message.update(comments=message.comments)
     return {'code':200,'msg':'删除评论成功'}
Exemplo n.º 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':'发布评论成功'}