本文整理汇总了Python中models.BlogPost.all方法的典型用法代码示例。如果您正苦于以下问题:Python BlogPost.all方法的具体用法?Python BlogPost.all怎么用?Python BlogPost.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.BlogPost
的用法示例。
在下文中一共展示了BlogPost.all方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import all [as 别名]
def __init__(self):
"""load basic members using memcache"""
logging.info("initialized")
self.posts_tags_db=[]
self.catdict={}
self.posts_tags_dict={}
self.posts=memcache.get(KEY)
if self.posts is None:
logging.info('cache is empty creating index')
self.posts = BlogPost.all().order('-timestamp')
createIndex(self.posts)
memcache.add(KEY,self.posts)
if isinstance(self.posts,list):self.nofposts=len(self.posts)-2
else:self.nofposts=self.posts.count()-2
self.tags=memcache.get(TAG)
if self.tags is None:
self.tags = Tag.all()
memcache.add(TAG,self.tags)
self.categories=memcache.get(CATEGORY)
if self.categories is None:
self.categories= Category.all()
memcache.add(CATEGORY,self.categories)
for post in self.posts:
logging.info(['posts',post.title])
self.posts_tags_db.extend(post.tags)
tags=[]
for key in post.tags:tags.append(db.get(key).tag)
self.posts_tags_dict[post.key()]=tags
self.catdict[post.category.key()]=post.category.category
logging.info(['catdict',self.catdict])
self.tagnames=list(chain.from_iterable(self.posts_tags_dict.values()))
示例2: get
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import all [as 别名]
def get(self):
posts = BlogPost.all().order("-date_created")
return {
"admin_section": "admin-blog-posts",
"posts": posts,
}
示例3: get
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import all [as 别名]
def get(self,page):
posts = BlogPost.all().order('-pub_date').fetch(limit=10)
self.templ_vals.update({
'url':users.create_logout_url("/"),
'posts':posts,
})
self.render_to_response('index.html',self.templ_vals)
示例4: refetch
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import all [as 别名]
def refetch(self):
self.posts =BlogPost.all().order('-timestamp')
memcache.add(KEY,self.posts)
self.tags = Tag.all()
memcache.add(TAG,self.tags)
self.categories= Category.all()
memcache.add(CATEGORY,self.categories)
createIndex(self.posts)
示例5: get
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import all [as 别名]
def get(self, category = None):
cur_category = None
categories = BlogCategory.all()
if category:
cur_category = BlogCategory.all().filter("slug =", category).get()
posts = BlogPost.all().filter("category =", cur_category).order("-date_created")
else:
posts = BlogPost.all().order("-date_created")
cur_category = None
return {
"section": "blog",
"posts": posts,
"cur_category": cur_category,
"categories": categories,
}
示例6: getrecentposts
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import all [as 别名]
def getrecentposts(limit=5):
""" Get html for the [num] most recent posts.
Return a list of (title, html) tuples. """
q = BlogPost.all()
q.order('post_date')
posts = [(post.title, post.html) for post in q.run(limit=limit)]
return posts
示例7: generate_resource
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import all [as 别名]
def generate_resource(cls, post, resource):
from models import BlogPost
# Query all posts, and filter out drafts.
q = BlogPost.all().order("-published")
q.filter("published !=", datetime.datetime.max)
html = utils.render_template("labnotes.html", {"generator_class": cls.__name__, "posts": q})
static.set("/labnotes", html, config.html_mime_type)
示例8: getblogpost
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import all [as 别名]
def getblogpost(title):
""" Get a blog post titled 'title' from the data store.
Must be an exact match. """
q = BlogPost.all()
q.filter("title =", title.lower())
try:
post = q.get()
return post.title, post.html
except AttributeError:
return None
示例9: generate_resource
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import all [as 别名]
def generate_resource(cls, post, resource):
from models import BlogPost
# Query all posts, and filter out drafts.
q = BlogPost.all().order("-published")
q.filter("published !=", datetime.datetime.max)
by_year = {}
for post in q:
by_year.setdefault(post.published.year, []).append(post)
html = utils.render_template(
"archive.html",
{"generator_class": cls.__name__, "by_year": [by_year[y] for y in sorted(by_year, reverse=True)]},
)
static.set("/archive/", html, config.html_mime_type)
示例10: handleApost
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import all [as 别名]
def handleApost(id):
posts=memcache.get(KEY)
tags=memcache.get(TAG)
categories=memcache.get(CATEGORY)
if not posts:
posts = BlogPost.all().order("-timestamp").fetch(20)
memcache.add(KEY,posts)
if not tags:
tags = Tag.all().fetch(20)
memcache.add(TAG,tags)
if not categories:
categories= Category.all().fetch(20)
memcache.add(CATEGORY,categories)
obj=BlogPost.get_by_id(int(id))
tagkeys=obj.tags
if request.method=="GET":
apost=APost(id=id)
data=apost.retrieve()
return jsonify(msg="OK",posts=data)
elif users.is_current_user_admin() and request.method=="DELETE":
apost=APost(id=id)
apost.delete()
return jsonify(msg="OK")
elif users.is_current_user_admin() and request.method=="PUT":
title=request.json['title']
body=request.json['body']
date=request.json['date']
category=request.json['category']
posttags=request.json['tags']
apost=APost(title,body,date,category,posttags,id)
(data,returnedTags)=apost.update()
return jsonify(msg="OK",tags=returnedTags,posts=data)
示例11: action
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import all [as 别名]
def action(id=None):
if 'posts' not in globals():
global posts
posts=memcache.get(KEY)
tags=memcache.get(TAG)
categories=memcache.get(CATEGORY)
if not posts:
posts = BlogPost.all().order("-timestamp").fetch(20)
memcache.add(KEY,posts)
if not tags:
tags = Tag.all().fetch(20)
memcache.add(TAG,tags)
if not categories:
categories= Category.all().fetch(20)
memcache.add(CATEGORY,categories)
data=[]
#
if request.method=='GET':
# posts = BlogPost.all()
# posts.order("-timestamp")
# if category=="categories":
Categories=[]
[Categories.append([categoryobj.category,categoryobj.key().id()]) for categoryobj in categories]
Categories=map(lambda category:{"category":category[0],"catid":category[1]} ,Categories)
logging.info(Categories)
return jsonify(msg="OK",categories=Categories,header="Categories",type="categories")
示例12: db_delete
# 需要导入模块: from models import BlogPost [as 别名]
# 或者: from models.BlogPost import all [as 别名]
def db_delete():
""" Delete all blog posts in the datastore. Be careful! """
q = BlogPost.all()
db.delete(post.key() for post in q.run())
logging.info("Deleting blogposts...")