def edit_post(post_id): """allows user to edit an existing post""" the_post = Post.query.get(post_id) if request.method == 'GET': form = PostForm( formdata=MultiDict({ 'title': the_post.title, 'date_written': the_post.date_written, 'body': the_post.body, 'author_display_name': the_post.author.display_name, 'language': the_post.language.name, 'nasod': the_post.country.name })) else: form = PostForm() if form.validate_on_submit(): the_author = Author.get_by_display_name(form.author_display_name.data) the_post.author_id = the_author.id the_post.title = form.title.data the_post.date_written = form.date_written.data the_post.body = form.body.data the_post.language_id = Language.query.filter( Language.name == form.language.data).first().id the_post.country_id = Country.query.filter( Country.name == form.nasod.data).first().id the_post.modified_by = current_user.id the_post.modify_timestamp = datetime.utcnow() db.session.commit() return redirect(url_for('post', post_id=post_id)) return render_template('post.html', form=form, post=the_post, author=the_post.author, poster=the_post.poster)
def new_post(): """allows user to create a new post""" form = PostForm() the_post = Post() if form.validate_on_submit(): the_author = Author.get_by_display_name(form.author_display_name.data) the_post.author_id = the_author.id the_post.title = form.title.data the_post.date_written = form.date_written.data the_post.body = form.body.data the_post.language_id = Language.query.filter( Language.name == form.language.data).first().id the_post.country_id = Country.query.filter( Country.name == form.nasod.data).first().id the_post.created_by = current_user.id the_post.modified_by = current_user.id db.session.add(the_post) db.session.commit() return redirect(url_for('post', post_id=the_post.id)) elif request.method == 'GET': the_post.title = form.title.data the_post.date_written = form.date_written.data the_post.body = form.body.data the_post.language = form.language.data return render_template('post.html', form=form, post=the_post, poster=current_user)
def new_post(): """新建文章视图""" form = PostForm(request.form) if form.validate_on_submit(): form.content.data = request.form['markdownEditor-html-code'] form.categories.data = [Category.query.get(category_id) for category_id in form.categories.data] if not form.description.data: form.description.data = remove_html_tag(form.content.data)[0:150] if form.publish.data: with db.auto_commit(): post = Post() post.set_attr(form.data) db.session.add(post) flash('文章已发布', 'success') if form.save.data: with db.auto_commit(): post = Post() post.set_attr(form.data) post.published = False db.session.add(post) flash('文章已保存为草稿', 'success') return redirect(url_for('web.manage_post')) return render_template('admin/post_editor.html', form=form)
def post_new(): form = PostForm() if request.method == "POST" and form.validate(): post = Post(title=form.title.data, content=form.content.data, author=current_user) db.session.add(post) db.session.commit() flash("Your post has been created!", "success") return redirect(url_for('post', id=post.id)) return render_template("post_new.html", title="Create New Post", form=form)
def new_post(): form = PostForm() if form.validate_on_submit(): title = form.title.data body = form.body.data category = Category.query.get(form.category.data) post = Post(title=title, body=body, category=category) db.session.add(post) db.session.commit() flash('发表成功.', 'success') return redirect(url_for('web.show_post', post_id=post.id)) return render_template('admin/new_post.html', form=form)
def notas(nombre): form = PostForm() if form.validate_on_submit(): post = Post(nota=form.post.data) db.session.add(post) db.session.commit() flash('Se coloc la nota !') return redirect(url_for('notas', nombre=current_user.nombre)) user = Alumno.query.filter_by(nombre=nombre).first_or_404() return render_template('views/profile.html', title=f'Perfil {nombre}', user=user, form=form)
def edit_post(post_id): form = PostForm() post = Post.query.get_or_404(post_id) if form.validate_on_submit(): post.title = form.title.data post.body = form.body.data post.category = Category.query.get(form.category.data) db.session.commit() flash('Post updated.', 'success') return redirect(url_for('web.show_post', post_id=post.id)) form.title.data = post.title form.body.data = post.body form.category.data = post.category_id return render_template('admin/edit_post.html', form=form)
def edit_post(id): post = Post.objects.get(pk=id) form = PostForm(obj=post) if form.validate_on_submit(): post.title = form.title.data post.body = form.body.data post.save() flash('Post updated', 'success') return redirect(url_for('admin.posts')) return render_template('admin/form.html', form=form, endpoint=url_for('.edit_post', id=post.id))
def new_post(): form = PostForm() if form.validate_on_submit(): post = Post(author=current_user.id, title=form.title.data, body=form.body.data) post.save() flash('Post created', 'success') return redirect(url_for('admin.posts')) return render_template('admin/form.html', form=form, endpoint=url_for('.new_post'))
def edit_post(id: int): post = Post.query.get_or_404(id) if post.author != current_user: abort(403) form = PostForm() if request.method == "POST" and form.validate(): post.title = form.title.data post.content = form.content.data db.session.commit() flash("Your post has been updated!", "info") return redirect(url_for('post', id=post.id)) else: form.title.data = post.title form.content.data = post.content return render_template("edit_post.html", title="Update Post", form=form)
def profile(nombre): form = PostForm() if form.validate_on_submit(): post = Post(alumno=form.alumno.data, asistencia=form.asistencia.data, tipo_examen=form.tipoexamen.data, nota=form.post.data, author=current_user) db.session.add(post) db.session.commit() flash('Se coloc la nota !') return redirect(url_for('profile', nombre=current_user.nombre)) user = Profesor.query.filter_by(nombre=nombre).first_or_404() return render_template('views/profile.html', title=f'Perfil {nombre}', user=user, form=form)
def edit_post(post_id): """ 编辑文章视图 :param post_id: 文章 id """ post = Post.query.get_or_404(post_id) form = PostForm(request.form) if form.validate_on_submit(): form.content.data = request.form['markdownEditor-html-code'] form.categories.data = [ Category.query.get(category_id) for category_id in form.categories.data ] if not form.description.data: form.description.data = remove_html_tag(form.content.data)[0:150] if form.publish.data: with db.auto_commit(): post.set_attr(form.data) post.published = True db.session.add(post) flash('文章已更新', 'success') if form.save.data: with db.auto_commit(): post.set_attr(form.data) post.published = False db.session.add(post) flash('文章已保存为草稿', 'success') return redirect(url_for('web.manage_post')) if not form.errors: form.title.data = post.title form.categories.data = [category.id for category in post.categories] form.content_markdown.data = post.content_markdown form.description.data = post.description form.can_comment.data = post.can_comment return render_template('admin/post_editor.html', form=form, post=post)