本文整理汇总了Python中models.Author.put方法的典型用法代码示例。如果您正苦于以下问题:Python Author.put方法的具体用法?Python Author.put怎么用?Python Author.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Author
的用法示例。
在下文中一共展示了Author.put方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: copyFromArticles
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import put [as 别名]
def copyFromArticles(self, request):
'''Copies articles and authors from legacy Articles Kind into new Article and Author kinds'''
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
for article in Articles().all():
if '@' not in article.author:
author_email = article.author + '@gmail.com'
else:
author_email = article.author
a_key = ndb.Key(Author, author_email)
author = a_key.get()
# create new Author if not there
if not author:
author = Author(
key = a_key,
authorID = str(Author.allocate_ids(size=1)[0]),
displayName = author_email.split('@')[0],
mainEmail = author_email,
)
author.put()
self.copyArticlesKind(article, author)
return BooleanMessage(data=True)
示例2: make_author
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import put [as 别名]
def make_author(author_link, commit=True):
id = find_int(author_link['href'])
username = unicode(author_link.string)
key = db.Key.from_path('Author', int(id))
author = Author(key=key, username=username)
if commit:
author.put()
return author
示例3: create
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import put [as 别名]
def create(request):
"""
Create an author.
"""
name = request.POST["author_name"]
author_email = request.POST["author_email"]
author = Author.query(Author.email == author_email).get()
if (author is None):
author = Author(name=name, email=author_email)
else:
author.name = name
author.put()
return HttpResponse(json_fixed.dumps(author))
示例4: _getAuthorFromEmail
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import put [as 别名]
def _getAuthorFromEmail(self, email):
"""Return user Author from datastore, creating new one if non-existent."""
# get Author from datastore or create new Author if not there
a_key = ndb.Key(Author, email)
author = a_key.get()
# create new Author if not there
if not author:
author = Author(
key = a_key,
authorID = str(Author.allocate_ids(size=1)[0]),
displayName = user.nickname(),
mainEmail = user.email(),
)
author.put()
return author
示例5: create
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import put [as 别名]
def create(request):
"""
Create an author.
"""
name = request.POST["name"]
author = Author(name=name)
author_id = author.put().id()
return HttpResponse("Created an author: %s %s " % (name, author_id))
示例6: _getAuthorFromUser
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import put [as 别名]
def _getAuthorFromUser(self):
"""Return user Author from datastore, creating new one if non-existent."""
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
# get Author from datastore or create new Author if not there
user_id = getUserId(user)
a_key = ndb.Key(Author, user_id)
author = a_key.get()
# create new Author if not there
if not author:
author = Author(
key = a_key,
authorID = str(Author.allocate_ids(size=1)[0]),
displayName = user.nickname(),
mainEmail = user.email(),
)
author.put()
return author
示例7: copyArticlesKind
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import put [as 别名]
def copyArticlesKind(self, article, author):
"""Create new Article and Comment objects from old Articles object, returning True if success."""
article_id = Article.allocate_ids(size=1, parent=author.key)[0]
article_key = ndb.Key(Article, article_id, parent=author.key)
a = article_key.get()
if a:
return
# copy ArticleForm/ProtoRPC Message into dict
data = db.to_dict(article)
data['key'] = article_key
if 'comments' in data:
for comment in data['comments']:
#Create new Comment object
comment_author_email = str(loads(str(comment))[1])
a_key = ndb.Key(Author, comment_author_email or 'unknown')
comment_author = a_key.get()
# create new Author if not there
if not comment_author:
comment_author = Author(
key = a_key,
authorID = str(Author.allocate_ids(size=1)[0]),
displayName = comment_author_email.split('@')[0],
mainEmail = comment_author_email,
)
comment_author.put()
comment_data = {
'comment': loads(str(comment))[0],
'authorName': comment_author.displayName if comment_author else 'unknown',
'authorID': comment_author.authorID if comment_author else 'unknown',
'dateCreated': loads(str(comment))[2]
}
comment_id = Comment.allocate_ids(size=1, parent=article_key)[0]
comment_key = ndb.Key(Comment, comment_id, parent=article_key)
comment_data['key'] = comment_key
# create Comment
Comment(**comment_data).put()
del data['comments']
if 'tags' in data:
#del data['tags']
try:
data['tags'] = str(data['tags']).split(', ')
except UnicodeEncodeError:
del data['tags']
if 'tags' in data and data['tags'] == [""]:
del data['tags']
if 'id' in data:
del data['id']
if data['view'] == None:
del data['view']
else:
data['view'] = {'Publish': 'PUBLISHED', 'Preview': 'NOT_PUBLISHED', 'Retract': 'RETRACTED'}[str(data['view'])]
data['legacyID'] = str(article.key().id())
data['authorName'] = author.displayName
del data['author']
data['dateCreated'] = data['date']
del data['date']
# create Article
Article(**data).put()
示例8: post
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author 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(","):
#.........这里部分代码省略.........