def get(self): groupid=self.request.get('groupid') tagmap={} for tag in Tag.all(): tagmap[str(tag.key().id())]=tag.name username=get_current_user(self) user=getorAddUser(username) if groupid: groupid=int(groupid) # group=Group.get_by_id(groupid) group=getGroup(groupid) if group.author==username: group.delete() nlist=[] rnlist=[] for n in Note.all().filter('group =',groupid): nlist.append(n) rnlist.append('r'+str(n.key().id())) db.delete(Replay.get_by_key_name(rnlist)) db.delete(nlist) if groupid in user.createGroup: user.createGroup.remove(groupid) user.put() if groupid in user.createGroupAdd: user.createGroupAdd.remove(groupid) user.put() groupidlist=user.createGroup+user.createGroupAdd list=Group.get_by_id(groupidlist) # list=Group.all().filter('author =',username) listgroup=[] ischange=False for i,group in enumerate(list): if not group: if groupidlist[i] in user.createGroup: user.createGroup.remove(groupidlist[i]) ischange=True if groupidlist[i] in user.createGroupAdd: user.createGroupAdd.remove(groupidlist[i]) ischange=True else: group.tagname=tagmap.get(str(group.tag),'') listgroup.append(group) if ischange: user.put() self.render('templates/removegroupList.html',{'list':listgroup})
if group.type==1: if username not in group.partner and username!=group.author: self.response.out.write('2') return elif group.type==2: if username!=group.author and username!=group.author: self.response.out.write('2') return if mod=='add': if group.notenum<group.notecount: note=Note() else: note=Note.all().filter('group =',groupid).filter('isTop =',False).order('isDelete').order('updateTime').fetch(1)[0] r=Replay.get_by_key_name('r'+str(note.key().id())) if r: r.content='' r.updateTime=noteupdate r.put() else: msg=u'修改帖子成功' note=Note.get_by_id(noteid) note.group=groupid note.author=username note.content=content note.title=title note.updateTime=noteupdate #####
def post(self): tmpimgid=int(datetime.datetime.utcnow().strftime('%Y%m%d%H%M%S')) notenum=self.request.get('notenum') logging.info('notenum:'+str(notenum)) if notenum: notenum=int(notenum) else: notenum=0 group=None groupchange=False rssnote=None rssnotelist=None rssimg=None rssimgdic=None for num in range(notenum): groupid=self.request.get(str(num)+'code') # logging.info('code:'+groupid) title=self.request.get(str(num)+'title') content=self.request.get(str(num)+'content') # logging.info('content:'+content) username=self.request.get(str(num)+'username') # logging.info('username:'******'rsscode'+str(groupid)) if not lastnews: lastnews=[] lastnews.insert(0,title) memcache.set('rsscode'+str(groupid),lastnews,360000) else: if title not in lastnews: lastnews.insert(0,title) lastnews=lastnews[:20] memcache.set('rsscode'+str(groupid),lastnews,360000) else: # logging.error('title:'+title) # logging.error('titlelist:'+str(lastnews)) continue logging.info('rsscode'+str(groupid)+'rssMsg:'+title) if not rssimg: rssimg=memcache.get('rssimg'+str(groupid)) if not rssimg: rssimg=RssImg.get_by_key_name('rss'+str(groupid)) if not rssimg: rssimg=RssImg(key_name='rss'+str(groupid)) if not rssimgdic: rssimgdic=rssimg.getImgDic() imgdic={} imglist=[] for i in range(20): imgsrc=self.request.get(str(num)+'img'+str(i)) if imgsrc: img='0%sG%s%s00%s'%(groupid,tmpimgid,num,i) imgdic[img]=imgsrc memcache.set('image_id'+str(img),imgsrc,3600*24*20) # img=Img() # img.src=imgsrc imglist.append(img) else: break if groupid and title and content: try: groupid=int(groupid) except Exception,e : logging.error('e1:'+str(e)) return # db.put(imglist) imgstr='' for img in imglist: imgstr+= "[*TempLink/%s/%s*]" %(img,setting.APPCODE_ID) # memcache.set('image_id'+str(img.key().id()),img,36000) # group=Group.get_by_id(groupid) if not group: group=memacheGroup(groupid) if not rssnote: rssnote=RssNote.get_by_key_name('rss'+str(groupid)) if not rssnote: rssnote=RssNote(key_name='rss'+str(groupid)) group.notenum=0 group.put() if not rssnotelist: rssnotelist=rssnote.getNoteList() if group.notenum<group.notecount: # note=Note() note={'id':len(rssnotelist)+1,'isDelete':False,'isTop':False,'updateTime':None,'down':0,'up':0,'point':0,'author':'','content':'','title':'','group':0} rssnotelist.append(note) else: # note=Note.all().filter('group =',groupid).filter('isTop =',False).order('isDelete').order('updateTime').fetch(1)[0] note=rssnotelist.pop(0) rssnotelist.append(note) if note['content']: imgstrlist=re.findall('(?i)templink/([^/\s\?&]*)/',note['content']) imglist=[] for img in imgstrlist: if img[0]=='0': continue img=int(img) imglist.append(img) imglist=Img.get_by_id(imglist) db.delete(imglist) # memcache.delete('replay'+str(groupid)+str(note['id'])) r=Replay.get_by_key_name('g'+str(groupid)+'r'+str(note['id'])) if r: r.content='' r.updateTime=datetime.datetime.utcnow()+timezone r.put() note['group']=groupid note['author']=username note['content']=content+imgstr note['title']=title noteupdate=datetime.datetime.utcnow()+timezone note['updateTime']=time.mktime(noteupdate.timetuple()) note['point']=0 note['up']=0 note['down']=0 note['isTop']=False note['isDelete']=False if imgdic: rssimgdic[str(note['id'])]=imgdic else: if rssimgdic.has_key(str(note['id'])): del rssimgdic[str(note['id'])] if not note['content']: # logging.error('content:'+content[:20]) continue try: memcache.set('rssgroupmemcach'+str(groupid),rssnotelist,3600) except : logging.error('rss group note too big:'+str(len(rssnotelist))) # logging.info('content:'+note.content[:20]) if group.notenum<group.notecount: group.notenum+=1 groupchange=True