def get(self,key): user_key = self.get_secure_cookie("user_key") print user_key pinLike = PinLike() l_key = hashlib.md5("%s%s" % (user_key,key)).hexdigest() l_data = pinLike.get(l_key) #return self.dumpJson(l_data) res = {} if l_data: res['code'] = 1 res['msg'] = "您已喜欢过" else : pinLike.key = l_key pinLike.data['user'] = user_key pinLike.data['pin'] = key pinLike.data['createTime'] = int(time.time()) pinLike.post() pin =Pin() data = pin.get(key) pin.key = key pin.data = data pin.data['like'] = int(data['like']) + 1 pin.put() dump(data) res['code'] = 0 res['msg'] = "成功" res_str = json.dumps(res) self.write(res_str)
def formatPins(self,data): pin = Pin() board = Board() user = User() thumb = Thumb() comment = Comment() marks_dict = [] for pin_row in data: _pin = {} _pin['pin'] = pin.get(pin_row['pin']) _pin['user'] = user.getDetail(pin_row['user']) _pin['thumb'] = thumb.get(pin_row['pin']) _pin['board'] = board.getDetail(_pin['pin']['board']) #print _pin['board'] _pin['comments'] = comment.getByPin(pin_row['pin']) marks_dict.append(_pin) return marks_dict