def show(id): if not g.db.doc_exist(id): abort(404) errors = [] task = Task.get(id) form = CommentForm(request.form) comments = list(Comment.view('comments/by_task_id', key=id)) comments = sorted(comments, key=lambda x: x.date) if request.method == 'POST' and form.validate(): new_comment = Comment() new_comment.author = session['username'] new_comment.text = form.text.data new_comment.date = datetime.datetime.utcnow() new_comment.task_id = id new_comment.save() flash('Comment was successfully added') return redirect(url_for('tasks.show', id=id)) fpath = os.path.join(UPLOADED_FILES, id) files = None if os.path.exists(fpath): files = os.listdir(fpath) errors.extend(format_form_errors(form.errors.items())) return render_template('task_show.html', \ task = task, comments = comments, form = form, errors = errors, \ files = files)
def show(id): if not g.db.doc_exist(id): abort(404) errors = [] task = Task.get(id) form = CommentForm(request.form) comments = list(Comment.view('comments/by_task_id', key = id)) comments = sorted(comments, key = lambda x: x.date) if request.method == 'POST' and form.validate(): new_comment = Comment() new_comment.author = session['username'] new_comment.text = form.text.data new_comment.date = datetime.datetime.utcnow() new_comment.task_id = id new_comment.save() flash('Comment was successfully added') return redirect(url_for('tasks.show', id = id)) fpath = os.path.join(UPLOADED_FILES, id) files = None if os.path.exists(fpath): files = os.listdir(fpath) errors.extend(format_form_errors(form.errors.items())) return render_template('task_show.html', \ task = task, comments = comments, form = form, errors = errors, \ files = files)
def news_replies(id): form = CommentForm() comments = Comments_news.query.filter_by(id=id).first() if form.validate(): reply = Replies_news(datetime.datetime.now(),form.body.data,form.author.data,id) db.session.add(reply) db.session.commit() return render_template('news_comment.html',comment=comments,form=form)
def news_replies(id): form = CommentForm() comments = Comments_news.query.filter_by(id=id).first() if form.validate(): reply = Replies_news(datetime.datetime.now(), form.body.data, form.author.data, id) db.session.add(reply) db.session.commit() return render_template('news_comment.html', comment=comments, form=form)
def news_comment(id): form = CommentForm() cur = mysql.connect().cursor() sql = "select newsid, Picture, Content, Name from news WHERE newsid=%s" %(id) cur.execute(sql) news = cur.fetchone() p = re.compile(r'<.*?>') new = p.sub('', news[2]) if form.validate(): comment = Comments_news(newsid=id,created_at=datetime.datetime.now(),body=form.body.data,author=form.author.data) db.session.add(comment) db.session.commit() return render_template('news_comment.html',news=news,new=new,form=form)
def comment(id): form = CommentForm() phon = "" phones = [Samsung,Apple,Microsoft,Nokia,Sony,LG,HTC,Motorola,Huawei,Lenovo,Xiaomi,Acer,Asus,Oppo,Blackberry,Alcatel, ZTE,Toshiba,Gigabyte,Pantech,XOLO,Lava,Micromax,BLU,Spice,Verykool,Maxwest,Celkon,Gionee,Vivo,NIU,Yezz,Parla,Plum] for phone in phones: if not phon: phon = db.session.query(phone).filter_by(phoneId=id).first() if form.validate(): comment = Comments(id,datetime.datetime.now(),form.body.data,form.author.data) db.session.add(comment) db.session.commit() return render_template('comment.html',phone=phon,form=form)
def news_comment(id): form = CommentForm() cur = mysql.connect().cursor() sql = "select newsid, Picture, Content, Name from news WHERE newsid=%s" % ( id) cur.execute(sql) news = cur.fetchone() p = re.compile(r'<.*?>') new = p.sub('', news[2]) if form.validate(): comment = Comments_news(newsid=id, created_at=datetime.datetime.now(), body=form.body.data, author=form.author.data) db.session.add(comment) db.session.commit() return render_template('news_comment.html', news=news, new=new, form=form)
def post_view(id): form = CommentForm() comments = Comment.query.filter_by(post_id=id).order_by( Comment.timestamp.desc()).all() post = Post.query.filter_by(id=id).first_or_404() if form.submit2.data and form.validate(): comment = Comment(body=form.body.data, post_id=post.id, author_id=current_user.id) db.session.add(comment) db.session.commit() flash('Your comment has been added') return redirect(url_for('post_view', id=post.id)) return render_template('post.html', post=post, title='post', form=form, comments=comments)
def comment(id): form = CommentForm() phon = "" phones = [ Samsung, Apple, Microsoft, Nokia, Sony, LG, HTC, Motorola, Huawei, Lenovo, Xiaomi, Acer, Asus, Oppo, Blackberry, Alcatel, ZTE, Toshiba, Gigabyte, Pantech, XOLO, Lava, Micromax, BLU, Spice, Verykool, Maxwest, Celkon, Gionee, Vivo, NIU, Yezz, Parla, Plum ] for phone in phones: if not phon: phon = db.session.query(phone).filter_by(phoneId=id).first() if form.validate(): comment = Comments(id, datetime.datetime.now(), form.body.data, form.author.data) db.session.add(comment) db.session.commit() return render_template('comment.html', phone=phon, form=form)
def comment(): if request.method == 'POST': form_comment = CommentForm(request.form) if form_comment.validate(): print(form_comment.data) post_comment = Comments(**form_comment.data) db.session.add(post_comment) db.session.commit() return f"{ form_comment.data['first_id']} Comment created", 200 else: return 'Not valid comment !!', 200 else: return 'Wrong comment response', 404
def post(self, user): # grab the form form = CommentForm(self.request.params) if not form.validate(): form.csrf_token.data = self.generate_csrf() self.r(form) return # get the comment try: comment = Key(urlsafe=form.key.data).get() except: # invalid key comment = None if comment is None: self.redirect('/') return if comment.author != user: self.redirect('/') return # better be a post here or else! post = comment.key.parent().get() if post is None: self.redirect('/') return # update the comment try: comment.content = form.comment.data comment.put() self.redirect('/post/view?key=%s' % post.key.urlsafe()) return except: # let's give them another chance form.csrf_token.data = self.generate_csrf() self.r(form, flashes=flash()) return
def post(self, user): # grab the form form = CommentForm(self.request.params) # check the form if not form.validate(): form.csrf_token.data = self.generate_csrf() self.redirect(self.request.referer) return # need the key k = form.key.data try: # grab the post from the given key post = Key(urlsafe=k).get() except: post = None # key was invalid. No alert to user because this # shouldn't happen under normal navigation if post is None: self.redirect(self.request.referer) return try: # create the comment comment = Comment(parent=post.key, author=user, content=form.comment.data) comment.put() # go back to the post self.redirect(self.request.referer) return except Exception as e: # go back to post if we fail :( self.redirect(self.request.referer) return
def staticUnity(slug): if request.method == 'POST': unity = Unity.get_or_404(slug=slug) form = CommentForm() if not form.validate(): return render_template('unity/staticUnity.html', pageTitle=unity.title, unity=unity, form=form) else: newComment = Comment(body=form.comment.data) newComment.author = User.get(email=current_user.email) unity.comments.append(newComment) unity.save() form.comment.data = None # resets field on refresh flash('Comment Posted') return render_template('unity/staticUnity.html', pageTitle=unity.title, unity=unity, form=form) elif request.method == 'GET': try: return render_template('unity/%s.html' % slug, pageTitle=slug) except TemplateNotFound: unity = Unity.get_or_404(slug=slug) currentUser = User.get(email=current_user.email) if (unity.postType == 'draft' and unity.author != currentUser and currentUser.is_admin() is False): flash('You must be draft author or admin to view.') return redirect(url_for('.listUnity')) else: form = CommentForm() return render_template('unity/staticUnity.html', pageTitle=unity.title, unity=unity, form=form)