コード例 #1
0
ファイル: index.py プロジェクト: 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("")
コード例 #2
0
    def test_get_comments(self):
        with db.connect_db() as conn:
            db_add(conn, tdc.TEST_ROWS['owners'])
            db_add(conn, tdc.TEST_ROWS['projects'])
            db_add(conn, tdc.TEST_ROWS['comments'])

            result = db.get_comments(conn, tdc.MOCK_PROJ_UUID_11)
            self.assertEqual(result[1][4], "Owner 1, project 1, comment 2")
コード例 #3
0
ファイル: handlers.py プロジェクト: metalman/magicoding
 def get(self, index):
     entry = db.get_entry(index)
     if not entry: raise tornado.web.HTTPError(404)
     # XXX maybe should do comments paging with ajax
     comment_start = self.get_argument("comment_start", None)
     comments, extra_comment = db.get_comments(index,
         comment_start, config.COMMENTS_PER_PAGE)
     self.render("entry.html",
         entry=entry, comments=comments, extra_comment=extra_comment)
コード例 #4
0
def advert(advert_id):

    advert = get_advert(advert_id)

    likes = get_likes(advert_id)

    comments = get_comments(advert_id)

    return jsonify(advert=advert, likes=likes, comments=comments)
コード例 #5
0
def index():
    if request.method == 'POST':
        global comments
        comment_title = request.form['title']
        comment_content = request.form['content']
        create_comment(comment_title, comment_content)

    comments = get_comments()
    return render_template('index.html', comments=comments)
コード例 #6
0
def details(id):
    page = int(request.args.get("page", 0))
    query = request.args.get("query", "").strip()
    query = query if query else "*:*"
    comments = get_comments(id)
    read_mention(g.user["id"], id)
    view_permissions = [p[5:] for p in g.permissions if p.startswith("VIEW_")]
    # g.document["summary"] = repr(g.document["summary"])[1:-1]
    return render_template("practice/details.html", practice=g.document, comments=comments, page=page, query=query,
                           master=get_master_dictionary(), actions=get_next_state(g.document["status"]),
                           more_like_this=g.more_like_this, view_permissions=view_permissions)
コード例 #7
0
 def get(self, index):
     entry = db.get_entry(index)
     if not entry: raise tornado.web.HTTPError(404)
     # XXX maybe should do comments paging with ajax
     comment_start = self.get_argument("comment_start", None)
     comments, extra_comment = db.get_comments(index, comment_start,
                                               config.COMMENTS_PER_PAGE)
     self.render("entry.html",
                 entry=entry,
                 comments=comments,
                 extra_comment=extra_comment)
コード例 #8
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)
コード例 #9
0
def get_comments(postID):  # noqa: E501
    """Finds all comments of a post

    Get a list of comments for a particular post # noqa: E501

    :param postID: Post ID for getting comments
    :type postID: str

    :rtype: List[Comment]
    """
    comments = db.get_comments(postID)
    return comments
コード例 #10
0
def fetch_comments(data):
    post_id = data['post_id']
    comments = get_comments(post_id)
    parse_comments = []
    for comment in comments:
        parse_comments.append({
            'username': comment['username'],
            'comment': comment['comment'],
            'time': comment['time']
        })
    data = [{'post_id': post_id}]
    data.append(parse_comments)
    socketio.emit('send_comments', data=data)
コード例 #11
0
ファイル: app.py プロジェクト: BachToTheFuture/Spool
def comment():
    current_user = flask_login.current_user
    comment = request.form['comment']
    thread_id = request.form["id"]
    color = request.form["color"]
    db.create_comment(thread_id, {
        "author": current_user.id,
        "content": comment,
        "color": color
    })

    thread = db.get_comments()
    return render_template('index.html',
                           page_name="index",
                           current_user=current_user,
                           main_thread=thread)
コード例 #12
0
ファイル: app.py プロジェクト: svv232/DB_Project
def get_comment():
    # Login required decorator ensures only logged in users can get comments
    # Async request from JavaScript to fetch this info
    # Request sends item_id of post to fetch comments for as json
    item_id = request.get_json().get('item_id')

    # First return value is status code which we don't need outside of debug
    # situations. Mostly following convention here.
    _, content = get_comments(item_id, session['email'])

    # Content is the results of the query
    # If no comments then empty JSON array is sent
    for comment in content:
        # Datetime cannot be json serialized
        # First convert all datetimes to strings
        comment['comment_time'] = str(comment['comment_time'])

    # Return back comments as JSON
    return json.dumps(content)
コード例 #13
0
ファイル: app.py プロジェクト: BachToTheFuture/Spool
def index():
    if request.form:
        # If inputPassword2 field is not empty, this is a registration.
        name = request.form["username"]
        pwrd = request.form["password"]
        # Registration
        if request.form["password2"]:
            # Check for illegal characters in the name
            for x in name:
                if not re.match(r'[A-Za-z0-9_]+$', name):
                    flash(
                        "Your name has an illegal character! Only letters, numbers, and underscores are allowed."
                    )
                    return render_template('index.html',
                                           page_name="index",
                                           current_user=False)
            if (pwrd != request.form["password2"]):
                flash("Passwords do not match!")
                return render_template('index.html',
                                       page_name="index",
                                       current_user=False)
            if (len(pwrd) < 6):
                flash("Password must be at least 6 characters.")
                return render_template('index.html',
                                       page_name="index",
                                       current_user=False)
            if db.get_user_by("username", name):
                flash("User '{}' already exists!".format(name))
                return render_template('index.html',
                                       page_name="index",
                                       current_user=False)
            else:
                print("New user {} registered!".format(name))
                db.create_user(name, pwrd)
                flash("User created!")
                return render_template('index.html',
                                       page_name="index",
                                       newuser=True,
                                       current_user=False)
        # Validated user
        elif db.verify_user(name, pwrd):
            print(name, "has been verified!")
            user = User()
            user.id = name
            flask_login.login_user(user)
            return redirect("/")
        else:
            flash("Incorrect credentials!")
            return render_template('index.html',
                                   page_name="index",
                                   current_user=False)
    else:
        current_user = flask_login.current_user
        # Structure of threads
        thread = db.get_comments()
        # If the user isn't logged in the id isn't defined
        try:
            current_user.id
        except:
            current_user = None
        return render_template('index.html',
                               page_name="index",
                               current_user=current_user,
                               main_thread=thread)
コード例 #14
0
ファイル: manager.py プロジェクト: alexmerser/mylog
    def get(self, page):

        # 校验身份
        if self.check_login() == False:
            self.redirect("/login")
            return

            # 处理请求页面
        if 1 == 1:

            if page == "index":
                self.MyRender(admin_dir("%s.html" % page), classify=db.get_classify())

                # 文章管理
            elif page == "articles":
                self.MyRender(admin_dir("%s.html" % page), articles=db.get_article())

                # 更新文章
            elif page == "update":

                id = self.get_argument("id")
                self.MyRender(
                    admin_dir("%s.html" % page), classify=db.get_classify(), article=db.get_atcbyid(id, True), id=id
                )

                # 评论管理
            elif page == "comments":

                self.MyRender(admin_dir("%s.html" % page), comments=db.get_comments())

                # 留言管理
            elif page == "guests":

                self.MyRender(admin_dir("%s.html" % page), guests=db.get_guest())

                # 留言管理
            elif page == "links":

                self.MyRender(admin_dir("%s.html" % page), links=db.get_links())

                # 分类管理

            elif page == "classify":

                self.MyRender(admin_dir("%s.html" % page), classify=db.get_classify())

                # 分类管理

            elif page == "upload":

                self.MyRender(admin_dir("%s.html" % page))

                # 博客配置
            elif page == "options":

                self.MyRender(admin_dir("%s.html" % page), templates=os.listdir(cur_dir() + "templates"))

                # 返回自定义页面
            else:
                # self.MyRender(admin_dir("%s.html" % page))
                self.redirect("/login")
        else:
            self.redirect("/login")