本文整理汇总了Python中models.Submission.query方法的典型用法代码示例。如果您正苦于以下问题:Python Submission.query方法的具体用法?Python Submission.query怎么用?Python Submission.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Submission
的用法示例。
在下文中一共展示了Submission.query方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Submission [as 别名]
# 或者: from models.Submission import query [as 别名]
def get(self, test):
"""Retrieve submissions for the current user."""
self.response.content_type = "application/json"
gplus_id = self.session.get("gplus_id")
if gplus_id is None:
self.response.status = 401
self.response.out.write(utils.createError(401, "Current user not connected."))
return
if test is not None:
user = ndb.Key("TestUser", gplus_id).get()
else:
user = ndb.Key("User", gplus_id).get()
if user is None:
self.response.status = 401
self.response.out.write(utils.createError(401, "Current user not connected."))
return
items = []
submissions = Submission.query(ancestor=user.key).order(-Submission.date).fetch(50)
for submission in submissions:
items.append({
"id": submission.key.id(),
"colour": submission.colour,
"url": submission.url,
"date": submission.date.strftime("%Y-%m-%dT%H:%M:%S.%f")
})
self.response.out.write(json.dumps({"items": items}))
示例2: get
# 需要导入模块: from models import Submission [as 别名]
# 或者: from models.Submission import query [as 别名]
def get(self, test):
"""Retrieve recent submissions"""
self.response.content_type = "application/json"
qry = Submission.query()
qry = qry.order(-Submission.date)
items = []
users = set()
curs = Cursor(urlsafe=self.request.get('cursor'))
submissions, next_curs, more = qry.fetch_page(10, start_cursor=curs)
for submission in submissions:
items.append({
"id": submission.key.id(),
"user": submission.key.parent().id(),
"colour": submission.colour,
"url": submission.url,
"date": submission.date.strftime("%Y-%m-%dT%H:%M:%S.%f")
})
users.add(submission.key.parent().id())
user_data = dict()
for user_id in users:
user = ndb.Key("User", user_id).get()
if user is None:
user = ndb.Key("TestUser", user_id).get()
if user is not None:
user_data[user_id] = {
"displayName": user.displayName,
"imageUrl": user.imageUrl
}
response = {}
response["items"] = items
response["users"] = user_data
if more and next_curs:
response["next"] = next_curs.urlsafe()
self.response.out.write(json.dumps(response))
示例3: getSubmissions
# 需要导入模块: from models import Submission [as 别名]
# 或者: from models.Submission import query [as 别名]
def getSubmissions(self):
submissions = Submission.query()
return self._copyToSubmissionForms(submissions)