def POST(self): params=web.input() cid=int(params.get('cid')) content=params.get('content') from_uid=int(params.get("from_uid",1)) piclist=params.get('piclist','') if len(piclist): piclist=piclist.split(',') else: piclist=[] mid=None if params.get('mid'): mid=int(params.get('mid')) newpost=CirclePost() newpost.picture_list=piclist newpost.cid=cid newpost.uid=from_uid newpost.content=content newpost.mid=mid newpost.save() json_msg=DefJsonEncoder.encode(newpost.toJson()) pusher.rawPush(body=json_msg, routing_key="sys.circle_new_board",headers={"type":"circle.newpost"}) return DefJsonEncoder.encode({"postid":newpost.postid})
def run(cid, after_postid): params = {"cid": cid} params["postid__gt"] = after_postid posts = CirclePost.objects(**params).order_by("-postid").limit(100) allpost = [] for one in posts: allpost.append(one.toJson()) return Res({"posts": allpost})
def run(cid,before_postid=None,count=20): params={'cid':cid} if before_postid: params['postid__lt']=before_postid posts=CirclePost.objects(**params).order_by("-postid").limit(count) allpost=[] for one in posts: allpost.append(one.toJson()) return Res({"posts":allpost})
def run(cid,content,pictures=[],mid=None): if isinstance(pictures,list)==False: pictures=[pictures] newpost=CirclePost() newpost.picture_list=pictures newpost.cid=cid newpost.uid=BackEndEnvData.uid newpost.content=content newpost.mid=mid newpost.save() json_msg=DefJsonEncoder.encode(newpost.toJson()) BackEndEnvData.queue_producer.publish(body=json_msg,delivery_mode=2, routing_key="sys.circle_new_board",headers={"type":"circle.newpost"}, compression='gzip') return Res({"postid":newpost.postid})
def run(postid,content): newpost=CirclePost.objects(postid=postid).first() newreply=ReplyRecord() newreply.uid=BackEndEnvData.uid newreply.content=content newpost.replys.append(newreply) newpost.save() json_msg=DefJsonEncoder.encode({"reply":newreply.toJson(), "postid":postid, "cid":newpost.cid}) BackEndEnvData.queue_producer.publish(body=json_msg,delivery_mode=2, routing_key="sys.circle_new_board",headers={"type":"circle.newreply"}, compression='gzip') return Res({"post":newreply.toJson()})
def run(postid): post=CirclePost.objects(postid=postid).first() for one in post.likes: if one.uid==BackEndEnvData.uid: return Res({'like':one.toJson()}) newlike=LikeRecord() newlike.uid=BackEndEnvData.uid post.likes.append(newlike) post.save() json_msg=DefJsonEncoder.encode({"like":newlike.toJson(),"postid":post.postid,"cid":post.cid}) BackEndEnvData.queue_producer.publish(body=json_msg, headers={"uid":post.uid,"type":"circle.post.newlike"}, delivery_mode=2, routing_key='sys.push_to_user', compression='gzip') return Res({'like':newlike.toJson()})