def new(subdomain='www'): items = Controller.new(subdomain=subdomain) return render_template( "index.html", subdomain=subdomain, title="Newest", posts=items[0], next_url=items[1], start_rank_num=items[2], )
def index(subdomain='www'): if not current_user.is_authenticated: return redirect(url_for("auth.login", subdomain=subdomain)) search_terms = request.args.get("q") if search_terms: title = "Search for \"" + search_terms + "\"" else: title = "Trending" items = Controller.index(search_terms=search_terms, subdomain=subdomain) if len(items[0]) == 0 and not search_terms: flash( "Welcome, there is no article yet in your company. Submit the first one by clicking the submit button", "success") if len(items[0]) == 0 and search_terms: flash("We did not find any matching result", "warning") return render_template( "index.html", subdomain=subdomain, title=title, posts=items[0], next_url=items[1], start_rank_num=items[2], )
def post(self, current_user): item = Controller.reply_comment(request.form['comment_id'], request.form['text'], current_user) if item: return {"message": "You replied to a comment"}, 200 post_ns.abort(401, 'You cannot reply to this comment')
def post(self, current_user): item = Controller.reply_post(request.form['post_id'], request.form['text'], current_user) if item: return {"message": "You submited a new post"}, 200 post_ns.abort(401, 'You cannot post')
def post(self, current_user): item = Controller.upvote(int(request.form['id']), current_user) if item: return {"post_id": int(request.form['id'])}, 200 post_ns.abort(401, 'You already voted')
def get(self, comment_id): item = Controller.comment_page(comment_id) return jsonify(json.loads(item.to_json(max_nesting=1)))
def get(self, post_id): item = Controller.post_by_id(post_id) return jsonify(json.loads(item.to_json(max_nesting=1)))
def get(self, page=1): items = Controller.index(page) return jsonify([i.id for i in items[0]])
def get(self, page=1): items = Controller.index(page) return jsonify( [json.loads(i.to_json(max_nesting=1)) for i in items[0]])
def get(self, current_user): items = Controller.user_submissions(current_user) return jsonify([json.loads(i.to_json(max_nesting=1)) for i in items])
def post(self, current_user): item = Controller.delete_post(request.form['post_id'], current_user) if item: return {"message": "You deleted your post"}, 200 post_ns.abort(401, 'You cannot cannot this post')
def post(self, current_user): item = Controller.upvote_comment(request.form['comment_id'], current_user) if item: return {"message": "You upvoted a comment"}, 200 post_ns.abort(401, 'You cannot upvote this comment')
def get(self, username, current_user): return jsonify(json.loads(Controller.user(username)[0].to_json(max_nesting=0)))
def post(self, current_user): return Controller.edit_profile(request.form['username'], request.form['about_me'], request.form['email'], current_user)