Ejemplo n.º 1
0
def create_comment(r, project_id):
    # get bearer token from auth header
    auth_header = request.headers.get("authorization")
    access_token = auth_header[len("Bearer "):]

    # get username and user id to respond with
    user_info = get_user_info(access_token)
    username = user_info["username"]
    user_id = user_info["user_id"]

    data = json.loads(r.data)

    # Create the comment id.
    comment_id = str(uuid.uuid1())

    # Insert the comment
    add_comment(comment_id, user_id, username, data['message'], project_id)

    response_dict = {
        "comment_id": comment_id,
        "commenter_id": user_id,
        "commenter_username": username,
        "message": data['message']
    }
    return Response(json.dumps(response_dict),
                    status=200,
                    mimetype='application/json')
Ejemplo n.º 2
0
Archivo: index.py Proyecto: ab/blag
 def entry(self, postid,name=None,title=None,body=None,submit=None):
     if cherrypy.request.method.lower() == "get":
         post = dereference_author(db.get_post(postid))
         comments = db.get_comments(postid)
         return {"page_title": post["title"], "post": post, "comments":comments}
     else:
         db.add_comment(postid,name,title,body)
         raise cherrypy.HTTPRedirect("")
Ejemplo n.º 3
0
def index():
    if request.method == 'POST':
        db.add_comment(request.form['comment'])

    search_query = request.args.get('q')

    comments = db.get_comments(search_query)

    return render_template('index.html',
                           comments=comments,
                           search_query=search_query)
Ejemplo n.º 4
0
	def post(self):

		m = self.get_argument("m","")
		id = self.get_argument("id","")
		name = self.get_argument("name","")
		mail = self.get_argument("mail","")
		url = self.get_argument("url","")
		content = self.get_argument("content","")

		if m == "add_comments":
			db.add_comment(id,name,mail,url,content)

		self.redirect("/article?id=%s" % id)
Ejemplo n.º 5
0
def comment():
    # Post a comment
    # Form on page sends over the appropriate fields
    item_id = request.form['item_id']
    comment = request.form['comment']

    # Don't really care for success values of commenting
    # If user tries to cheat and send random item_id, the add_comment function
    # will handle it
    # Nothing will happen if item_id is not visible to commenter, which is fine
    # because if users follows the rules it should work fine
    # Users not following the rules will not break the database
    add_comment(item_id, comment, session['email'])

    # Just redirect to index page
    return redirect('/')
Ejemplo n.º 6
0
def add_comment():
    res = input("Want to add a comment? (y/n) ")
    if res != 'y':
        print("OK, no comment.")
        return

    ids = db.all_post_ids()
    # noinspection PyBroadException
    try:
        pick = int(input('Choose a post to comment upon: {}'.format(ids)))
        comment = input(
            "Enter your comment on a single line (enter to save):\n\n")
    except:
        print("That wasn't a good choice! (need a valid number)")
        return

    db.add_comment(pick, comment)
Ejemplo n.º 7
0
def view_post(post_id):
    form = forms.Comment()
    if form.validate_on_submit():
        db.add_comment(post_id, session['user_id'], form.comment.data)
        return redirect(url_for('view_post', post_id=post_id))
        # form=forms.Comment(comment='')
    posts = db.post_list_by_post_id(post_id)
    comments = db.comment_list_by_post_id(post_id)
    if len(posts) == 0:
        abort(404)
    if len(comments) > 500:
        abort(404)
    return render_template('stream.html',
                           stream=posts,
                           use=1,
                           form=form,
                           comments=comments)
Ejemplo n.º 8
0
def add_comment(conn, commenter_id, project_id, message):
    """add_comment - add a new comment to this project
    :param conn: sqllite3 db connection
    :param commenter_id: (string) commenter uuid
    :param project_id: (string) project_id
    :param message: (string) message text
    :return:
        returns value from db.add_comment()
    """
    return db.add_comment(conn, commenter_id, project_id, message)
Ejemplo n.º 9
0
 def sub(self, item, conn):
     self._require_admin(conn.user)
     u = yield find_user.by_prefix_for_user(item, conn)
     if u:
         if not u.is_muted:
             raise ListError(_('%s is not on the mute list.\n') % u.name)
         yield u.set_muted(False)
         if not u.is_guest:
             yield db.add_comment(conn.user.id_, u.id_, 'Unmuted.')
         self._notify_removed(conn, u)
Ejemplo n.º 10
0
def new_comment():
    sudoku_id = request.form["sudoku_id"]

    error = None
    if "user_id" not in session:
        error = "comment_no_user"
    elif "csrf_token" not in session or "csrf_token" not in request.form:
        error = "no_csrf_token"
    elif session["csrf_token"] != request.form["csrf_token"]:
        error = "invalid_csrf_token"

    if error: redirect("/sudoku/" + sudoku_id + "?err=" + error)

    user_id = session["user_id"]
    rating = request.form["rating"]
    content = request.form["comment"]

    db.add_comment(user_id, sudoku_id, rating, content)

    return redirect("/sudoku/" + sudoku_id)
Ejemplo n.º 11
0
 def sub(self, item, conn):
     self._require_admin(conn.user)
     u = yield find_user.by_prefix_for_user(item, conn)
     if u:
         if u.is_guest:
             raise ListError(A_('Only registered players can be banned.\n'))
         if not u.is_banned:
             raise ListError(_('%s is not on the ban list.\n') % u.name)
         yield u.set_banned(False)
         yield db.add_comment(conn.user.id_, u.id_, 'Unbanned.')
         self._notify_removed(conn, u)
Ejemplo n.º 12
0
 def add(self, item, conn):
     self._require_admin(conn.user)
     u = yield find_user.by_prefix_for_user(item, conn)
     if u:
         if u.is_admin():
             raise ListError(A_('Admins cannot be playbanned.\n'))
         if u.is_playbanned:
             raise ListError(
                 _('%s is already on the playban list.\n') % u.name)
         yield u.set_playbanned(True)
         if not u.is_guest:
             yield db.add_comment(conn.user.id_, u.id_, 'Playbanned.')
         self._notify_added(conn, u)
Ejemplo n.º 13
0
def add_comment(body):  # noqa: E501
    """Add a new comment

     # noqa: E501

    :param body: Comment details to be added
    :type body: dict | bytes

    :rtype: None
    """
    if connexion.request.is_json:
        body = connexion.request.get_json()
    return {"id": db.add_comment(body)}
Ejemplo n.º 14
0
def new_comment():
    if not auth.is_login():
        return jsonify({'status': 'not_login'})
    current_user = session.get('current_user')
    current_user = db.db_session.query(
        db.User).filter(db.User.u_name == current_user).first()
    u_id = current_user.u_id
    data = request.get_json()
    p_id = data['p_id']
    c_content = data['c_content']
    f_id = data['f_id']
    db.add_comment(u_id, p_id, c_content, f_id)
    all_comments = db.get_all_comments(p_id)
    comments = []
    for i in all_comments:
        commit_user = db.get_user_by_id(i.u_id)
        if i.f_id == 0:
            comments.append([
                i.c_id, i.u_id, i.p_id, i.c_content, i.f_id,
                commit_user.u_head_img, commit_user.u_nickname, 0, 0
            ])
        else:
            f_user = db.get_user_by_f_id(i.f_id)
            comments.append([
                i.c_id, i.u_id, i.p_id, i.c_content, i.f_id,
                commit_user.u_head_img, commit_user.u_nickname, f_user.u_id,
                f_user.u_nickname
            ])
    post_obj = db.db_session.query(
        db.Post).filter(db.Post.p_id == p_id).first()
    post = [
        post_obj.p_id, post_obj.p_title, post_obj.p_content,
        post_obj.p_create_at, post_obj.p_count_comments, post_obj.b_id,
        post_obj.u_id
    ]
    return jsonify({'comments': comments, 'post': post})
Ejemplo n.º 15
0
 def add(self, item, conn):
     self._require_admin(conn.user)
     u = yield find_user.by_prefix_for_user(item, conn)
     if u:
         if u.is_guest:
             raise ListError(
                 A_('Only registered players can be c-muzzled.\n'))
         if u.is_admin():
             raise ListError(A_('Admins cannot be c-muzzled.\n'))
         if u.is_cmuzzled:
             raise ListError(
                 _('%s is already on the cmuzzle list.\n') % u.name)
         yield u.set_cmuzzled(True)
         yield db.add_comment(conn.user.id_, u.id_, 'C-muzzled.')
         self._notify_added(conn, u)
Ejemplo n.º 16
0
def delete_project_test():
    add_project("111", "Test Project", "*****@*****.**",
                "8bde3e84-a964-479c-9c7b-4d7991717a1b")
    add_comment("0", "55555", "fake user", "fake user's message", "111")
    add_comment("1", "55555", "fake user", "fake user's second message", "111")
    add_comment("2", "55555", "fake user", "fake user's last message", "111")
    path = BASE_URL + "/projects/111"

    headers = {
        "Accept": "application/json",
        "Content-Type": "application/json",
        "Authorization": "Bearer " + ACCESS_TOKEN_1
    }

    r = requests.delete(path, headers=headers)
    data = r.json()
    for k in data:
        print k, data[k]
Ejemplo n.º 17
0
def get_project_test():
    """
    Tests get method on /projects/<id> endpoint.
    """
    add_project("111", "Test Project", "*****@*****.**",
                "8bde3e84-a964-479c-9c7b-4d7991717a1b")
    add_comment("0", "55555", "fake user", "fake user's message", "111")
    add_comment("1", "55555", "fake user", "fake user's second message", "111")
    add_comment("2", "55555", "fake user", "fake user's last message", "111")
    path = BASE_URL + "/projects/111"

    for access_token, username in [(ACCESS_TOKEN_1, USERNAME_1),
                                   (ACCESS_TOKEN_2, USERNAME_2)]:
        headers = {
            "Accept": "application/json",
            "Content-Type": "application/json",
            "Authorization": "Bearer " + access_token
        }

        r = requests.get(path, headers=headers)
        data = r.json()
        for k in data:
            print k, data[k]
    delete_project("111")