Пример #1
0
def blog():
    link_name = request.args.get('post')
    if link_name != None:
        post = queries.get_post(link_name)
        return render_template('post.html', post=post)
    else:
        posts = queries.get_blog_posts()
        return render_template('blog_posts.html', posts=posts)
Пример #2
0
def view_post():
    blogID = request.args.get('blog')
	
    if(blogID is None):
        return blog()
    else:
        cur = qry.get_post(blogID)
        if not cur:
            return abort(404)
        return render_template('post.html', post=cur)
Пример #3
0
def blog():
    link_name = request.args.get('post')
    # assume page = 1 if undefined
    try:
        page = int(request.args.get('page'))
    except TypeError as e:
        page = 1

    if link_name != None:
        post = queries.get_post(link_name)
        return render_template('post.html', post=post)
    else:
        posts = queries.get_blog_posts(page)
        return render_template('blog_posts.html', posts=posts)
Пример #4
0
def edit_post():
    if request.method == 'POST':
        file = request.files['file']
        title = request.form['title']
        author = request.form['author']
        content = request.form['content']
        post_id = request.form['post_id']

        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            img_id = queries.get_current_img_id(post_id)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], str(img_id)))

        date_published = datetime.today().strftime('%Y-%m-%d')
        link_name = queries.update_blog_post(post_id, title, author, content)
        return redirect('/blog?post=' + link_name)
    else:
        link_name = request.args.get('post')
        post = queries.get_post(link_name)
        return render_template('edit_post.html', post=post)
Пример #5
0
def view_post(slug):
    cur = qry.get_post(slug)
    if not cur:
        return abort(404)
    return render_template('post.html', post=cur)