def POST(self,name): name = name.encode('utf-8') key = vote_key(name) lock_key = vote_lock_key(name) if not kv.add(lock_key,1): return 0 try: ip = web.ctx['ip'].encode('utf-8') ip_key = vote_ip_key(ip,name) if not kv.add(ip_key,1): return 0 c = kv.get(key) c = int(c) if c else 0 kv.set(key,c+1) finally: kv.delete(lock_key) return kv.get(key)
def GET(self,name): name = name.encode('utf-8') v = kv.get(vote_key(name)) v = v if v else 0 return v