def addComment(): commentBody = request.form['commentBody'] tagsArr = request.form['tags'].split(',') print "tags: ", tagsArr print "comment body ", request.form['commentBody'] print "verrrdsflkfdskl ", request.form['verseId'] print "comment type", request.form['commentType'] print "verse id ", request.form['verseId'] print "in reply to", request.form['inReplyToCommentId'] comment_db = model.Comment( user_key=auth.current_user_key(), comment=request.form['commentBody'], verse_id=int(request.form['verseId']), commentType=request.form['commentType'], tags=tagsArr, ) try: comment_db.inReplyToCommentId = int(request.form['inReplyToCommentId']) print "did have a reply" except: print "didn't have a reply to id" comment_db.put() flask.flash('New comment was successfuly created!', category='success') print commentBody return commentBody
def comment_update(comment_id=0): if comment_id: comment_db = model.Comment.get_by_id(comment_id) else: comment_db = model.Comment(user_key=auth.current_user_key()) if not comment_db or comment_db.user_key != auth.current_user_key(): flask.abort(404) form = CommentUpdateForm(obj=comment_db) user_dbs, user_cursor = model.User.get_dbs(limit=-1) post_dbs, post_cursor = model.Post.get_dbs(limit=-1) form.post_key.choices = [(c.key.urlsafe(), c.title) for c in post_dbs] if flask.request.method == 'GET' and not form.errors: form.post_key.data = comment_db.post_key.urlsafe() if comment_db.post_key else None if form.validate_on_submit(): form.post_key.data = ndb.Key(urlsafe=form.post_key.data) if form.post_key.data else None form.populate_obj(comment_db) comment_db.put() return flask.redirect(flask.url_for('comment_view', comment_id=comment_db.key.id())) return flask.render_template( 'comment/comment_update.html', title=comment_db.content if comment_id else 'New Comment', html_class='comment-update', form=form, comment_db=comment_db, )
def admin_comment_update(comment_id=0): if comment_id: comment_db = model.Comment.get_by_id(comment_id) else: comment_db = model.Comment(user_key=auth.current_user_key()) if not comment_db: flask.abort(404) form = CommentUpdateAdminForm(obj=comment_db) user_dbs, user_cursor = model.User.get_dbs(limit=-1) post_dbs, post_cursor = model.Post.get_dbs(limit=-1) form.post_key.choices = [(c.key.urlsafe(), c.title) for c in post_dbs] if flask.request.method == 'GET' and not form.errors: form.post_key.data = comment_db.post_key.urlsafe() if comment_db.post_key else None if form.validate_on_submit(): form.post_key.data = ndb.Key(urlsafe=form.post_key.data) if form.post_key.data else None form.populate_obj(comment_db) comment_db.put() return flask.redirect(flask.url_for('admin_comment_list', order='-modified')) return flask.render_template( 'comment/admin_comment_update.html', title=comment_db.content, html_class='admin-comment-update', form=form, comment_db=comment_db, back_url_for='admin_comment_list', api_url=flask.url_for('api.admin.comment', comment_key=comment_db.key.urlsafe() if comment_db.key else ''), )
def generate(self, user, date): (a, b), c = getRandomGossip() news_outlet = choice(self.sources) post = model.Post(date, a, model.Image(c), news_outlet, None) comment = model.Comment(b, user, post) post.comments.append(comment) return post
def load_master(session): f = open("seed_data/u.master") rows = f.read().split("\n") f.close() for line in rows: row = line.split("|") name = row[0] email = row[1] phone_num = row[2] full_address = row[3] lat = row[4] lng = row[5] supply_type = row[6] extra_comment = row[-1] master = model.Master(name=name, email=email, phone_num=phone_num, full_address=full_address, lat=lat, lng=lng, supply_type=supply_type, extra_comment=extra_comment) user = model.User(name=name, email=email, phone_num=phone_num) location = model.Location(full_address=full_address, lat=lat, lng=lng) supply = model.Supply(supply_type=supply_type) comment = model.Comment(extra_comment=extra_comment) model.session.add(master) model.session.add(user) model.session.add(location) model.session.add(supply) model.session.add(comment)
def GET(self, food_id): food_id = int(food_id) food = model.Foods().view(food_id) if food: comment = model.Comment().list(food_id) return titled_render().view(food, comment) else: raise web.seeother('/')
def GET(self, food_id): food_id = int(food_id) model.Comment().ddel(food_id) model.Foods().ddel(food_id) manager_id = model.Manager().current_id() if manager_id: raise web.seeother('/manager/%d' % manager_id) else: raise web.notfound()
def GET(self, post_id): post_id = int(post_id) post = model.Post().view(post_id) if post: comment = model.Comment(int(post_id)) comments = comment.quote(comment.list()) comment_lis = util.comments_to_lis(comments) return titled_render(post.title).view(post, comment_lis) else: raise web.seeother('/')
def POST(self, food_id): i = web.input(mycomment='') food_id = int(food_id) cur_user_id = model.User().current_id() if cur_user_id: #comment = model.Comment(int(food_id)) comment_id = model.Comment().new(i.mycomment, cur_user_id, food_id) raise web.seeother("/view/%d" % food_id) else: return titled_render().failed('操作受限,请先<a href="/login">登录</a>')
def GET(self, comment_id): model.Comment().del_ones(comment_id) user_id = model.User().current_id() manager_id = model.Manager().current_id() if user_id: raise web.seeother('/user/%d' % user_id) else: if manager_id: raise web.seeother('/manager/%d' % manager_id) else: raise web.notfound()
def POST(self, post_id): # jQuery+Ajax实现无刷新回帖 i = web.input() cur_user_id = model.User().current_id() web.header('Content-Type', 'application/json') if cur_user_id: comment = model.Comment(int(post_id)) # 回帖成功:返回"回帖"+"引用贴"信息 if comment.new(i.content, cur_user_id, i.quote_id): comments = comment.quote([comment.last()]) return json.dumps(util.comments_to_lis(comments)) # 无权限:返回空 return json.dumps([])
def post(self): # 文章的鍵值 article_key = self.request.get('key') article = db.get(article_key) # 讀取參數 username = self.request.get('username') message = self.request.get('comment') # 新增一筆留言資料 comment = model.Comment(parent=article, article=article, user=username, comment=message) comment.put() self.redirect('/article/%s' % article_key)
def GET(self, post_id): post_id = int(post_id) cur_user_id = model.User().current_id() post = model.Post().view(post_id) # 只有作者(已登录)才能删除自己的文章 if post and post['user_id'] == cur_user_id: # 删除文章的同时也会删除相关的所有评论 model.Comment(post_id).ddel() model.Post().ddel(post_id) raise web.seeother('/account/posts') elif cur_user_id: # 用户已登录,但不是作者 return titled_render().failed('操作受限,你无权删除其他人的文章') else: # 用户未登录 return titled_render().failed('操作受限,请先<a href="/login">登录</a>')
def make_comment(): assert_is_authenticated() html_section = request.args.get("html_section") comment = request.form.get("comment") section = model.Section.from_html_section(html_section) user_id = get_user_id() new_comment = model.Comment(comment=comment, section_id=section.id, user_id=user_id) model.session.add(new_comment) model.session.commit() return redirect(url_for('show_comments', html_section=html_section))
async def api_create_comment(id, request, *, content): user = request.__user__ if user is None: raise APIPermissionError('Please signin first.') if not content or not content.strip(): raise APIValueError('content') blog = await model.Blog.find(id) if blog is None: raise APIResourceNotFoundError('Blog') comment = model.Comment(blog_id=blog.id, user_id=user.id, user_name=user.name, user_image=user.image, content=content.strip()) await comment.save() return comment
def scriptures_verse(volume_name, book_name, chapter_num, verse_num): selectedVolume = volumesObjects[volume_name] selectedBook = selectedVolume["books"][book_name] query = model.Verse.query(model.Verse.book_id == selectedBook['book_id'], model.Verse.chapter == chapter_num).order( model.Verse.verse_id) verse_dbs = query.fetch() verse_id = None for tmpverse in verse_dbs: if tmpverse.verse == verse_num: verse_id = tmpverse.verse_id form = CommentAddForm() if form.validate_on_submit(): tagsArr = form.tags.data.split(',') comment_db = model.Comment( user_key=auth.current_user_key(), comment=form.comment.data, verse_id=verse_id, commentType=form.commentType.data, tags=tagsArr, ) comment_db.put() flask.flash('New comment was successfuly created!', category='success') query = model.Comment.query( model.Comment.verse_id == verse_id).order(-model.Verse.created) comment_dbs = query.fetch() for c in comment_dbs: c.userObject = c.user_key.get() return flask.render_template('scripture_selector.html', html_class='scripture', title='Scripture Selector', selectedVolume=selectedVolume, selectedBook=selectedBook, chapterNum=chapter_num, volumeName=volume_name, bookName=book_name, verse_dbs=verse_dbs, verseNum=verse_num, verseId=verse_id, form=form, comment_dbs=comment_dbs)
def GET(self, user_id): user_id = int(user_id) status = model.User().status(user_id) if status['username']: if user_id == model.User().current_id(): my_messages = model.MessageBoard().show(user_id) my_comments = model.Comment().show_ones(user_id) return titled_render(status['username']).master_profile( status['username'], status['picture'], status['description'], status['email'], my_messages, my_comments) else: return titled_render(status['username']).user_profile( status['username'], status['picture'], status['description']) else: raise web.notfound()
def post(self, post_id): args = comment_parser.parse_args() # find post post = model.Post.query.filter_by(id=post_id).first() if post == None: raise NotFoundException() # create comment author_name = args["authorName"] if args["authorName"] else localize("Anonymous") comment = model.Comment(body=args.body, author_name=author_name) post.comments.append(comment) model.db.session.add(comment) model.db.session.commit() return comment
def writeComment(req): info = '' ret_data = {} aid = req['aid'] try: comm = model.Comment(content=req['content'], uid=req['uid'], aid=aid) model.db.session.add(comm) model.db.session.commit() ret_data['cid'] = comm.id except Exception as e: info = 'write answer error : handle database failure' print e logger.error(info) logger.error(e.message) return False, DB_ERR_HAND, info, ret_data info = 'write answer success' # logger.info(info) return True, SUCCESS, info, ret_data
def post(self, post_id): if not self.user: self.redirect('/login') return #check post post = model.Post.by_id(long(post_id)) if not post: self.error(404) return #check author is_author = post.author.key().id() == self.user.key().id() content = self.request.get('content') if content: comment = model.Comment(content=content, author=self.user, post=post) comment.put() # reloads the page time.sleep(0.1) self.redirect(self.request.referer)
def comment(self, who: model.User, what: model.Reactable, text: str): comment = model.Comment(text, who, what) what.comments.append(comment) self.notify_activity(comment) return comment
def on_comment(self, target: model.Reactable, text: str): cmnt = model.Comment(text, model.User.main_user(), target) target.comments.append(cmnt) self.notify_activity(cmnt) for friend in model.friends: self.react(friend, cmnt, model.Reaction.FUCK_YOU)