コード例 #1
0
ファイル: app.py プロジェクト: making3/summonerqa-svc
def dump_comments():
    # TODO: Make sure this is the Weekly QA thread
    qa_sticky = r.get_sticky("summonerschool", bottom=False)

    for rcomment in qa_sticky.comments:
        if hasattr(rcomment, "body"):
            comment = db.Comment(rcomment)
            db.insert_comment(comment)
コード例 #2
0
def comment():
    if session["csrf_token"] != request.form["csrf_token"]:
        abort(403)
    review_id = request.form["id"]
    username = session["username"]
    user_id = db.find_user_id(username)
    writing = request.form["comment"]
    db.insert_comment(review_id, user_id, writing)
    page = "/review/" + str(review_id)
    return redirect(page)
コード例 #3
0
def create():
    page = int(request.args.get("page", 0))
    query = request.args.get("query", "").strip()
    query = query if query else "*:*"

    if request.method == "POST":
        docs = solr.search("*:*", **{"sort": "_id_int desc", "rows": 1,
                                     "fl": "_id_int", "wt": "json"}).docs
        max_id = docs[0]["_id_int"] if len(docs) > 0 else 0
        doc = request.form.to_dict(flat=False)
        doc["id"] = max_id + 1
        solr.add([doc], commit=False, softCommit=True)
        flash({"status": "alert-success", "text": "New item has been successfully created."})
        insert_comment(doc["id"], g.user["id"], "Document has been <mark>created</mark>.")
        return redirect(url_for("practice.index", go_to_last_page=True))

    return render_template("practice/create.html", page=page, query=query, master=get_master_dictionary())
コード例 #4
0
def iterate_comments(state, submission, conn):
    """
    TODO: Docstring
    """

    comments = generate_comments(state.reddit, submission.id)
    praw_timer(state.reddit)
    for j in list(comments):
        try:
            comment = (str(j.author), str(utc_to_local(j.created_utc)),
                       str(j.id), str(j.body), str(submission.id))
            db.insert_comment(conn, comment)
        except AttributeError as err:
            print(err)
            continue
        state.update_praw()
        state.inc_comment()
コード例 #5
0
def action(id):
    page = int(request.args.get("page", 0))
    query = request.args.get("query", "").strip()
    query = query if query else "*:*"
    next_states = get_next_state(g.document["status"], request.form["action"].upper())

    if len(next_states) != 0:
        next_status = next_states[0]["next"]
        solr.add([{"id": str(id), "status": next_status}], fieldUpdates={"status": "set"}, commit=False,
                 softCommit=True)
        flash({"status": "alert-{}".format(STATUS_BADGE_STYLE[next_status]),
               "text": "Item {} has been successfully {}.".format(id, next_status)})
        insert_comment(id, g.user["id"], "Document has been <mark>{}</mark>.".format(next_status.lower()))
    else:
        flash({"status": "alert-danger", "text": "Item {} status update failure due to version conflict.".format(id)})
        return redirect(url_for("practice.details", id=id, page=page, query=query))

    return redirect(url_for("practice.index", page=page, query=query))
コード例 #6
0
def comment_handler(h, p=None):
    global opts
    msg = ''
    # Добавление комментария
    if h.method != 'GET':
        try:
            db.insert_comment(p)
        except db.DBException as e:
            msg = e.message
        except:
            msg = "При добавлении комментария произошла ошибка"
        else:
            msg = "Комментарий добавлен успешно"
        msg = "alert('%s')" % msg
    html = view.HTMLObject('Оставить комментарий')
    html.Script(func=view.comment_script, content=msg)
    html.Style(func=view.main_css, param=dict(filename=opts.css_file))
    html.Body(func=view.html_form)
    return str(html)
コード例 #7
0
 def comment(self):
     pid = int(self.argv[1])
     comment = ""
     argi = 2
     while argi < len(self.argv):
         comment = self.argv[
             argi] if comment == "" else comment + " " + self.argv[argi]
         argi += 1
     if db.insert_comment(pid, self.username, comment) == 0:
         return "Comment successfully."
     else:
         return "Post does not exist."
コード例 #8
0
    def comment(self):
        pid = int(self.argv[1])
        if not db.post_existed_check(pid):
            return "Post does not exist."

        comment = self.username + ":"
        argi = 2
        while argi < len(self.argv):
            comment += (" " + self.argv[argi]) if comment != self.username + ":" else self.argv[argi]
            argi += 1
        result = db.insert_comment(pid)
        bucket = db.get_bucket(result[0])
        comment_object_name = result[1]
        return '&<!comment::>' + bucket + '&<!spl>' + comment_object_name + '&<!spl>' + comment + '&<!meta|msg>Comment successfully.'
コード例 #9
0
ファイル: app.py プロジェクト: froi/morsel
def add_comment(snippet_id):
    snippet = db.get_snippet_details(snippet_id)
    try:
        comment_text = request.form["comment"].strip()

        comment = db.insert_comment(comment_text, current_user.username)

        snippet.comments.append(comment)

        snippet.save()

        flash("Comment added.", "success")
    except Exception as e:
        print e
        flash("Error adding comment to snippet.", "error")

    return redirect(url_for("snippet_view", snippet_id=snippet_id))
コード例 #10
0
def add_comment(advert_id):
    creator = request.authorization.username

    check = comments_limit(creator)

    if check[0] is False:
        return jsonify(check[1])

    try:
        comment = request.get_json()['comment']
    except Exception as e:
        print(e)
        return jsonify("Should be a field 'comment'")

    check = comment_is_valid(creator, comment)

    if check[0] is False:
        return jsonify(check[1])

    status = insert_comment(creator, comment, advert_id)
    return jsonify([status, "detail view: /api/advert/{}".format(advert_id)])
コード例 #11
0
def comment(id):
    page = int(request.args.get("page", 0))
    query = request.args.get("query", "").strip()
    query = query if query else "*:*"
    insert_comment(id, g.user["id"], request.form["comment"])
    return redirect(url_for("practice.details", id=id, page=page, query=query))