def post(self):
     msgid=''
     try:
         point=int(self.request.get('point','0'))
         username=get_current_user(self)
         user=getorAddUserPoint(username)
         msg=u'竞拍成功。'
         if point>user.point:
             msg=u'竞拍失败,积分不足。'
         else:
             pl=PaiMai.all().order('-__key__').fetch(1)
             pm=None
             if 1==len(pl):
                 pm=pl[0]
                 lasttimestr=jingpaiDate()
                 if lasttimestr!=pm.key().name()[1:]:
                     pm=PaiMai(key_name='p'+lasttimestr)
                     memcache.delete('adnote')
             elif 0==len(pl):
                 pm=PaiMai(key_name='p'+ setting.AdNoteTime)
                 memcache.delete('adnote')
             if pm.maxpoint<point:
                 pm.maxpoint=point
                 pm.user=username
                 pm.put()
             else:
                 msg=u'竞拍失败,使用积分少于 当前竞拍最高分 。'
         msgid=str(uuid.uuid4())
         memcache.set(msgid,msg,3600)
     except :
         pass
     self.redirect('/JingPai?msg='+msgid)
     return
def jingpaiDate():
    pl=PaiMai.all().order('-__key__').fetch(1)
    pm=None
    if 1==len(pl):
        pm=pl[0]
        lasttime=datetime.datetime.strptime(pm.key().name()[1:],'%Y%m%d')
        nowdate=datetime.datetime.strptime((datetime.datetime.utcnow()+datetime.timedelta(hours =8)).strftime("%Y%m%d"),'%Y%m%d')
        #1.lasttime 小于 当前日期
        while nowdate>lasttime:
            lasttime=lasttime+datetime.timedelta(hours =24*7)
        #2.lasttime 大于 当前日期
        lasttimestr=lasttime.strftime("%Y%m%d")
        return lasttimestr
    elif 0==len(pl):
        return setting.AdNoteTime
    def get(self):
        username=get_current_user(self)
        lasttimestr=jingpaiDate()
        starttime=datetime.datetime.strptime(lasttimestr,'%Y%m%d')
        endtime=starttime+datetime.timedelta(hours =24*7)-+datetime.timedelta(minutes =1)
        pl=PaiMai.all().order('-__key__').fetch(1)
        pm=None
        if 1==len(pl):
            pm=pl[0]
            if lasttimestr!=pm.key().name()[1:]:
                pm=None
        adnote=None
        if pm:
            adnote=AdNote.get_by_key_name('u'+pm.user)
        msgid=self.request.get('msg')
        msg=None
        if msgid:
            msg=memcache.get(msgid)

        self.render('templates/jingpai.html',{'username':username,'starttime':starttime,'endtime':endtime,'paimai':pm,'adnote':adnote,'userpoint':getorAddUserPoint(username),'msg':msg})