Exemplo n.º 1
0
def set_user_action_as_completed(action, deal_id, user_seq_num):
    '''
    This function denotes the user as having completed either "like", "flag",
    or "bookmarked" action.
    '''
    key = gen_user_action_hash_key(action, deal_id)
    r.setbit(key, user_seq_num, 1)
Exemplo n.º 2
0
def set_user_action_as_completed(action, deal_id, user_seq_num):
    '''
    This function denotes the user as having completed either "like", "flag",
    or "bookmarked" action.
    '''
    key = gen_user_action_hash_key(action, deal_id)
    r.setbit(key, user_seq_num, 1)
Exemplo n.º 3
0
def user_has(action, deal_id):
    '''
    This function is used to see if user has either flagged, saved,
    or voted a specific deal, which is denoted by deal_id

    The function returns true if a user has flagged, saved, or voted on a
    specific deal. The function returns false if otherwise.
    '''

    if action not in ['flag', 'save', 'vote']:
        return abort(404)
    user = get_current_user()
    if user is None:
        return False

    key = gen_user_action_hash_key(action, deal_id)
    user_sequence_num = user.sequence_num
    finished_action = r.getbit(key, user_sequence_num)
    if finished_action:
        return True
    else:
        # If the user action bit is false, we can't be 100% sure that
        # the user has NOT done this action. For example, the redis instance
        # may have went down, and its cache was wiped completely (or wiped
        # under other unseen circumstances).
        #
        # Therefore, if the action bit is set to false, we will query our
        # mongodb db and see if the user has accomplished any of these actions
        action_completed = False
        if action == 'flag':
            action_completed = str(deal_id) in user.deals_flagged
        elif action == 'save':
            action_completed = str(deal_id) in user.deals_saved
        elif action == "vote":
            action_completed = str(deal_id) in user.deals_voted

        if action_completed:
            r.setbit(key, user_sequence_num, 1)
        return action_completed
Exemplo n.º 4
0
def user_has(action, deal_id):
    '''
    This function is used to see if user has either flagged, saved,
    or voted a specific deal, which is denoted by deal_id

    The function returns true if a user has flagged, saved, or voted on a
    specific deal. The function returns false if otherwise.
    '''

    if action not in ['flag', 'save', 'vote']:
        return abort(404)
    user = get_current_user()
    if user is None:
        return False

    key = gen_user_action_hash_key(action, deal_id)
    user_sequence_num = user.sequence_num
    finished_action = r.getbit(key, user_sequence_num)
    if finished_action:
        return True
    else:
        # If the user action bit is false, we can't be 100% sure that
        # the user has NOT done this action. For example, the redis instance
        # may have went down, and its cache was wiped completely (or wiped
        # under other unseen circumstances).
        #
        # Therefore, if the action bit is set to false, we will query our
        # mongodb db and see if the user has accomplished any of these actions
        action_completed = False
        if action == 'flag':
            action_completed = str(deal_id) in user.deals_flagged
        elif action == 'save':
            action_completed = str(deal_id) in user.deals_saved
        elif action == "vote":
            action_completed = str(deal_id) in user.deals_voted

        if action_completed:
            r.setbit(key, user_sequence_num, 1)
        return action_completed