本文整理汇总了Python中models.Category.query方法的典型用法代码示例。如果您正苦于以下问题:Python Category.query方法的具体用法?Python Category.query怎么用?Python Category.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Category
的用法示例。
在下文中一共展示了Category.query方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import query [as 别名]
def post(self):
update = self.request.get('update', False)
cate_name = self.request.get('cate_name')
tags_list = self.request.get_all('tags_name', [])
title = self.request.get('title')
blog = self.request.get('blog')
if not blog:
self.response.write('blog content empty!')
cate = Category.query(Category.title==cate_name).get()
if not cate:
cate = Category(title=cate_name)
cate.put()
print tags_list
tags = Tag.query(Tag.title.IN(tags_list)).fetch()
tags_old = [tag.title for tag in tags]
tags_new = []
for tag in tags_list:
if tag not in tags_old:
tag = Tag(title=tag)
tag.put()
tags_new.append(tag)
print tags
print tags_new
tags += tags_new
print tags
print '==='
print dir(tags[0])
tags = [tag.key for tag in tags]
blog = Blog(title=title, text=blog, category=cate.key, tags=tags)
blog.put()
self.response.write('blog publish success')
self.response.set_status(200)
示例2: save_categories
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import query [as 别名]
def save_categories(request, slug):
if request.method == 'POST':
post = get_object_or_404(request.site['posts'], slug=slug)
categories = request.POST['value']
post['categories'].delete()
for category in categories.split(","):
category,created = Category.query().get_or_create(name=category.strip().lower())
post['categories'].get_or_create(category=category)
return HttpResponse(post.get_categories())
示例3: GET
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import query [as 别名]
def GET(self, name):
if name.lower() == 'category':
q = Category.query().order(Category.name)
results, cursor, more = q.fetch_page(10)
if cursor: cursor = cursor.urlsafe()
return render.list(categories=results, cursor=cursor, more=more)
elif name.lower() == 'entry':
q = Entry.query().order(-Entry.timestamp)
results,cursor,more = q.fetch_page(10, projection=[
Entry.timestamp,
Entry.title,
Entry.published])
if cursor: cursor = cursor.urlsafe()
return render.list(posts=results, cursor=cursor, more=more)
else:
raise web.seeother('/admin')
示例4: GET
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import query [as 别名]
def GET(self, name):
#get latest 3 blog posts
c = Category.query(Category.name ==name).fetch(1)
if len(c) == 0:
raise web.notfound()
else:
q = Entry.query(Entry.published==True).order(-Entry.timestamp)
entries = q.filter(Entry.category==c[0].key).fetch(3)
for e in entries:
e.category_name = name
data = {
'entries' : extend_entry(entries),
'categories': categories.fetch(),
'e_list': extend_entry(e_list.fetch(5, projection=[Entry.title, Entry.alias, Entry.timestamp]))
}
return render.index(**data)
示例5: get_all_categories
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import query [as 别名]
def get_all_categories():
"""Returns all categories"""
return Category.query(ancestor=ROOT_CATEGORY_KEY).fetch()
示例6: create_form
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import query [as 别名]
def create_form(entity):
#todo: proper validation for tags
if entity.__class__.__name__ == 'Entry':
q = Category.query().order(Category.name)
categories = q.fetch(10)
try:
tags = reduce(lambda x,y: x + ' ' + y, entity.tags)
except:
tags = ''
createform = form.Form(
form.Checkbox(
'published',
value=entity.published if entity.published else False,
checked=entity.published
),
form.Textbox(
'title',
form.notnull,
value=entity.title
),
form.Dropdown(
'category',
map(lambda x: (x.key.urlsafe(), x.name), categories)
),
form.Hidden(
'content',
form.notnull,
value=entity.content,
),
form.Hidden(
'intro',
value=entity.intro
),
form.Div(
'content',
value=entity.content,
id='epiceditor'
),
form.Textbox(
'tags',
form.regexp(
r'^$|[a-zA-Z- ]',
'Invalid tag(s) entered.'
),
value=tags
),
form.Button(
'submit',
type_='submit',
class_='btn btn-primary btn-large'
)
)
elif entity.__class__.__name__ == 'Category':
createform = form.Form(
form.Textbox(
'name',
form.notnull,
form.regexp(
r'[a-zA-Z ]',
'Invalid chars entered.'
),
value=entity.name
),
form.Textbox(
'desc',
form.notnull,
value=entity.desc
),
form.Button(
'submit',
type_='submit',
class_='btn btn-primary btn-large'
)
)
return createform
示例7: get
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import query [as 别名]
def get(self):
# TODO: forms uses
taglist = Tag.query().fetch()
catelist = Category.query().fetch()
self.render("pub.html", taglist=taglist, catelist=catelist)
示例8: extend_entry
# 需要导入模块: from models import Category [as 别名]
# 或者: from models.Category import query [as 别名]
return decorate
def extend_entry(entries, category=False):
'''Extends each entry object with url attribute
Uses flag to determine if category should be extended too
'''
for e in entries:
d = e.timestamp
e.url = '%s/%s/%s/%s' % (d.year, d.month, d.day, e.alias)
if category:
e.category_name = e.category.get().name
return entries
categories = Category.query().order(Category.name)
e_list = Entry.query(Entry.published==True).order(-Entry.timestamp)
class index:
def GET(self):
#get latest 3 blog posts
q = Entry.query(Entry.published==True).order(-Entry.timestamp)
entries = q.fetch(3)
data = {
'entries' : extend_entry(entries, True),
'categories': categories.fetch(),
'e_list': extend_entry(e_list.fetch(5, projection=[Entry.title, Entry.alias, Entry.timestamp]))
}
return render.index(**data)