Ejemplo n.º 1
0
def delete_post(post_id, username):
    """
    Deletes a post (as well as its related set of tags).
    """
    debug("DELETE POST. username:"******",post:" + str(post_id))
    post_id = str(post_id)
    if _is_post_created(post_id):
        # Delete each of the tags (to decrement the score in the ranking)
        for temp_tag in get_post_tags(post_id):
            delete_tag_from_post(post_id, temp_tag)
        # Delete the set of tags that the post has
        tags_id = db.hget(post_id + APPEND_KEY_POSTS, KEY_TAGS)
        db.delete(tags_id + APPEND_KEY_TAG)
        # Delete the counter of votes that the post has
        votes_id = db.hget(post_id + APPEND_KEY_POSTS, KEY_VOTES)
        db.delete(votes_id + APPEND_KEY_VOTE)
        # Delete the post from the sorted set of posts by date
        db.zrem(username + APPEND_SEARCH_POST_TIMEDATE, post_id)
        # Delete the post id from the user's post list
        # (1 is the number of items to be removed)
        db.lrem(username + APPEND_KEY_POSTS, 1, post_id)
        # Delete the post from the last updates
        _delete_post_last_updates(post_id)
        # Delete the post from the global ranking
        db.zrem(POPULAR_TOP_POSTS, post_id)
        # Delete the hash of the post
        db.delete(post_id + APPEND_KEY_POSTS)
        """
        db.hdel(post_id  + APPEND_KEY_POSTS, KEY_TAGS)
        db.hdel(post_id + APPEND_KEY_POSTS, KEY_TITLE)
        db.hdel(post_id + APPEND_KEY_POSTS, KEY_DATE)
        db.hdel(post_id + APPEND_KEY_POSTS, KEY_CONTENTS)
        """
        return True
    else:
        return False
Ejemplo n.º 2
0
def _delete_post_last_updates(post_id):
    """ Removes the post from the capped list of last updates if present. """
    db.lrem(GLOBAL_POST_UPDATE_ID, 1, post_id)