本文整理汇总了Python中model.Category.all方法的典型用法代码示例。如果您正苦于以下问题:Python Category.all方法的具体用法?Python Category.all怎么用?Python Category.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Category
的用法示例。
在下文中一共展示了Category.all方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from model import Category [as 别名]
# 或者: from model.Category import all [as 别名]
def post(self):
name = urllib.quote(self.request.get('name').encode('utf8'))
category = Category.all().filter('name',name).get()
if category is not None:
self.response.out.write('category: %s has already existed' % (name))
else:
category = Category()
category.name = name
category.put()
categories = Category.all()
template_values = {
'categories': categories,
}
self.generate('../templates/admin.html', template_values)
示例2: get
# 需要导入模块: from model import Category [as 别名]
# 或者: from model.Category import all [as 别名]
def get(self):
urls = []
def addurl(loc, lastmod=None, changefreq=None, priority=None):
url_info = {
'location': loc,
'lastmod': lastmod,
'changefreq': changefreq,
'priority': priority,
}
urls.append(url_info)
addurl(g_blog.baseurl, changefreq='daily', priority=1)
entries = Entry.all().filter('published =', True).order('-date').fetch(g_blog.sitemap_entries)
for item in entries:
loc = '%s/%s' % (g_blog.baseurl, item.link)
addurl(loc, item.date, 'daily', 0.9)
if g_blog.sitemap_include_category:
cats = Category.all()
for cat in cats:
loc = '%s/category/%s' % (g_blog.baseurl, cat.slug)
addurl(loc, None, 'weekly', 0.8)
if g_blog.sitemap_include_tag:
tags = Tag.all()
for tag in tags:
loc = '%s/tag/%s' % (g_blog.baseurl, urlencode(tag.tag))
addurl(loc, None, 'weekly', 0.8)
self.response.headers['Content-Type'] = 'text/xml; charset=utf-8'
self.render2('views/sitemap.xml', {'urlset': urls})
示例3: update_basic_info
# 需要导入模块: from model import Category [as 别名]
# 或者: from model.Category import all [as 别名]
def update_basic_info(
update_categories=False,
update_tags=False,
update_links=False,
update_comments=False,
update_archives=False,
update_pages=False):
from model import Entry,Archive,Comment,Category,Tag,Link
basic_info = ObjCache.get(is_basicinfo=True)
if basic_info is not None:
info = ObjCache.get_cache_value(basic_info.cache_key)
if update_pages:
info['menu_pages'] = Entry.all().filter('entrytype =','page')\
.filter('published =',True)\
.filter('entry_parent =',0)\
.order('menu_order').fetch(limit=1000)
if update_archives:
info['archives'] = Archive.all().order('-year').order('-month').fetch(12)
if update_comments:
info['recent_comments'] = Comment.all().order('-date').fetch(5)
if update_links:
info['blogroll'] = Link.all().filter('linktype =','blogroll').fetch(limit=1000)
if update_tags:
info['alltags'] = Tag.all().order('-tagcount').fetch(limit=100)
if update_categories:
info['categories'] = Category.all().fetch(limit=1000)
logging.debug('basic_info updated')
basic_info.update(info)
示例4: get
# 需要导入模块: from model import Category [as 别名]
# 或者: from model.Category import all [as 别名]
def get(self, page_slug=""):
if page_slug:
t_values = {}
posts = Entry.all().filter("is_external_page =", True).filter("entrytype =", 'page').filter("slug =", page_slug)
if posts.count() == 1:
logging.warning("find one page with slug=%s" % (page_slug))
posts = posts.fetch(limit=1)
post = posts[0]
t_values['post'] = post
# dump(post)
# find all comments
comments = Comment.all().filter("entry =", post).order("date")
t_values['comments'] = comments
else:
logging.warning("%d entries share the same slug %s" % (posts.count(), page_slug))
links = Link.all().order("date")
t_values['links'] = links
categories = Category.all()
t_values['categories'] = categories
pages = Entry.all().filter("is_external_page =", True).filter("entrytype =", 'page').order("date")
t_values['pages'] = pages
return self.response.out.write(render_template("page.html", t_values, "basic", False))
else:
self.redirect(uri_for("weblog.index"))
示例5: get
# 需要导入模块: from model import Category [as 别名]
# 或者: from model.Category import all [as 别名]
def get(self):
t_values = {}
logging.info("CategoryManager: get")
# find all categories
cates = Category.all().order("name")
t_values["categories"] = cates
return self.response.out.write(render_template("categories.html", t_values, "", True))
示例6: create_category
# 需要导入模块: from model import Category [as 别名]
# 或者: from model.Category import all [as 别名]
def create_category(category_name):
""" Create a category in datastore """
query = Category.all()
query.filter("description =", category_name)
ret = query.get()
if ret is None:
ret = Category()
ret.description = category_name
ret.put()
return ret
示例7: getCategoryLists
# 需要导入模块: from model import Category [as 别名]
# 或者: from model.Category import all [as 别名]
def getCategoryLists():
key_ = "category_lists"
categories = memcache.get(key_)
if categories is not None:
return categories
else:
categories_ = Category.all()
categories = [x for x in categories_]
if not memcache.add(key_, categories, 3600):
logging.error("Memcache set failed.")
return categories
示例8: get
# 需要导入模块: from model import Category [as 别名]
# 或者: from model.Category import all [as 别名]
def get(self):
categories = Category.all()
cache_stats = memcache.get_stats()
oldest_item_age = int(cache_stats['oldest_item_age'])
format_time = str(oldest_item_age/3600)+":"
oldest_item_age = oldest_item_age%3600
format_time += str(oldest_item_age/60)+":"
oldest_item_age = oldest_item_age%60
format_time += str(oldest_item_age/60)
cache_stats['oldest_item_age'] = format_time
ua_list = UserAgent.all().fetch(500)
ua_list = sorted(ua_list,key = lambda x:x.count,reverse = True)
visitor_counter = Visitor.all().count()
template_values = {
'cache_stats': cache_stats,
'ua_list': ua_list,
'visitor_counter': visitor_counter,
}
self.generate('../templates/admin.html', template_values)
示例9: post
# 需要导入模块: from model import Category [as 别名]
# 或者: from model.Category import all [as 别名]
def post(self, post_slug=""):
if post_slug:
t_values = {}
post_id = self.request.POST['post_id']
post = Entry.get_by_id(long(post_id))
if post:
# ok, we find the post, try to add comment to this post
logging.warning("find one post with post_id %s" % (post_id))
t_values['post'] = post
# dump(post)
# check google recaptcha, these two fileds might not exist due to connection to reCAPTCHA
recaptcha_challenge_field = self.request.POST.get('recaptcha_challenge_field', "")
recaptcha_response_field = self.request.POST.get('recaptcha_response_field', "")
remote_ip = self.request.environ['REMOTE_ADDR']
private_key = "6LdwFdISAAAAAOYRK7ls3O-kXPTnYDEstrLM2MRo"
antispam_flag = False
try:
result = submit(recaptcha_challenge_field, recaptcha_response_field, private_key, remote_ip)
logging.info("google recaptcha %s, %s" % (result.is_valid, result.error_code))
if result.is_valid:
antispam_flag = True
except:
e = sys.exc_info()[0]
logging.info(e)
# create comment for this post
if antispam_flag:
logging.info("PostManager - add comment")
comm_author = self.request.POST['author']
comm_email = self.request.POST['email']
comm_weburl = self.request.POST['weburl']
comm_content = self.request.POST['comment']
comment_ip = self.request.environ['REMOTE_ADDR']
comm = Comment(entry=post, author=comm_author, email=comm_email, weburl=comm_weburl, content=comm_content, ip=comment_ip)
comm.put()
t_values['alert_message'] = "Thanks %s for your comment!" % (comm_author)
else:
logging.warning("comment ignored because antispam failed")
t_values['alert_message'] = "Sorry, your comment was ignored because of reCAPTCHA failure!"
# find all comments
comments = Comment.all().filter("entry =", post).order("date")
logging.info("PostHandler, post, find %d comments" % (comments.count()))
if post_id:
# only update commentcount when new comment is added
post.commentcount = comments.count()
post.put()
t_values['comments'] = comments
else:
logging.warning("post_id %s does not exist" % (post_id))
links = Link.all().order("date")
t_values['links'] = links
categories = Category.all()
t_values['categories'] = categories
pages = Entry.all().filter("is_external_page =", True).filter("entrytype =", 'page').order("date")
t_values['pages'] = pages
return self.response.out.write(render_template("post.html", t_values, "basic", False))
else:
self.redirect(uri_for("weblog.index"))