Example #1
0
def blog_index(page=1):
    """ Index Page. Here is where the magic starts """
    #page = request.args.get("page", 0, type=int)
    if page <= 0:
        abort(404)
    else:
        page -= 1 #To the outside, blog index is 1-indexed

    # Sorry for the verbose names, but this seemed like a sensible
    # thing to do.
    posts_per_page = current_app.config["POSTS_PER_PAGE"]
    posts, there_is_more = get_posts(posts_per_page, page)
    social_links = current_app.config["SOCIAL_LINKS"]
    return render_template("blog.html", 
                           posts=posts, 
                           now=datetime.datetime.now(),
                           is_more=there_is_more, 
                           current_page=page+1,
                           social_links=social_links)
Example #2
0
def view_post_slug(slug):
    try:
        post = db.session.query(Post).filter_by(slug=slug, draft=False).one()
    except Exception:
        #TODO: Better exception
        return abort(404)

    if not any(botname in request.user_agent.string for botname in 
                ['Googlebot',  'Slurp',         'Twiceler',     'msnbot',
                 'KaloogaBot', 'YodaoBot',      '"Baiduspider',
                 'googlebot',  'Speedy Spider', 'DotBot']):
        db.session.query(Post)\
            .filter_by(slug=slug)\
            .update({Post.views:Post.views+1})
        db.session.commit()

    posts,_ = get_posts(current_app.config["POSTS_PER_PAGE"])
    social_links = current_app.config["SOCIAL_LINKS"]
    return render_template("single-post.html", 
            post=post, 
            posts=posts, 
            social_links=social_links)