Exemplo n.º 1
0
 def get(self,jokeid=None):
     html=memcache_get('joke'+jokeid)
     if not html :
         ha=NewJoke.get_by_key_name(jokeid)
         html=self.obj2str('templates/jokedetail.html',{'ha':ha,'uuid':str(uuid.uuid4()),'guest':{}})
         memcache_set('joke'+jokeid,html,720000)
     self.flashhtml(html)
Exemplo n.º 2
0
    def get(self,date=None,page=1,limit=20):
        perdate=''
        afterdate=''
        if None==date:
            defaultdate=DefaultDate.get_by_key_name('date')
            date=defaultdate.date
            afterdate='flage'

        html=memcache_get('date'+date+'page'+str(page)+'limit'+str(limit))
        if html:
            return self.flashhtml(html)
        perdate=(datetime.datetime.strptime(date,'%Y%m%d')-datetime.timedelta(hours =24)).strftime('%Y%m%d')
        if not afterdate:
            afterdate=(datetime.datetime.strptime(date,'%Y%m%d')+datetime.timedelta(hours =24)).strftime('%Y%m%d')
        else:
            afterdate=''
        if page:
            page=int(page)
        if limit:
            limit=int(limit)
        hahamap=memcache.get('query:date'+date+'page'+str(page)+'limit'+str(limit))
        if not hahamap:
            hahalist=[]
            for joke in NewJoke.all().filter('date =',date).order('-updateTime'):
                hahalist.append(joke)
            total=int(len(hahalist)/limit)
            for i in range(total):
                if i==(total-1):
                    memcache.set('query:date'+date+'page'+str(i+1)+'limit'+str(limit),{'hahalist':hahalist[i*limit:],'total':len(hahalist)},3600*72)
                else:
                    memcache.set('query:date'+date+'page'+str(i+1)+'limit'+str(limit),{'hahalist':hahalist[i*limit:(i+1)*limit],'total':len(hahalist)},3600*72)
        hahamap=memcache.get('query:date'+date+'page'+str(page)+'limit'+str(limit))
        if not hahamap:
            self.redirect('/%s/1/%s'%(perdate,limit))
            return
        totalpage=hahamap.get('total',0)
        nowpage=None
        pagelist=[]
        for p in range(int(totalpage/limit)):
            if (page-1)==p:
                nowpage='/%s/%s/%s'%(date,(p+1),limit)
            pagelist.append({'page':'/%s/%s/%s'%(date,(p+1),limit),'pagenum':p+1})
        if perdate==date:
            perdate=''
        html=self.obj2str('templates/jokeindex.html',{'hahalist':hahamap.get('hahalist',[]),'pagelist':pagelist,'nowpage':nowpage,'pagenum':page,'limit':limit,'nowdate':date,'perdate':perdate,'afterdate':afterdate})
        memcache_set('date'+date+'page'+str(page)+'limit'+str(limit),html,3600*5*page)
        self.flashhtml(html)
        return
Exemplo n.º 3
0
 def get(self):
     jokeid=self.request.get('jokeid')
     html=memcache_get('replayjoke'+jokeid)
     if not html:
         replaylist=[]
         for replay in Replay.all().filter('joke =',jokeid).order('-updateTime'):
             rmap={}
             rmap['id']=replay.key().id()
             rmap['jokeid']=replay.joke
             rmap['face']=replay.face
             rmap['content']=replay.content
             rmap['createDate']=replay.updateTime.strftime('%Y年%m月%d日 %H:%M:%S')
             rmap['fatherid']=replay.fatherid_id
             rmap['userid']=replay.user
             rmap['username']=getUserName(replay.user)
             replaylist.append(rmap)
         html=json.dumps(replaylist)
         memcache_set('replayjoke'+jokeid,html,7200)
     self.flashhtml(html)