Ejemplo n.º 1
0
    def post(self):
        try:
            msgid=''
            username=get_current_user(self)
            note=AdNote.get_by_key_name('u'+username)
            if not note:
                note=AdNote(key_name='u'+username)
            else:
                img=Img.get_by_id(note.imgid)
                if img:
                    img.delete()

#            note.group=groupid
            note.author=username
            note.content=self.request.get('NoteContent','')
            note.title=self.request.get('NoteTitle','')

#            note.updateTime=noteupdate
            imgfield=self.request.POST.get('imgfile')
            if imgfield!=None and imgfield!='' and imgfield!=u'':

                if imgfield.type.lower() not in ['image/pjpeg','image/x-png','image/jpeg','image/png','image/gif','image/jpg']:
                    msgid=str(uuid.uuid4())
                    memcache.set(msgid,u'图片格式不合格',3600)
                    self.redirect('/PutAdNote?msgid='+msgid)
                    logging.info(imgfield.type)
                    return
#                    raise 'type error'
                imgfile=Img()
                imgfile.type=imgfield.type
                if imgfield.type.lower().find('gif')==-1:
                    imgfile.afile=db.Blob(images.resize(self.request.get("imgfile"), height=150))
                else:
                    imgfile.afile=self.request.get("imgfile")
#                imgfile.afile=db.Blob(images.resize(self.request.get("imgfile"), height=150))
                imgfile.put()
                note.imgid=imgfile.key().id()
                note.content+="[*TempLink/%s/%s*]" %(imgfile.key().id(),setting.APPCODE_ID)
            note.put()

        except Exception,e:
            logging.error(str(e))
            pass
Ejemplo n.º 2
0
    def get(self):
        username=get_current_user(self)
        imglist=[]
        note=AdNote.get_by_key_name('u'+username)
#        note=Note.get_by_id(int(noteid))
        if note:
            imgstrlist=re.findall('(?i)templink/([^/\s\?&]*)/',note.content)
            for img in imgstrlist:
                img=int(img)
                imglist.append(img)
            imglist=Img.get_by_id(imglist)
            news, number = re.subn('[\*TempLink/([^/]*/[^\]]*]','', note.content)
            note.content=news
        msg=memcache.get(self.request.get('msgid',''))
        if not msg:
            msg=''
        self.render('templates/adNoteShow.html',{'adnote':note,'username':username,'user':getorAddUser(username),'imglist':imglist,'msg':msg})
Ejemplo n.º 3
0
    def get(self):
#        username=get_current_user(self)
        grouplist=[]
        noteid=self.request.get('Noteid',0)
        note={}
        imglist=[]
        if noteid:

            note=DaTingNote.get_by_id(int(noteid))
            if note:
                imgstrlist=re.findall('(?i)templink/([^/\s\?&]*)/',note.content)

                for img in imgstrlist:
                    img=int(img)
                    imglist.append(img)
                imglist=Img.get_by_id(imglist)
                news, number = re.subn('[\*TempLink/([^/]*/[^\]]*]','', note.content)
                note.content=news
        msg=memcache.get(self.request.get('msgid',''))
        if not msg:
            msg=''
        self.render('templates/daTingNoteAdd.html',{'note':note,'imglist':imglist,'msg':msg})
Ejemplo n.º 4
0
    def get(self):
        username=get_current_user(self)
        grouplist=[]
        noteid=self.request.get('Noteid',0)
        note={}
        imglist=[]
        if noteid:
            note=Note.get_by_id(int(noteid))
            if note:
                imgstrlist=re.findall('(?i)templink/([^/\s\?&]*)/',note.content)

                for img in imgstrlist:
                    img=int(img)
                    imglist.append(img)
                imglist=Img.get_by_id(imglist)
                news, number = re.subn('[\*TempLink/([^/]*/[^\]]*]','', note.content)
                note.content=news
        groupid=self.request.get('GroupId')
        if note:
            groupid=note.group
        group=None
        if groupid:
#            group=Group.get_by_id(int(groupid))
            group=getGroup(int(groupid))
        if not group:
            if '000'==username:
                self.redirect('/GroupListM')
                return
            else:
                for g in Group.all().filter('author =',username):
                    grouplist.append(g)

        msg=memcache.get(self.request.get('msgid',''))
        if not msg:
            msg=''
        self.render('templates/noteAdd.html',{'group':group,'grouplist':grouplist,'note':note,'imglist':imglist,'msg':msg})
Ejemplo n.º 5
0
            #####
            imgfield=self.request.POST.get('imgfile')
            if imgfield!=None and imgfield!='' and imgfield!=u'':
                if imgfield.type.lower() not in ['image/pjpeg','image/x-png','image/jpeg','image/png','image/gif','image/jpg']:
                    msgid=str(uuid.uuid4())
                    memcache.set(msgid,u'图片格式不合格',3600)
                    self.redirect('/CreateNoteM?Noteid='+str(noteid)+'&GroupId='+str(groupid)+'&msgid='+msgid)
                    logging.info(imgfield.type)
                    return
                imgstrlist=re.findall('(?i)templink/([^/\s\?&]*)/',note.content)
                imglist=[]
                for img in imgstrlist:
                    img=int(img)
                    imglist.append(img)
                imglist=Img.get_by_id(imglist)
                db.delete(imglist)
#                    raise 'type error'
#                imgdb=imgfield.file.read()

#                img=Image(imgdb)
                imgfile=Img()
                imgfile.type=imgfield.type
                if imgfield.type.lower().find('gif')==-1:
                    imgfile.afile=db.Blob(images.resize(self.request.get("imgfile"), height=150))
                else:
                    imgfile.afile=self.request.get("imgfile")
                imgfile.put()
                note.content+="[*TempLink/%s/%s*]" %(imgfile.key().id(),setting.APPCODE_ID)

            note.put()
Ejemplo n.º 6
0
    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