Exemple #1
0
def _delete_tag_from_all_user_posts(username, tag):
    """
    Deletes a tag from all the posts a given user has.
    """
    debug("DELETE TAG FROM USER POSTS. tag:" + tag + ", user:" + username)
    for post_id in db.lrange(username + APPEND_KEY_POSTS, 0, -1):
        delete_tag_from_post(post_id, tag)
Exemple #2
0
def get_last_post_updates():
    """ Gets the last post updates. """
    post_ids = db.lrange(GLOBAL_POST_UPDATE_ID, 0, -1)
    ret = []
    for post_id in post_ids:
        post = get_post(post_id)
        if post != None:
            ret.append(post)
    return ret
Exemple #3
0
def get_posts(username, int_page=0): # OK
    """
    Returns all the posts written by a user, ordered by latest - oldest.
    int_page: is used for the pagination.
    """
    debug("GET POSTS OF USER: " + username)
    if _is_user_created(username):
        if int_page == 0:
            # Return all the posts
            posts_ids = db.lrange(username + APPEND_KEY_POSTS, 0, -1)
        else:
            # Get the posts specified in the pagination
            posts_ids = db.lrange(username + APPEND_KEY_POSTS,
                                  # Start index
                                  (int_page - 1) * API_PAGINATION,
                                  # End index (included in lrange)
                                  int_page * API_PAGINATION - 1)
        posts = []
        for key in posts_ids:
            posts.append(get_post(key))
        return posts
    else:
        return None
Exemple #4
0
def _get_posts(username):
    """ Returns the posts ids of a user. """
    return db.lrange(username + APPEND_KEY_POSTS, 0, -1)