Ejemplo n.º 1
0
def add_post():
    """
    Create a new post
    """
    if request.method == 'POST':

        # Create New Blog Post Object
        blog_post = BlogPost(title=request.form['title'],
                             text=request.form['text'],
                             author=users.get_current_user(),
                             url=clean_url(request.form['title']))

        # Create New Blog Post Categories
        post_categories = request.form['categories'].split(",")
        blog_post.categories = BlogCategory.add_categories(post_categories)

        # Save the new post
        blog_post.put()

        # Redirect
        sleep(1)
        return redirect(url_for('admin.posts'))
    # GET
    return render_template('blog/admin-posts-add.html',
                           categories=BlogCategory.query_all())
Ejemplo n.º 2
0
def edit_category(cat_id):
    ''' Renders all categories'''
    # Get the object to edit
    edit_cat = ndb.Key(BlogCategory, int(cat_id))

    if request.method == 'POST':
        if request.form["action"] == "save":
            category = edit_cat.get()
            category.name = request.form['name']
            category.put()
            time.sleep(1)
            return redirect(url_for('admin.categories'))

        elif request.form["action"] == "delete":
            BlogCategory.update_posts_categories(edit_cat.get())
            edit_cat.delete()
            time.sleep(1)
            return redirect(url_for('admin.categories'))

        else:
            pass

    return render_template('categories-edit.html',
                           categories=BlogCategory.query(),
                           edit_cat=edit_cat.get())
Ejemplo n.º 3
0
def add_post():
    """
    Create a new post
    """
    if request.method == 'POST':

        # Create New Blog Post Object
        blog_post = BlogPost(title=request.form['title'],
                             text=request.form['text'],
                             author=users.get_current_user(),
                             url=clean_url(request.form['title']))

        # Create New Blog Post Categories
        post_categories = request.form['categories'].split(",")
        blog_post.categories = BlogCategory.add_categories(post_categories)

        # Save the new post
        blog_post.put()

        # Redirect
        sleep(1)
        return redirect(url_for('admin.posts'))
    # GET
    return render_template('blog/admin-posts-add.html',
                           categories=BlogCategory.query_all())
Ejemplo n.º 4
0
def categories():
    ''' Renders all categories'''
    if request.method == 'POST':
        post_categories = request.form['categories'].split(",")
        BlogCategory.add_categories(post_categories)
        time.sleep(1)

    return render_template('categories-view.html',
                           categories=BlogCategory.query())
Ejemplo n.º 5
0
def categories():
    """ Renders all categories """
    if request.method == 'POST':
        post_categories = request.form['categories'].split(",")
        BlogCategory.add_categories(post_categories)
        sleep(1)

    return render_template('blog/categories/admin-categories.html',
                           categories=BlogCategory.query().fetch())
Ejemplo n.º 6
0
def categories():
    """ Renders all categories """
    if request.method == 'POST':
        post_categories = request.form['categories'].split(",")
        BlogCategory.add_categories(post_categories)
        sleep(1)

    return render_template('blog/categories/admin-categories.html',
                           categories=BlogCategory.query().fetch())
Ejemplo n.º 7
0
def edit_post(post_id):
    '''Edit posts'''
    if request.method == 'POST':

        # Retrieve the object
        blog_post = ndb.Key('BlogPost', int(post_id)).get()

        # Update the values
        blog_post.title = request.form['title']
        blog_post.text = request.form['text']
        post_categories = request.form['categories'].split(",")
        blog_post.categories = BlogCategory.add_categories(post_categories)

        # Save the new post
        blog_post.put()

        # Redirect
        time.sleep(1)
        return redirect(url_for('admin.posts'))

    return render_template('posts-edit.html',
                           post=ndb.Key('BlogPost', int(post_id)).get(),
                           categories=BlogCategory.query_all())
Ejemplo n.º 8
0
def edit_post(post_id):
    """Edit posts"""
    if request.method == 'POST':

        # Retrieve the object
        blog_post = ndb.Key('BlogPost', int(post_id)).get()

        # Update the values
        blog_post.title = request.form['title']
        blog_post.text = request.form['text']
        post_categories = request.form['categories'].split(",")
        blog_post.categories = BlogCategory.add_categories(post_categories)

        # Save the new post
        blog_post.put()
        logging.info("Edit post : {}".format(post_id))
        # Redirect
        sleep(1)

        return redirect(url_for('admin.posts'))
    return render_template('blog/admin-posts-edit.html',
                           post=ndb.Key(BlogPost, int(post_id)).get(),
                           categories=BlogCategory.query_all())
Ejemplo n.º 9
0
def edit_category(cat_id):
    """ Edit a category"""
    edit_cat = ndb.Key(BlogCategory, int(cat_id))

    if request.method == 'POST':
        if request.form["action"] == "save":
            category = edit_cat.get()
            category.name = request.form['name']
            category.put()
            sleep(1)
            return redirect(url_for('admin.categories'))

        elif request.form["action"] == "delete":
            BlogCategory.update_posts_categories(edit_cat.get())
            edit_cat.delete()
            sleep(1)
            return redirect(url_for('admin.categories'))

        else:
            pass

    return render_template('blog/categories/admin-categories-edit.html',
                           categories=BlogCategory.query().fetch(),
                           edit_cat=edit_cat.get())
Ejemplo n.º 10
0
def edit_category(cat_id):
    """ Edit a category"""
    edit_cat = ndb.Key(BlogCategory, int(cat_id))

    if request.method == 'POST':
        if request.form["action"] == "save":
            category = edit_cat.get()
            category.name = request.form['name']
            category.put()
            sleep(1)
            return redirect(url_for('admin.categories'))

        elif request.form["action"] == "delete":
            BlogCategory.update_posts_categories(edit_cat.get())
            edit_cat.delete()
            sleep(1)
            return redirect(url_for('admin.categories'))

        else:
            pass

    return render_template('blog/categories/admin-categories-edit.html',
                           categories=BlogCategory.query().fetch(),
                           edit_cat=edit_cat.get())