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)
def generate_resource(cls, post, resource): from blog.models import BlogPost if not post: post = BlogPost.get_by_id(resource) else: assert resource == post.key().id() template_vals = { 'post': post, 'config': config, } template_name = "blog/themes/%s/post.html" % config.theme rendered = utils.render_template(template_name, template_vals) StaticContent.set(post.path, rendered, config.html_mime_type)
def get_content(request, path=''): """Get content from datastore as requested on the url path Args: path - comes without leading slash. / added in code """ content = StaticContent.get_by_key_name("/%s" % path) if not content: if path == '': # Nothing generated yet. Inform user to create some content return render_to_response("blog/themes/%s/listing.html" % config.theme, {'config': config, 'no_post': True,}) else: raise NotFound serve = True # check modifications and etag if 'If-Modified-Since' in request.headers: last_seen = datetime.datetime.strptime( request.headers['If-Modified-Since'], HTTP_DATE_FMT) if last_seen >= content.last_modified.replace(microsecond=0): serve = False if 'If-None-Match' in request.headers: etags = [x.strip('" ') for x in request.headers['If-None-Match'].split(',')] if content.etag in etags: serve = False response = _output(content, serve) return response
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 site_verification(previous_version): StaticContent.set('/' + config.google_site_verification, utils.render_template('blog/site_verification.html', {'config':config}), config.html_mime_type, False)
def generate(previous_version): for path, template, indexed in pages: rendered = utils.render_template(template, {'config':config}) StaticContent.set(path, rendered, config.html_mime_type, indexed)