def getNewsList(request): # depend on the friends depart num = request.GET['num'] allFriends = Account.objects(pk__in=request.user.friends).all() number = News.objects(author__in=allFriends).count() if int(num)*15>number: result=[] return HttpResponse(dumps(result)) result = News.objects(author__in=allFriends)[int(num)*15:int(num)*15 + 15].order_by("-time").as_pymongo() result = list(result) for news in result: del(news['_types']) del(news['_cls']) news['picture'] = endpoint + "news/getPicture?id=" + str(news['_id']) news['voice'] = endpoint + "news/getVoice?id=" + str(news['_id']) uid = news['author'] user = News.objects(author=uid).first().author gid = news['good'] good = News.objects(good=gid).first().good news['good'] = endpoint + "goods/getGoods?id=" + str(good.pk) news['author'] = {"portrait": endpoint + "users/getPortrait?id=" + str(user.pk), "name": user.username} news['comments'] = endpoint + "news/getComments?id=" + str(news['_id']) # news['_id'] = endpoint + "news/getNewsDetail?id=" + str(news['_id']) del(news['_id']) news['time']=str(news['time']) result = dumps(result) return HttpResponse(result)
def getComments(request): nid=request.GET['id'] news=News.objects(pk=nid).as_pymongo() comments=list(news)[0]["comments"] for comment in comments: del(comment["_types"]) del(comment["_cls"]) uid=comment["author"] user = Account.objects(pk=uid.id).first() if comment["voice"]!=None: comment["voice"]=endpoint + "news/getCommentVoice?vid="+str(comment["voice"]) else: comment["voice"]="" comment["username"]=user.username comment["portrait"]=endpoint+"users/getPortrait?id="+str(user.pk) del(comment["author"]) return HttpResponse(dumps(comments))