Esempio n. 1
0
def blog_edit(blog_id):
    """Takes a blog id and edits that blog"""

    blog = UserBlog()
    child_blog = blog.get_blog(blog_id)

    if not child_blog:
        abort(404)

    form = BlogForm(
        obj=child_blog
    )  # populate the blog form with details from the child blog object

    if form.validate_on_submit():

        blog_data = _get_updated_data(form, child_blog)

        if blog_data:
            child_blog.update_blog(data=blog_data)
            Message.display_to_gui_screen(
                "You have successfully updated your blog.")
            return redirect(
                url_for("blogs_app.my_blog", blog_id=child_blog.child_blog_id))

    return render_template("blogs/blog.html",
                           form=form,
                           child_blog=child_blog,
                           edit_blog=True)
Esempio n. 2
0
def delete_all_blogs():
    """Deletes all blogs created by the user"""

    blog = UserBlog()
    blog.delete_all_blogs()
    Message.display_to_gui_screen(
        "All child blogs relating to this blog have been deleted.")
    return redirect(url_for('blogs_app.blog'))
Esempio n. 3
0
def blog_delete(blog_id):
    """Deletes a blog using its blog_id"""

    blog = UserBlog()
    child_blog = blog.get_blog(blog_id)
    child_blog.delete_blog()
    Message.display_to_gui_screen("One of your blogs was deleted successfully")
    return redirect(url_for("blogs_app.blog"))
Esempio n. 4
0
def blog_create():
    """Allows the user to create a brand new blog."""

    form = BlogForm()

    if form.validate_on_submit():

        blog = UserBlog()
        blog.create_blog(form)
        Message.display_to_gui_screen("A new blog was successfully created.")
        return redirect(url_for("blogs_app.blog"))

    return render_template('blogs/blog.html', form=form, edit_blog=False)
Esempio n. 5
0
def delete_comment(blog_id, post_id, comment_id):
    """"""
    post, blog = None, UserBlog()
    child_blog = blog.get_blog(blog_id)

    if child_blog:
        post = child_blog.Post.get_post_by_id(post_id)
    if post:
        post.Comment.delete_comment(comment_id)

    return redirect(
        url_for("posts_app.post_permalink",
                blog_id=blog_id,
                post_id=post_id,
                comment_id=comment_id))
Esempio n. 6
0
def _get_blog(blog_id):
    """"""
    blog = UserBlog()
    return blog.get_blog(blog_id)
Esempio n. 7
0
def blog():
    """Displays all the blogs created by the user"""
    blog = UserBlog()
    return render_template('blogs/blogs.html', blogs=blog.get_all_blogs())