def thread_view(key): thread = Thread.load(decrypt(key)) categories = get_categories(thread) user = active_user() if any(c.access is None or c.access.has_permission(user,'read') for c in categories): return template("view_thread",user=user,thread=thread) return flash_message("No permission. :(", "/","501")
def submit_post(key): user = active_user() if has_permission(user,'create-post'): post = Post() thread = Thread.load(decrypt(key)) content = bottle.request.forms.get("content","").strip() assert len(content)>0 post.update({"content":content,"owner":user.key}) thread.posts.append(post) thread.save() post.save()
def new_thread(key=None): user = active_user() if has_permission(user,'new-thread'): new_thread = Thread() first_post = Post() name = bottle.request.forms.get("name") content = bottle.request.forms.get("content") tags = parse_tags(bottle.request.forms.get("tags","")) first_post.update({ "owner":user.key, "content":content }) new_thread.update({ "name":name, "owner":user.key, "posts":[first_post.key], "tags":tags }) forum = Forum.load(forum_key()) target = Category.load(decrypt(key)) if key else forum target.threads.append(new_thread.key) target.save() new_thread.save() return flash_message("Your thread has been created.","/thread/"+new_thread.slug+"/","Success") raise bottle.HTTPError(404, """Sorry, but we weren't able to find what you were looking for. I hope that someday you do find it, but when you do, it won't be here. """)