def get_post_id_from_text(s): if is_number(s): return int(s) rt = route_from(s, method="GET") if rt[0] == 'views.render_post': return rt[1]['post_id'] elif rt[0] == 'views.post_page': try: return Post.query.filter(Post.url==rt[1]['post_url']) \ .with_entities(Post.id).one()[0] except NoResultFound: return None elif rt[0] == 'views.index': return Post.root_post_id()
def submit_post(): req_data = get_post_data_from_req(request) post = Post.submit_post(current_user, req_data.get("text"), req_data.get("title")) if isinstance(post, str): return transitify({"error": post, "error_type": "create-post"}) post_id = req_data.get('parent', Post.root_post_id()) relation = Relation.link_posts(post_id, post, current_user) if isinstance(relation, str): return transitify({"error": relation, "error_type": "link-posts"}) app_state = {"success": "posted successfully"} if req_data.get('current_post') and req_data.get('ask_for'): page = req_data.get( "page", math.ceil(float(total_actions(post_id)) / float(ACTIONS_PER_PAGE))) app_state.update( handle_asks(req_data.get('current_post'), req_data.get('ask_for'), page)) return transitify(app_state)
def submit_post(): req_data = get_post_data_from_req(request) post = Post.submit_post(current_user, req_data.get("text"), req_data.get("title")) if isinstance(post, basestring): return transitify({"error": post, "error_type": "create-post"}) post_id = req_data.get('parent', Post.root_post_id()) relation = Relation.link_posts(post_id, post, current_user) if isinstance(relation, basestring): return transitify({"error": relation, "error_type": "link-posts"}) app_state = {"success": "posted successfully"} if req_data.get('current_post') and req_data.get('ask_for'): page = req_data.get("page", math.ceil(float(total_actions(post_id)) / float(ACTIONS_PER_PAGE))) app_state.update(handle_asks(req_data.get('current_post'), req_data.get('ask_for'), page)) return transitify(app_state)
def index(): app_state = {"user": writable_current_user()} return render_post(Post.root_post_id())