本文整理汇总了Python中models.Tag.put方法的典型用法代码示例。如果您正苦于以下问题:Python Tag.put方法的具体用法?Python Tag.put怎么用?Python Tag.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Tag
的用法示例。
在下文中一共展示了Tag.put方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testdb_init
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import put [as 别名]
def testdb_init():
# db clear
t1 = Tag(title="emacs")
t2 = Tag(title="python")
t1.put()
t2.put()
c1 = Category(title='program')
c2 = Category(title='edit')
c1.put()
c2.put()
b1 = Blog(title='first blog')
b1.context = "this is my first blog, hello world"
b1.put()
b2 = Blog(title="second blog")
b2.context = "this is my second blog, hello python"
b2.tags = [t1.key, t2.key]
b2.put()
b3 = Blog(title="third blog")
b3.context = "this is my third blog, hello python"
b3.tags = [t1.key,]
b3.category = c2.key
b3.put()
b4 = Blog(title="fourth blog")
b4.context = "this is my fourth blog, hello python"
b4.tags = [t2.key,]
b4.category = c1.key
b4.put()
示例2: post
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import put [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)
示例3: POST
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import put [as 别名]
def POST(self):
user = users.get_current_user()
form = form_add_tag()
object = {}
if form.validates():
object["success"] = True
object["response"] = form.d.tag
tag = Tag(author=user, name=form.d.tag)
tag.put()
object["message"] = "New tag has been created"
else:
object["success"] = False
object["errors"] = form.get_errors()
object["message"] = "Tag has not been created"
return simplejson.dumps(object)
示例4: setUp
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import put [as 别名]
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
tag1 = Tag(title='emacs')
tag2 = Tag(title='vim')
tag1.put()
tag2.put()
cate = Category(title='emacs笔记')
cate.put()
b1 = Blog(title="the first emacs blog", context="hello, world",
category=cate.key, tags=[tag1.key, tag2.key])
b2 = Blog(title="the second emacs blog", context="hello, world",
category=cate.key, tags=[tag1.key, tag2.key])
b3 = Blog(title="the third emacs blog", context="hello, world",
category=cate.key, tags=[tag1.key, tag2.key])
b1.put()
b2.put()
b3.put()
示例5: post
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import put [as 别名]
def post(self):
user = users.get_current_user()
url = self.request.get('url_text')
tags = self.request.get('url_tag').split(",")
usable_tags = []
for tag_name in tags:
if len(tag_name) is 0:
continue
tag = Tag(name = tag_name)
tags_query = Tag.all()
tags_query.filter('name =', tag_name)
if len(tags_query.fetch(1)) is not 0:
continue
tag.put()
usable_tags.append(tag.key())
book_mark = Bookmark(user = user, url = url, tags = usable_tags)
book_mark.put()
json_data = simplejson.dumps({'result':True, 'link': url, 'tags': tags})
self.response.out.write(json_data)
示例6: post
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import put [as 别名]
def post(self):
if not self.user.administrator:
return webapp2.redirect("/")
mode = self.request.POST["mode"]
if mode == "0":
# Institution
institution = Institution(name=self.request.POST["name"], website=self.request.POST["website"])
institution.put()
elif mode == "1":
thumbnail_url = self.request.POST["thumbnail"]
try:
content = urllib2.urlopen(thumbnail_url)
image = content.read()
except urllib2.HTTPError:
logging.warning("URL: " + thumbnail_url + "was not found.")
image = ""
institution = ndb.Key(urlsafe=self.request.POST["institution"])
author = Author(
name=self.request.POST["name"],
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(","):
#.........这里部分代码省略.........