def generate_resource(cls, post, resource, pagenum=1, start_ts=None):
        from blog.models import BlogPost
        q = BlogPost.all().order('-published')
        q.filter('published <', start_ts or datetime.datetime.max)
        cls._filter_query(resource, q)

        posts = q.fetch(config.posts_per_page + 1)
        more_posts = len(posts) > config.posts_per_page

        path_args = {
            'resource': resource,
        }
        path_args['pagenum'] = pagenum - 1
        prev_page = cls.path % path_args
        path_args['pagenum'] = pagenum + 1
        next_page = cls.path % path_args
        template_vals = {
            'posts': posts[:config.posts_per_page],
            'prev_page': prev_page if pagenum > 1 else None,
            'next_page': next_page if more_posts else None,
            'config': config,
        }
        template_name = "blog/themes/%s/listing.html" % config.theme
        rendered = utils.render_template(template_name, template_vals)
        
        path_args['pagenum'] = pagenum
        StaticContent.set(cls.path % path_args, rendered, config.html_mime_type)

        if pagenum == 1:
            StaticContent.set(cls.first_page_path % path_args, rendered, config.html_mime_type)
        if more_posts:
            deferred.defer(cls.generate_resource, None, resource, pagenum + 1,
                           posts[-2].published)
Example #2
0
def index(request):
    """Displays the index page."""
    # Fetch all of the BlogPosts
    posts = BlogPost.all().order('-date')

    # Setup the data to pass on to the template
    template_values = {
        'posts': posts,
    }

    # Load and render the template
    return shortcuts.render_to_response('index.html', template_values)
Example #3
0
def index(request):
    """Displays the index page."""
    # Fetch all of the BlogPosts
    posts = BlogPost.all().order('-date')

    # Setup the data to pass on to the template
    template_values = {
        'posts': posts,
    }

    # Load and render the template
    return shortcuts.render_to_response('index.html', template_values)
Example #4
0
def view(request, post_uri):
    # Find the requested post
    post = BlogPost.all().filter('uri = ', post_uri).fetch(1)

    # Make sure the requested post exists
    if post == None or len(post) == 0:
        return http.HttpResponseNotFound('No post exists with that uri (%r)' % post_uri)

    # Get the requested post data
    post = post[0]

    # Load and display the view template
    return shortcuts.render_to_response('view.html', {'post': post})
def regenerate(batch_size=50, seen=None, start_ts=None):
    """Regenerate all static content"""
    if not seen:
        seen = set()
    q = BlogPost.all().order('-published')
    q.filter('published <', start_ts or datetime.datetime.max)
    posts = q.fetch(batch_size)
    for post in posts:
        for generator_class, deps in post.get_deps(True):
            for dep in deps:
                if (generator_class.__name__, dep) not in seen:
                    logging.warn((generator_class.__name__, dep))
                    seen.add((generator_class.__name__, dep))
                    deferred.defer(generator_class.generate_resource, None, dep)
    if len(posts) == batch_size:
        deferred.defer(regenerate, batch_size, seen, posts[-1].published)
 def generate_resource(cls, post, resource):
     from blog.models import BlogPost
     q = BlogPost.all().order('-updated')
     posts = list(itertools.islice((x for x in q if x.path), 10))
     for post in posts:
         updated = post.updated
         break
     template_vals = {
         'posts': posts,
         'config': config,
         'updated': updated,
     }
     rendered = utils.render_template("blog/atom.xml", template_vals)
     StaticContent.set('/feeds/atom.xml', rendered,
                       'application/atom+xml; charset=utf-8')
     if config.hubbub_hub_url:
         cls.send_hubbub_ping(config.hubbub_hub_url)
def index(request, start=0, count=10):
    offset = start
    more_posts = False 
    posts = BlogPost.all().order('-published').fetch(count+1, offset)
    if len(posts) > count:
        posts = posts[0:count]
        more_posts = True
    template_vals = {
            'offset': offset,
            'count': count,
            'last_post': offset + len(posts) - 1,
            'prev_offset': max(0, offset - count),
            'next_offset': offset + count,
            'posts': posts,
            'more_posts': more_posts,
            'config': config,
            'menu_view': True,
            }
    return render_to_response("blog/admin/index.html", template_vals)
Example #8
0
 def get_context_data(self, **kwargs):
     context = super(BlogIndex, self).get_context_data(**kwargs)
     # Latest 10 posts.
     context['posts'] = BlogPost.all().order('-date').fetch(10)
     return context