def rewind(user): """ 撤销上一次滑动操作记录 撤销上一次创建的好友关系 :param user: :return: """ key = cache_keys.SWIPE_LIMIT_PREFIX.format(user.id) swipe_times = cache.get(key, 0) if swipe_times >= config.SWIPE_LIMIT: raise errors.SwipeLimitError swipe = Swiped.objects.filter(uid=user.id).latest('created_at') if swipe.mark in ['lke', 'superlike']: Friend.cancel_friends(swipe.uid, swipe.sid) swipe.delete() now = datetime.datetime.now() timeout = (24 * 60 * 60) - now.hour * 3600 - now.minute * 60 - now.second # n = int(time.time()) # timeout = 86400 - (n+ 8*3600) % 86400 cache.set(key, swipe_times + 1, timetout=timeout)
def rewind(user): """ 撤销当前登录用户的上传一次滑动操作 每天只能撤销三次 :param user: :return: """ key = config.REWIND_CACHE_PREFIX % user.id rewind_times = cache.get(key, 0) if rewind_times >= config.REWIND_TIMES: raise errors.RewindLimitError swipe = Swiped.objects.filter(uid=user.id).latest('created_at') if swipe.mark in ['like', 'superlike']: Friend.cancel_friends(user.id, swipe.sid) sub_swipe_score(swipe.mark, swipe.sid) swipe.delete() now = datetime.datetime.now() timeout = 86400 - now.hour * 3600 - now.minute * 60 - now.second cache.set(key, rewind_times + 1, timeout=timeout)