Example #1
0
def sidebar():
    """ Fetch a dict of information that should be used for each view
        e.g. recent posts, posts by view used in base_blog.html
    """
    recent_posts = Post.query_all().limit(5)
    grouped_by_month = Post.group_by_year_month()
    return recent_posts, grouped_by_month
Example #2
0
def sidebar():
    """ Fetch a dict of information that should be used for each view
        e.g. recent posts, posts by view used in base_blog.html
    """
    recent_posts = Post.query_all().limit(5)
    grouped_by_month = Post.group_by_year_month()
    return recent_posts, grouped_by_month
Example #3
0
def index(page=1):
    """ Display the main page of the blog with the most recent blog posts
        paginated and displayed
    :param int page: Which paginated page of blog entries to display
    """
    posts = Post.query_all().paginate(page, POSTS_PER_PAGE, False)
    pagination = Pagination(page=page, total=posts.total, per_page=POSTS_PER_PAGE,
                            record_name='posts', bs_version=3)
    recent, group_month = sidebar()
    return render_template('kevcrablog/index.html', posts=posts, pagination=pagination,
                           recent_posts=recent, grouped_by_month=group_month, title='Blog')
Example #4
0
def index(page=1):
    """ Display the main page of the blog with the most recent blog posts
        paginated and displayed
    :param int page: Which paginated page of blog entries to display
    """
    posts = Post.query_all().paginate(page, POSTS_PER_PAGE, False)
    pagination = Pagination(page=page,
                            total=posts.total,
                            per_page=POSTS_PER_PAGE,
                            record_name='posts',
                            bs_version=3)
    recent, group_month = sidebar()
    return render_template('kevcrablog/index.html',
                           posts=posts,
                           pagination=pagination,
                           recent_posts=recent,
                           grouped_by_month=group_month,
                           title='Blog')
Example #5
0
 def new_post(self):
     """ Display the 'new post' live text editor form
     """
     # Validate the form and ensure this Post title doesn't already exist
     form = PostForm()
     if form.validate_on_submit() and not Post.query.filter_by(
             title=form.title.data).first():
         new_post = Post(title=form.title.data,
                         body=form.body.data,
                         author_id=1)
         db.session.add(new_post)
         db.session.commit()
         flash('Your post is now live!', 'success')
         return self.render('admin/index.html')
     elif request.method == 'POST':
         flash(
             "There was a problem submitting the form (probably not a unique post title)!",
             'danger')
     return self.render('admin/new_post.html', form=form)
Example #6
0
def index():
    """ Main site index page
    """
    frontpage_posts = Post.query_all().slice(0, 3)
    return render_template('index.html', frontpage_posts=frontpage_posts)
Example #7
0
def index():
    """ Main site index page
    """
    frontpage_posts = Post.query_all().slice(0, 3)
    return render_template('index.html', frontpage_posts=frontpage_posts)