示例#1
0
def editpost(slug):
    if validate_if_admin_user(current_user):

        blog_entry = BlogPost.public().filter_by(slug=slug).first_or_404()
        form = CreateBlogPost.edit_values(blog_entry)
        if form.validate_on_submit():

            updated_slug = re.sub('[^\w]+', '-', form.blog_title.data.lower())

            blog_entry.title = form.blog_title.data
            blog_entry.slug = updated_slug
            blog_entry.icon = form.blog_icon.data
            blog_entry.tag = [
                BlogPostTags.query.filter(BlogPostTags.id == int(tag)).first()
                for tag in form.blog_tags.data
            ]
            blog_entry.content = form.blog_content.data

            db.session.commit()
            flash('Blog Post Updated.')
            return redirect(url_for('readpost', slug=updated_slug))

        return render_template('createpost.html', form=form)

    else:
        return redirect(url_for('user', username=current_user.username))
示例#2
0
def readpost(slug):

    query = BlogPost.public().filter_by(slug=slug).first_or_404()
    return render_template('readpost.html', blogpost=query)