Exemple #1
0
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],
    )
Exemple #2
0
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],
    )
Exemple #3
0
 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')
Exemple #4
0
 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')
Exemple #5
0
 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')
Exemple #6
0
 def get(self, comment_id):
     item = Controller.comment_page(comment_id)
     return jsonify(json.loads(item.to_json(max_nesting=1)))
Exemple #7
0
 def get(self, post_id):
     item = Controller.post_by_id(post_id)
     return jsonify(json.loads(item.to_json(max_nesting=1)))
Exemple #8
0
 def get(self, page=1):
     items = Controller.index(page)
     return jsonify([i.id for i in items[0]])
Exemple #9
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]])
Exemple #10
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])
Exemple #11
0
 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')
Exemple #12
0
 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')
Exemple #13
0
 def get(self, username, current_user):
     return jsonify(json.loads(Controller.user(username)[0].to_json(max_nesting=0)))
Exemple #14
0
 def post(self, current_user):
     return Controller.edit_profile(request.form['username'], request.form['about_me'], request.form['email'], current_user)