本文整理汇总了Python中blog.models.BlogPost.all方法的典型用法代码示例。如果您正苦于以下问题:Python BlogPost.all方法的具体用法?Python BlogPost.all怎么用?Python BlogPost.all使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.BlogPost
的用法示例。
在下文中一共展示了BlogPost.all方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_resource
# 需要导入模块: from blog.models import BlogPost [as 别名]
# 或者: from blog.models.BlogPost import all [as 别名]
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)
示例2: index
# 需要导入模块: from blog.models import BlogPost [as 别名]
# 或者: from blog.models.BlogPost import all [as 别名]
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)
示例3: view
# 需要导入模块: from blog.models import BlogPost [as 别名]
# 或者: from blog.models.BlogPost import all [as 别名]
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})
示例4: regenerate
# 需要导入模块: from blog.models import BlogPost [as 别名]
# 或者: from blog.models.BlogPost import all [as 别名]
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)
示例5: index
# 需要导入模块: from blog.models import BlogPost [as 别名]
# 或者: from blog.models.BlogPost import all [as 别名]
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)
示例6: get_context_data
# 需要导入模块: from blog.models import BlogPost [as 别名]
# 或者: from blog.models.BlogPost import all [as 别名]
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