def post(): form = PostForm() if form.validate_on_submit(): post = BlogPost(description=form.body.data, author_id=current_user._get_current_object()) db.session.add(post) return redirect(url_for('welcome')) posts = BlogPost.query.order_by(BlogPost.title).all() return render_template('index.html', form=form, posts=posts)
def post(): form = PostForm() if form.validate_on_submit(): post = Post( description=form.description.data, location=form.location.data) db.session.add(post) db.session.commit() flash('The party has been posted!') return render_template('post.html ', form=form)
def new_post(): form = PostForm() if form.validate_on_submit(): print("yes") blogpost = Blogpost() blogpost.title = form.title.data print(form.title.data) blogpost.content = form.text.data db.session.add(blogpost) db.session.commit() flash('success') return redirect(url_for('index')) return render_template('new.html',form=form)
def admin(): form = PostForm(csrf_enabled=False) if form.validate_on_submit(): title = form.title.data summary = form.summary.data content = form.content.data article = Article(title=title, summary=summary, content=content) db.session.add(article) db.session.commit() article_id = Article.query.filter_by(title=title).first().id return redirect(url_for('index', id=article_id)) return render_template('admin.html', form=form)
def user(): postForm = PostForm() postError = None userlog = current_user if postForm.validate_on_submit(): post = Post(postForm.body.data, datetime.utcnow(), userlog.id) db.session.add(post) db.session.commit() flash("Posted") else: postError = "Write something!" return render_template( "user.html", userlog=userlog, postForm=postForm, error=postError, showPost=posted(), updateForm=UpdateForm() )
def home(): if request.method == 'POST': form = PostForm(request.form) user_input = PostModel(form.data) if form.validate_on_submit(): user_input.save_text() user_input.get_qr() if form.data['download_file']: return redirect('/get_file') else: return redirect('/qr') else: form = PostForm() return render_template('index.html', form=form)
def home(): error = None form = PostForm(request.form) if form.validate_on_submit(): post = BlogPost( form.title.data, form.description.data, current_user.id) db.session.add(post) db.session.commit() # render a template flash('New entry was successfully posted. Thanks.') return redirect(url_for('home.home')) else: posts = db.session.query(BlogPost).all() return render_template('index.html', posts=posts, form = form, error = error)
def home(): error = None form = PostForm(request.form) if form.validate_on_submit(): post = BlogPost(form.title.data, form.description.data, current_user.id) db.session.add(post) db.session.commit() # render a template flash('New entry was successfully posted. Thanks.') return redirect(url_for('home.home')) else: posts = db.session.query(BlogPost).all() return render_template('index.html', posts=posts, form=form, error=error)
def admin_nouveau(): form = PostForm() if form.validate_on_submit(): titre = form.title.data identifiant = form.identifiant.data auteur = form.auteur.data date_parution = form.date.data paragraphe = form.content.data params = (titre, identifiant, auteur, date_parution, paragraphe) cursor.execute( "INSERT INTO article(titre, identifiant, auteur, " "date_publication, paragraphe) VALUES( ?, ?, ?, ?, ?)", params) flash('Post cree avec succes!', 'success') return redirect(url_for('admin')) return render_template('creation_post.html', title='Nouveau poste', form=form)
def post(): form = PostForm() if form.validate_on_submit(): title = form.title.data post = form.post.data location = form.location.data db.execute( "INSERT INTO post('post','title','location','id') values(:post, :title, :location, :id)", post=post, title=title, location=location, id=session.get("id")) form.title.data = '' form.post.data = '' form.location.data = '' return render_template('post.html', form=form) else: return render_template('post.html', form=form)
def new_post(): form = PostForm() topic = Topic.query.filter(Topic.tid == form.topic.data).first() if form.validate_on_submit(): post = Post(title=form.title.data, content=form.content.data, post_time=datetime.utcnow(), uid=current_user.uid, tid=form.topic.data) current_user.posts.append(post) topic.posts.append(post) db.session.add(post) db.session.commit() flash('Your post has been created!', 'success') posts = Post.query.filter(Post.pid == post.pid).order_by( Post.pid.desc()) return redirect("/viewpost?post=" + str(post.pid)) return render_template('create_post.html', title='New Post', form=form)
def edit(id=0): form = PostForm() # 表单实例化 if id == 0: post = Post(author=current_user) # 模型实例化 else: post = Post.query.get_or_404(id) if form.validate_on_submit(): post.body = form.body.data post.title = form.title.data db.session.add(post) db.session.commit() # 保存到库中 return redirect(url_for('.post', id=post.id)) title = _(u'添加新文章') if id > 0: title = _(u'编辑 - %(title)', title=post.title) # 如果是post,则是编辑 return render_template('posts/edit.html', title=title, form=form, post=post)
def adminer(): postform = PostForm() if postform.validate_on_submit(): post = Post(title=postform.title.data, body=postform.body.data) db.session.add(post) db.session.commit() return redirect(url_for('.adminer')) labelform = LabelForm() if labelform.validate_on_submit(): label = Label(name=labelform.name.data) print label db.session.add(label) db.session.commit() return redirect(url_for('.adminer')) posts = Post.query.all() page = request.args.get('page',1,type=int) pagination = Post.query.order_by(Post.timestamp.desc()).paginate( page,per_page=current_app.config['FLASKY_POSTS_PER_PAGE'], error_out=False) posts = pagination.items return render_template('admin/admin.html',postform=postform,labelform=labelform,posts=posts)