def add_comment(key, author, content): comment = Content(title=content["title"], content=content["content"], author=author) update = Content.get(key, bucket="spm_posts") update.comments.append(comment) comment.save(bucket="spm_comments") update.save(bucket="spm_posts") return comment
def post_update(author, content): update = Content(title=content["title"], content=content["content"], author=author) update.save(bucket="spm_posts") return update
def del_comment(key, content): comment = Content.get(key, bucket="spm_comments") comment.delete()
def edit_comment(key, content): comment = Content.get(key, bucket="spm_comments") comment.title = content["title"] comment.content = content["content"] comment.save(bucket="spm_comments") return comment
def del_update(key): update = Content.get(key, bucket="spm_posts") for comment in update.comments: comment.delete() update.delete()
def edit_update(key, content): update = Content.get(key, bucket="spm_posts") update.title = content["title"] update.content = content["content"] update.save(bucket="spm_posts") return update
def get_wall_post(key): return Content.get(key, bucket="spm_wallposts")
def get_all_posts_from_project(key): post_queries = Content.indexLookup("project_bin", key, bucket="spm_wallposts") posts = [] for post in post_queries.run(): posts.append(wall_post_to_display_json(post)) return sorted(posts, key=lambda x: x["pubdate"])[:50] # TODO: pagination? lol? delete old items? wut
def add_wall_post(key, content, user): post = Content(title=content, author=user) post.addIndex("project_bin", key) post.save(bucket="spm_wallposts") return post