Ejemplo n.º 1
0
def more_posts(page_num):
    """
    :param page_num: The number of pages/posts
    :return: AJAX more posts
    """
    offset = int(page_num * ELEMENTS_PER_PAGE)
    return render_template('blog/admin-posts-more.html',
                           posts=BlogPost.query().order(-BlogPost.date).fetch(
                               ELEMENTS_PER_PAGE, offset=offset))
Ejemplo n.º 2
0
def home(page):
    offset = (page - 1) * POSTS_PER_PAGE
    q = BlogPost.query().order(-BlogPost.date)
    posts = q.fetch(POSTS_PER_PAGE, offset=offset)
    all_posts = len(q.fetch())
    pagination = Pagination(page, POSTS_PER_PAGE, all_posts)
    response = make_response(render_template('front-index.html',
                                             posts=posts,
                                             pagination=pagination))
    return response
Ejemplo n.º 3
0
def posts():
    ''' Renders all posts'''
    if request.method == 'POST':

        # Get the Key, and delete() the object using Key (mandatory)
        ndb.Key('BlogPost', int(request.form['post_id'])).delete()
        time.sleep(1)

    return render_template('posts-view.html',
                           posts=BlogPost.query().order(-BlogPost.date))
Ejemplo n.º 4
0
def home(page):
    offset = (page - 1) * POSTS_PER_PAGE
    q = BlogPost.query().order(-BlogPost.date)
    posts = q.fetch(POSTS_PER_PAGE, offset=offset)
    all_posts = len(q.fetch())
    pagination = Pagination(page, POSTS_PER_PAGE, all_posts)
    response = make_response(
        render_template('front-index.html', posts=posts,
                        pagination=pagination))
    return response
Ejemplo n.º 5
0
def more_posts(page_num):
    """
    :param page_num: The number of pages/posts
    :return: AJAX more posts
    """
    offset = int(page_num * ELEMENTS_PER_PAGE)
    return render_template('blog/admin-posts-more.html',
                           posts=BlogPost.query()
                           .order(-BlogPost.date)
                           .fetch(ELEMENTS_PER_PAGE, offset=offset))
Ejemplo n.º 6
0
def posts(page_num):
    """
    GET --> Main post list
    POST --> Delete post
    """
    if request.method == 'POST':
        post = request.get_json()
        # Get the Key, and delete() the object using Key (mandatory)
        ndb.Key('BlogPost', int(post['objects'][0])).delete()
        logging.info("Deleted post: {}".format(post['objects'][0]))
        return "true"
    all_posts = BlogPost.query().order(-BlogPost.date).fetch(
        ELEMENTS_PER_PAGE * page_num)
    plus = False if len(all_posts) < (ELEMENTS_PER_PAGE * page_num) else True
    return render_template('blog/admin-posts.html', posts=all_posts, plus=plus)
Ejemplo n.º 7
0
def posts(page_num):
    """
    GET --> Main post list
    POST --> Delete post
    """
    if request.method == 'POST':
        post = request.get_json()
        # Get the Key, and delete() the object using Key (mandatory)
        ndb.Key('BlogPost', int(post['objects'][0])).delete()
        logging.info("Deleted post: {}".format(post['objects'][0]))
        return "true"
    all_posts = BlogPost.query().order(-BlogPost.date).fetch(ELEMENTS_PER_PAGE*page_num)
    plus = False if len(all_posts) < (ELEMENTS_PER_PAGE*page_num) else True
    return render_template('blog/admin-posts.html',
                           posts=all_posts, plus=plus)
Ejemplo n.º 8
0
def sitemap():
    """Generate sitemap.xml. Makes a list of urls and date modified."""
    pages = [['/', LAST_UPDATE]]

    # static pages
    for rule in main.app.url_map.iter_rules():
        if "GET" in rule.methods and len(rule.arguments) == 0 and not re.match(
                '(?:admin|static)', rule.endpoint):
            pages.append([rule.rule, LAST_UPDATE])

    # post model pages
    all_posts = BlogPost.query().order(-BlogPost.date).fetch()
    for single_post in all_posts:
        url = url_for('front.post', post_url=single_post.url)
        modified_time = single_post.date
        pages.append([url, modified_time])

    sitemap_xml = render_template('sitemap_template.xml', pages=pages)
    response = make_response(sitemap_xml)
    response.headers["Content-Type"] = "application/xml"

    return response
Ejemplo n.º 9
0
def sitemap():
    """Generate sitemap.xml. Makes a list of urls and date modified."""
    pages = [['/', LAST_UPDATE]]

    # static pages
    for rule in main.app.url_map.iter_rules():
        if "GET" in rule.methods and len(rule.arguments) == 0 and not re.match('(?:admin|static)', rule.endpoint):
            pages.append(
                [rule.rule, LAST_UPDATE]
            )

    # post model pages
    all_posts = BlogPost.query().order(-BlogPost.date).fetch()
    for single_post in all_posts:
        url = url_for('front.post', post_url=single_post.url)
        modified_time = single_post.date
        pages.append([url, modified_time])

    sitemap_xml = render_template('sitemap_template.xml', pages=pages)
    response = make_response(sitemap_xml)
    response.headers["Content-Type"] = "application/xml"

    return response
Ejemplo n.º 10
0
def post(post_url):
    single_post = BlogPost.query(BlogPost.url == post_url).get()
    return render_template('front-post.html',
                           post=single_post)
Ejemplo n.º 11
0
def post(post_url):
    single_post = BlogPost.query(BlogPost.url == post_url).get()
    return render_template('front-post.html', post=single_post)