def new_post(): """ Dashboard: Create a New Article. Same as Edit Article. """ form = PostForm() if form.validate_on_submit(): post = Post( markdown_url=form.markdown_url.data, author=current_user, title=form.title.data, url=form.url.data, img_url=form.img_url.data, summary=form.summary.data, ) # split the tags by the comas post_tags = form.tags.data.replace(" ", "").split(",") # check if the tag exists to append it to the post. Else, create it Tag.add_or_create_tags(post_tags, post) # add tag and post db.session.add(post) # commit to the db db.session.commit() flash('"{}" is now live!'.format(form.title.data)) return redirect(url_for("dashboard.overview")) return render_template("dashboard/new_post.html", title="New Post", form=form, post_active="is-active")
def new_post(): form = PostForm() if form.validate_on_submit(): post = Post(markdown_url=form.markdown_url.data, author=current_user, title=form.title.data, url=form.url.data, img_url=form.img_url.data, summary=form.summary.data) # split the tags by the comas post_tags = form.tags.data.replace(' ', '').split(',') # check if the tag exists to append it to the post. Else, create it Tag.add_or_create_tags(post_tags, post) # add tag and post db.session.add(post) # commit to the db db.session.commit() flash('"{}" is now live!'.format(form.title.data)) return redirect(url_for('dashboard.overview')) return render_template('dashboard/new_post.html', title='New Post', form=form, post_active='is-active')