Exemple #1
0
def insert_user(user): #OK
    """
    Inserts a user in the db. Returns False if there is already a user in the
    db with that username.
    """
    debug("CREATE USER :"******"\tUser successfully created")
        return get_user(username)
    else:
        debug("\tUser creation failed")
        return False
Exemple #2
0
def _vote(post_id, voting_user, positive): #OK
    """ Private method for handling postivite and negative votes. """
    post_id = str(post_id)
    debug("VOTE POSITIVE. user:"******", post:" + post_id)
    if _is_post_created(post_id) and _is_user_created(voting_user):
        debug("\t CURRENT VOTES of USER.")
        debug("\t\t-user: "******"\t\t-voted to: " + str(db.smembers(voting_user + APPEND_KEY_HAS_VOTED)))
        # Check if the user can vote
        if db.sismember(voting_user + APPEND_KEY_HAS_VOTED, post_id) == 0:
            vote_id = db.hget(post_id + APPEND_KEY_POSTS, KEY_VOTES)
            debug("\t vote_id: " + str(vote_id))
            pipe = db.pipeline()
            if positive:
                pipe.incr(vote_id + APPEND_KEY_VOTE)
            else:
                pipe.decr(vote_id + APPEND_KEY_VOTE)
            pipe.sadd(voting_user + APPEND_KEY_HAS_VOTED, post_id)
            pipe.execute()
            return True
        else:
            return False
    else:
        return None
Exemple #3
0
def _insert_post_last_updates(post_id):
    """ Insert post to the  global capped list of last updated posts. """
    pipe = db.pipeline()
    pipe.lpush(GLOBAL_POST_UPDATE_ID, post_id)
    pipe.ltrim(GLOBAL_POST_UPDATE_ID, 0, API_MAX_UPDATES -1)
    pipe.execute()