本文整理汇总了Python中models.Tag.query方法的典型用法代码示例。如果您正苦于以下问题:Python Tag.query方法的具体用法?Python Tag.query怎么用?Python Tag.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Tag
的用法示例。
在下文中一共展示了Tag.query方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag 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: create_context
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import query [as 别名]
def create_context(self):
context = super(EditPost, self).create_context()
tags_future = Tag.query().fetch_async()
context['tags'] = tags_future.get_result()
if self.request.route.name == 'edit_post':
post_key = self.request.route_kwargs.get('key', None)
context['post'] = model.Key(urlsafe=post_key).get()
return context
示例3: get
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag 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)
示例4: post
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import query [as 别名]
#.........这里部分代码省略.........
website=self.request.POST["website"],
thumbnail=image,
institution=institution,
)
author.put()
elif mode == "2":
# Conference
conference = Conference(name=self.request.POST["name"], acronym=self.request.POST["acronym"])
conference.put()
pass
elif mode == "3":
# Publication
date = datetime.strptime(self.request.POST["date"], "%Y-%m-%d")
# A bit messy, does author order
authors = self.request.params.getall("authors")
idx = 0
author_order = [int(order_idx) for order_idx in self.request.POST["order"].split(",")]
ordered_authors = []
for author_idx in range(len(authors)):
ordered_authors.append(ndb.Key(urlsafe=authors[author_order[author_idx] - 1]))
conference = ndb.Key(urlsafe=self.request.POST["conference"])
pdf_image_url = self.request.POST["pdfimage"]
image = ""
if pdf_image_url:
try:
content = urllib2.urlopen(pdf_image_url)
image = content.read()
except urllib2.HTTPError:
logging.warning("URL: " + pdf_image_url + "was not found.")
publication = Publication(
title=self.request.POST["title"],
abstract=self.request.POST["abstract"],
date=date,
authors=ordered_authors,
citation=self.request.POST["citation"],
conference=conference,
pdf=self.request.POST["pdf"],
pdf_image=image,
arxiv_link=self.request.POST["arxiv"],
project_page=self.request.POST["projectpage"],
)
publication.put()
elif mode == "4":
# Content
content = Content(name=self.request.POST["name"], content=self.request.POST["content"])
content.put()
elif mode == "5":
# Project
authors = []
for author in self.request.params.getall("authors"):
authors.append(ndb.Key(urlsafe=author))
image_url = self.request.POST["image"]
if image_url:
try:
content = urllib2.urlopen(image_url)
image = content.read()
except urllib2.HTTPError:
logging.warning("URL: " + image_url + "was not found.")
image = ""
else:
image = ""
publications = []
for publication in self.request.params.getall("publications"):
publications.append(ndb.Key(urlsafe=publication))
contents = []
for content in self.request.params.getall("contents"):
contents.append(ndb.Key(urlsafe=content))
tags = []
for tag in self.request.POST["tags"].split(","):
# Try to find tag.
stripped_tag = tag.strip()
query = Tag.query(Tag.name == stripped_tag)
if query.count() == 1:
query_tag = query.get(keys_only=True)
tags.append(query_tag)
elif query.count() == 0:
query_tag = Tag(name=stripped_tag)
tags.append(query_tag.put())
else:
logging.error("Tag count > 1 | < 0 (%s)." % stripped_tag)
project = Project(
title=self.request.POST["title"],
description=self.request.POST["description"],
authors=authors,
image=image,
publications=publications,
extra_content=contents,
tags=tags,
)
project.put()
return self.get()
示例5: _get_tags_for_json_response
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import query [as 别名]
def _get_tags_for_json_response(self):
tags = Tag.query().fetch()
return json.dumps([{'key': t.key.urlsafe(), 'name': t.name}
for t in tags])