def projectView(username, project): form = EditProjectForm() allUsers = User.query.filter(User.username != "admin").all() currentRole = User.query.filter_by( username=current_user.username).first_or_404() user = User.query.filter_by(username=username).first_or_404() proj = Projects.query.filter_by(id=project).first_or_404() comments = Comments(comment_id=proj.id).query.filter_by( comment_id=project).all() comment = Comments(comment_id=proj.id) if form.validate_on_submit(): proj.description = form.description.data proj.company = form.company.data if form.priority.data == "": form.priority.data = "9999" proj.priority = form.priority.data proj.priority_dept = form.priority_dept.data proj.requester = form.requester.data proj.status = form.status.data proj.department = form.department.data proj.ticket = form.ticket.data proj.hours = form.hours.data comment.comment = form.comment.data if comment.comment != "": db.session.add(comment) db.session.commit() flash('Project Updated!') return redirect( url_for('projectView', username=username, comment=comments, project=project)) elif request.method == 'GET': form.description.data = proj.description form.company.data = proj.company if proj.priority == "9999": proj.priority = "" if proj.priority_dept == "9999": proj.priority_dept = "" form.priority.data = proj.priority form.priority_dept.data = proj.priority_dept form.requester.data = proj.requester form.status.data = proj.status form.department.data = proj.department form.ticket.data = proj.ticket form.hours.data = proj.hours return render_template('editprojects.1.html', title='Edit Project', user=user, form=form, comment=comments, project=proj, allUsers=allUsers, currentRole=currentRole, jfilesize=jfilesize, cfilesize=cfilesize, dev=username)
def detail(postid): form = CommentsForm() if form.validate_on_submit(): if not current_user.is_authenticated: flash('登录才能评论哦') return redirect(url_for('users.login')) else: user = current_user._get_current_object() post = Posts.query.get(postid) comment = Comments(content=form.content.data, user=user, post=post) db.session.add(comment) return redirect(url_for('main.detail', postid=postid)) post = Posts.query.get(postid) # 阅读数+1 post.views += 1 db.session.add(post) # 最热 最新 博文 Topposts = Posts.query.order_by(db.desc(Posts.views))[:5] Newposts = Posts.query.order_by(db.desc(Posts.timestamp))[:5] # 博文的评论 comments = Comments.query.filter_by(post=post).order_by( db.desc(Comments.timestamp)) return render_template('common/detail.html', post=post, Newposts=Newposts, Topposts=Topposts, form=form, comments=comments)
def iso_post(post_id): post = Post.query.get_or_404(post_id) adminForm = adminCommentForm() form = commentForm() comments = Comments.query.filter_by(post_id=post.id) if form.validate_on_submit(): com = Comments(comment=form.comment.data, user_id=current_user.id, post_id=post.id) db.session.add(com) db.session.commit() mail = Mail( post.author.email, f"There's a new comment on your post by {com.quoter.username}\n \"{com.comment}\" " ) mail.send() flash('Comment successfully added', 'success') return redirect(url_for('iso_post', post_id=post.id)) if adminForm.validate_on_submit(): post.admin_comment = adminForm.admin_comment.data db.session.commit() return render_template('post.html', title=post.title, post=post, adminForm=adminForm, form=form, comments=comments)
def post(postid): if request.method == "POST": name = request.form['comment-name'] comment = request.form['comment'] print('jsadfjasdf', name, comment) user = sess.query(Users).filter_by(id=session['user-id']).first() if name and comment: new_comment = Comments( username=user.username, comment_name=name, comment=comment, postid=postid, user_id=user.id ) sess.add(new_comment) sess.commit() return redirect(url_for('post', postid=postid)) else: if 'user-id' in session: postid = str(postid) data = sess.query(Posts).filter_by(id=postid).first() if data: comments = sess.query(Comments).filter_by(postid=postid).all() if not comments: comments = [] return render_template('post.html', post=data.post, user=data, image=data.image, comments=comments, coms_lenth=len(comments), postname=data.postname, id=data.id) return '<h1>Такого поста не существует</h1>' return redirect((url_for('login')))
def comment(self, request): # 读取请求 user_id = request.data.get('user_id') photo_id = request.data.get('photo_id') comment_text = request.data.get('comment_text') # 查询数据库 res = {'status': 0, 'msg': ''} try: user = User.objects.get(account=user_id) except User.DoesNotExist: user = None if not user: res['status'] = 401 res['msg'] = '账号不存在' return JsonResponse(res) try: photo = Photo.objects.get(photo_id=photo_id) except Photo.DoesNotExist: photo = None if not photo: res['status'] = 401 res['msg'] = '图片不存在' return JsonResponse(res) # 存入数据库 comment = Comments(comment=comment_text) comment.account = user comment.photo_id = photo comment.save() return JsonResponse(res)
def test_save_multiple_comment(self): self.new_comment.save_comment() self.second_her = User(username = '******', password='******', email='*****@*****.**') self.second_pitch = Pitch(title = 'test', content = 'hire',user_id = 2, category = 'interview') self.second_comment = Comments(id = 2, comment = 'test', user_id = 2, pitch = self.new_pitch) self.secpnd_comment.save_comment() self.assertTrue(len(Comments.query.all()),2)
def setUp(self): self.user_Collo = User(username="******", password="******", email="*****@*****.**") self.new_comment = Comments(pitch_id=10, pitch_title="Pitch", comments="Great")
def setUp(self): self.user_Collo = User(username="******", password="******", email="*****@*****.**") self.new_comment = Comments(pitch_id=10, pitch_title="Drone", comments="Nice app")
def create_life(structure_comments, post_id, owner_id, group_id, domain): if structure_comments.__len__() > 1: session = Session() time.sleep(random.randrange(10, 25)) for comment in structure_comments: if isinstance(comment, dict): for akk in akk_for_comment: if comment['from_id'] == akk['id']: if 'reply_to_cid' in comment: for created_comment in structure_comments: if isinstance(created_comment, dict): if created_comment['cid'] == comment['reply_to_cid']: comment_reply = vk_api.wall.createComment(owner_id='-' + str(owner_id), reply_to_comment=created_comment[ 'new_cid'], post_id=str(post_id), message=comment['text'], count='50', access_token=akk['token'], v='5.95') if comment_reply is not None: comment['new_cid'] = str(comment_reply['cid']) else: comment['new_cid'] = '' break else: comment_reply = vk_api.wall.createComment(owner_id='-' + str(owner_id), post_id=str(post_id), message=comment['text'], count='50', access_token=akk['token'], v='5.95') if comment_reply is not None: comment['new_cid'] = str(comment_reply['cid']) else: comment['new_cid'] = '' if 'new_cid' not in comment: comment['new_cid'] = '' if 'clen_text' in comment: if akk['id'] != '326786278': vk_api.messages.send(user_id='326786278', message=comment['clen_text'], access_token=akk['token'], v='5.95') utcnow = datetime.utcnow() session.add(Comments(body=comment['text'], timestamp=utcnow + timedelta(seconds=1), id_group=group_id, domain=domain)) print('Коментнул пост ' + str(akk['id'])) time.sleep(random.randrange(10, 25)) break session.commit() else: print('У поста нет комментов')
def test_func_save(self): comment = Comments(text='text', client_id=1, business_id=1, client_name='client_name', star=1) comment.save() self.assertEqual(comment, Comments.query.get(comment.id))
def setUp(self): self.user_Phil = User(username='******', password='******', email='*****@*****.**') self.new_comments = Comments(id=1, comment_section_id='This is a commentary', pitches_id=2, user_id=1)
def setUp(self): self.user_James = User(username='******', password='******', email='*****@*****.**') self.new_comment = Comments(post_id=12345, opinion='Review for movies', user_id=1, user=self.user_James)
def setUp(self): self.user_dean = Users(username='******', password='******', email='*****@*****.**') self.new_comment = Comments(email="*****@*****.**", username="******", comment="dope", blog_id=20)
def comment(blog_id): if request.method == 'POST': comment = request.form.get('comment') blog = Blog.query.filter_by(id=blog_id).first() comment = Comments(comment=comment, blog_id=blog.id) comment.save() return redirect(url_for('main.home', blog=blog)) return render_template('index.html')
def test_func_get_star(self): comment = Comments(text='text', client_id=1, business_id=1, client_name='client_name', star=1) db.session.add(comment) db.session.commit() self.assertEqual(comment.star, Comments.get_star(comment.id))
def new_comment(id): form = CommentForm() if form.validate_on_submit(): new_comment = Comments(comment_name=form.comment_name.data, user=current_user, blog_id=id) new_comment.save_comment() return redirect(url_for('.index')) return render_template('new_comment.html', form=form)
def comfunction(): comment = Comments.query.filter().all() form = CommentForm() if form.validate_on_submit(): com = Comments(content=form.content.data) db.session.add(com) db.session.commit() flash('Congratulations, you have issued!') return redirect(url_for('index')) return render_template('commentArea.html', form=form, comment=comment)
def setUp(self): """ Set up method that will run before every Test """ self.post = Post(category='Product', content='Yes we can!') self.user_Derrick = User(username='******', password='******', email='*****@*****.**') self.new_comment = Comments(text='This is good', user=self.user_Derrick)
def comment_process(): if request.method == 'POST': comment = request.form['comment'] user = current_user.id post_id = request.form['postid'] post = Upload.query.get(int(post_id)) brr = Comments(comment=comment,userid=user,post=post) db.session.add(brr) db.session.commit() return redirect(request.referrer)
def comment_answer(answer_id): if not (session and session.has_key('userid')): return "unauthorized" else: comment_value = request.data comment_value = comment_value.split("=")[1] new_comment = Comments(comment_value, session['userid'], None, answer_id) db.session.add(new_comment) db.session.commit() return "true"
def post_comments(): form = PostCommentsForm() if form.validate_on_submit(): comments = Comments() comments.body = form.body.data comments.user_id = current_user.id comments.news_id = request.args.get('nid') db.session.add(comments) db.session.commit() return redirect(url_for('.news', nid=comments.news_id)) return render_template('main/post_comments.html', form=form)
def add_comment(site_admin_id, username, comment_object_id, comment_text): try: comment = Comments(Username=username, CommentObjectId=comment_object_id, CommentText=comment_text, SiteAdminId=site_admin_id) logger.info(comment) db.session.add(comment) db.session.commit() except Exception as ex: logger.warning('func -- add_comment: ' + str(ex))
def setUp(self): self.user_her = User(username='******', password='******', email='*****@*****.**') self.new_pitch = Pitch(title='test', content='hire me', user_id=1, category='interview') self.new_comment = Comments(id=1, comment='test', user_id=1, pitch=self.new_pitch)
def setUp(self): self.user_Logan = User(username='******', password='******', email='*****@*****.**') self.new_pitch = Pitch(title='test', body='testing pitch creation', user_id=1, category='promotion') self.new_comment = Comments(id=1, comment='Comment test', user_id=1, pitch=self.new_pitch)
def comment_user(): data = request.form user_id = data['id'] comment = data['comment'] comment_user = Comments.query.get(user_id) if (comment_user): comment_user.comment = unicode(comment) else: comment_user = Comments(id=user_id, comment=unicode(comment)) db.session.add(comment_user) db.session.commit() return gen_success()
def comment_question(question_id): if not (session and session.has_key('userid')): return "unauthorized" else: comment_value = request.data comment_value = comment_value.split("=")[1] print(comment_value) new_comment = Comments(comment_value, session['userid'], question_id, None) db.session.add(new_comment) db.session.commit() return "true"
def post(id): article = Articles.query.get_or_404(id) posts = Articles.query.order_by(Articles.date_posted.desc()).all() comments = article.userscomments form = CommentsForm() if form.validate_on_submit(): comment = Comments(comment=form.comments.data,user_id=current_user.id,article_id=article.id) db.session.add(comment) db.session.commit() flash('Your have successfully added your comment!', 'success') return redirect(url_for('post',id = id)) return render_template('post.html', title=article.title, article = article,form=form,posts=posts,comments=comments)
def your_comment(pitch_id): form2 = CommentForm() comments = Comments.query.filter_by(pitch_id=pitch_id).all() if form2.validate_on_submit(): pitch_id = pitch_id user_id = current_user._get_current_object().id comments = Comments(comments=form2.comments.data, user_id=user_id, pitch_id=pitch_id) comments.save_comment() return redirect(url_for('main.index')) return render_template('comment.html', form2=form2, comments=comments)
def technology(): technology = Blog.query.filter_by(category='Technology').all() form = CommentForm() if form.validate_on_submit(): details = form.details.data user = current_user new_comment = Comments(details=details, blog_id=id, user=user) # # save comment db.session.add(new_comment) db.session.commit() return render_template('technology.html', technology=technology, form=form)
def business(): business = Blog.query.filter_by(category='business').all() form = CommentForm() if form.validate_on_submit(): details = form.details.data user = current_user new_comment = Comments(details=details, blog_id=id, user=user) # # save comment db.session.add(new_comment) db.session.commit() return render_template('business.html', business=business, form=form)