def delete_page(name): """Completely delete a wiki page.""" name = name.strip("/") path = "wiki/pages/{}".format(name) if JsonDB.exists(path): logger.info("Delete Wiki page {}".format(name)) JsonDB.delete(path) return True
def delete_entry(post_id): """Remove a blog entry.""" # Fetch the blog information. index = get_index() post = get_entry(post_id) if post is None: logger.warning("Can't delete post {}, it doesn't exist!".format(post_id)) # Delete the post. JsonDB.delete("blog/entries/{}".format(post_id)) # Update the index cache. del index[str(post_id)] # Python JSON dict keys must be strings, never ints JsonDB.commit("blog/index", index)
def update_user(uid, data): """Update the user's data.""" if not exists(uid=uid): raise Exception("Can't update user {}: doesn't exist!".format(uid)) db = get_user(uid=uid) # Change of username? if "username" in data and len(data["username"]) and data["username"] != db["username"]: JsonDB.delete("users/by-name/{}".format(db["username"])) JsonDB.commit("users/by-name/{}".format(data["username"]), dict( uid=int(uid), )) db.update(data) JsonDB.commit("users/by-id/{}".format(uid), db)
def delete_entry(post_id): """Remove a blog entry.""" # Fetch the blog information. index = get_index() post = get_entry(post_id) if post is None: logger.warning( "Can't delete post {}, it doesn't exist!".format(post_id)) # Delete the post. JsonDB.delete("blog/entries/{}".format(post_id)) # Update the index cache. del index[str( post_id)] # Python JSON dict keys must be strings, never ints JsonDB.commit("blog/index", index)
def delete_user(uid): """Delete a user account.""" if not exists(uid=uid): return db = get_user(uid=uid) username = db["username"] # Mark the account deleted. update_user(uid, dict( username="", name="", role="deleted", password="******", )) # Delete their username. JsonDB.delete("users/by-name/{}".format(username))
def write_subscribers(thread, subs): """Save the subscribers to the DB.""" if len(subs.keys()) == 0: return JsonDB.delete("comments/subscribers/{}".format(thread)) return JsonDB.commit("comments/subscribers/{}".format(thread), subs)
def write_comments(thread, comments): """Save the comments DB.""" if len(comments.keys()) == 0: return JsonDB.delete("comments/threads/{}".format(thread)) return JsonDB.commit("comments/threads/{}".format(thread), comments)