Example #1
0
    def post(self):

        groupid=self.request.get('groupid',0)
        weinoteid=self.request.get('weinoteid','')
        title=self.request.get('title','')
        content=self.request.get('content','')
        type=self.request.get('type','0')
        image_list=self.request.get('image_list','')
        author=self.request.get('author','')
        if not groupid or not title or not author:
            self.flashhtml(resultStr%('fail',u'标题、群号、用户号为必填项。',''))
            return
        try:
            if not weinoteid:
                weinote=WeiNote()
            else:
                weinote=WeiNote.get_by_id(int(weinoteid))
            weinote.group=int(groupid)
            weinote.title=title
            weinote.content=content
            weinote.type=int(type)
            for imageid in image_list.split(','):
                weinote.image_list.append(int(imageid))
            if author[0]=='u':
                weinote.author=author
            else:
                weinote.author='u'+author
            weinote.updateTime=datetime.datetime.utcnow()+timezone
            weinote.put()
            if not weinoteid:
                weiNotePoint=WeiNotePoint(key_name='n%s'%weinote.key().id())
                weiNotePoint.group=int(groupid)
                weiUser=getWeiUser(weinote.author,str(groupid))
                if weiUser:
                    weiNotePoint.point=weiUser.point
                else:
                    weiNotePoint.point=0
                weiNotePoint.put()
                self.flashhtml(resultStr%('success',u'发布帖子成功。',''))
            else:
                self.flashhtml(resultStr%('success',u'修改帖子成功。',''))
            return
        except Exception,e:
            self.flashhtml(resultStr%('fail',u'服务器异常,请稍后再操作。',''))
            logging.error(str(e))
            return
Example #2
0
    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}))