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("")
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")
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)
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)
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)
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)
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)
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
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)
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)
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)
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)
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")