def get(self): groupid=self.request.get('groupid','') userName=self.request.get("UserName") weiUser=getWeiUser(userName,groupid) nickname=getNickName(userName) result='{"result":"%s","message":"%s","url":"%s","obj":"%s"}' resultObj={'group':weiUser.group,'userid':weiUser.user,'point':weiUser.point,'tempPoint':weiUser.tempPoint,'nickname':nickname} self.flashhtml(result%('success',u'','',json.dumps(resultObj)))
def get(self): userName=self.request.get("UserName") groupid=self.request.get('groupid','') type=self.request.get('type','') weinoteid=self.request.get('weinoteid','') weinotereplayid=self.request.get('weinotereplayid','') start=self.request.get('start',0) limit=self.request.get('limit',30) start=int(start) limit=int(limit) if groupid: query=[] if '1'==type:#精华 querypoint=WeiNotePoint.all().filter('group =',int(groupid)).order('-point').fetch(limit,start) ids=[] for weinotepoint in querypoint: ids.append(int(weinotepoint.key().name()[1:])) ''' 缓存point 下面需要用到 ''' setWeiNotePoint(weinotepoint) query=WeiNote.get_by_id(ids) elif '2'==type:#新帖 query=WeiNote.all().filter('updateTime >',datetime.datetime.utcnow()-timezone-timezone).filter('group =',int(groupid)).order('-updateTime').fetch(limit,start) elif '3'==type:#收藏 shoucang=WeiShouCang.all().filter('user ='******'u'+userName).filter('group =',int(groupid)).fetch(1) if 1==len(shoucang): weishoucang=shoucang[0] query=WeiNote.get_by_id(weishoucang.shoucang[start:start+limit]) else: pass contents=[] for note in query: if note: notepoint=getWeiNotePoint(note.key().id()) jsoncontent={'type':'note','content':note.content,'noteid':note.key().id(),'title':note.title,'up':0,'down':0,'point':0,'author':note.author,'username':getNickName(note.author),'groupid':note.group,'replayType':weiNoteReplayType,'lastUpdateTime':note.updateTime} if notepoint: jsoncontent['up']=notepoint.up jsoncontent['down']=notepoint.down jsoncontent['point']=notepoint.point contents.append(jsoncontent) #contents.append({'code':percode+groupid+'-%s%s'%(type,note.key().id()),'father':percode+groupid,'maincode':setting.APPCODE,'level':'102','title':note.title,'content':json.dumps(jsoncontent),'replayType':weiNoteReplayType,'lastUpdateTime':note.updateTime,'status':'1'}) # xml,dates=queryWeiNoteXmlDic(contents) # return self.flashhtml(xml.toxml('utf-8')) return self.flashhtml(json.dumps({'notelist':contents})) if weinoteid: notelist=[] # notereplaylist=[] note=WeiNote.get_by_id(int(weinoteid)) notepoint=getWeiNotePoint(note.key().id()) jsoncontent={'type':'note','content':note.content,'noteid':note.key().id(),'title':note.title,'up':0,'down':0,'point':0,'author':note.author,'username':getNickName(note.author),'groupid':note.group,'replayType':weiNoteReplayType,'lastUpdateTime':note.updateTime} if notepoint: jsoncontent['up']=notepoint.up jsoncontent['down']=notepoint.down jsoncontent['point']=notepoint.point # contents.append({'code':percode+groupid+'-%s'%(note.key().id(),),'father':percode+groupid,'maincode':setting.APPCODE,'level':'102','title':note.title,'content':json.dumps(jsoncontent),'replayType':weiNoteReplayType,'lastUpdateTime':note.updateTime,'status':'1'}) notelist.append(jsoncontent) for notereplay in WeiNoteReplay.all().filter('note =',weinoteid).order('updateTime').fetch(limit,start): jsoncontent={'type':'notereplay','content':notereplay.content,'noteid':notereplay.note,'notereplayid':notereplay.key().id(),'author':notereplay.author,'username':getNickName(notereplay.author),'replayType':weiNoteReplayReplayType,'lastUpdateTime':notereplay.updateTime} notelist.append(jsoncontent) # notereplaylist.append({'code':percode+groupid+'-%s-%s'%(weinoteid,notereplay.key().id()),'father':percode+groupid+'-%s'%(weinoteid,),'maincode':setting.APPCODE,'level':'103','title':'','content':json.dumps(jsoncontent),'replayType':weiNoteReplayReplayType,'lastUpdateTime':notereplay.updateTime,'status':'1'}) for i,replay in enumerate( notereplay.replay[:5]): jsoncontent=json.loads(replay) jsoncontent['type']='notereplayreplay' jsoncontent['index']=i jsoncontent['notereplayid']=notereplay.key().id() jsoncontent['username']=getNickName(jsoncontent['author']) jsoncontent['to_username']=getNickName(jsoncontent['to_userid']) notelist.append(jsoncontent) # jsoncontent={'noteid':notereplay.note,'notereplayid':notereplay.key().id(),'author':notereplay.author,'username':getNickName(notereplay.author),'replayType':weiNoteReplayReplayType} # contents.append({'code':percode+groupid+'-%s-%s-%s'%(weinoteid,notereplay.key().id(),i),'father':percode+groupid+'-%s-%s'%(weinoteid,notereplay.key().id()),'maincode':setting.APPCODE,'level':'104','title':'','content':replay,'replayType':weiNoteReplayReplayType,'lastUpdateTime':'','status':'1'}) # xml,dates=queryWeiNoteXmlDic(contents) return self.flashhtml(json.dumps({'notelist':notelist})) if weinotereplayid: contents=[] notereplay=WeiNoteReplay.get_by_id(int(weinotereplayid)) weinoteid=notereplay.note jsoncontent={'type':'notereplay','content':notereplay.content,'noteid':notereplay.note,'notereplayid':notereplay.key().id(),'author':notereplay.author,'username':getNickName(notereplay.author),'replayType':weiNoteReplayReplayType,'lastUpdateTime':notereplay.updateTime} contents.append(jsoncontent) # contents.append({'code':percode+groupid+'-%s-%s'%(weinoteid,notereplay.key().id()),'father':percode+groupid+'-%s'%(weinoteid,),'maincode':setting.APPCODE,'level':'103','title':'','content':json.dumps(jsoncontent),'replayType':weiNoteReplayReplayType,'lastUpdateTime':notereplay.updateTime,'status':'1'}) for i,replay in enumerate(notereplay.replay): jsoncontent=json.loads(replay) jsoncontent['type']='notereplayreplay' jsoncontent['index']=i jsoncontent['notereplayid']=notereplay.key().id() jsoncontent['username']=getNickName(jsoncontent['author']) jsoncontent['to_username']=getNickName(jsoncontent['to_userid']) contents.append(jsoncontent) # contents.append({'code':percode+groupid+'-%s-%s-%s'%(weinoteid,notereplay.key().id(),i),'father':percode+groupid+'-%s-%s'%(weinoteid,notereplay.key().id()),'maincode':setting.APPCODE,'level':'104','title':'','content':replay,'replayType':weiNoteReplayReplayType,'lastUpdateTime':'','status':'1'}) # xml,dates=queryWeiNoteXmlDic(contents) return self.flashhtml(json.dumps({'notelist':contents}))