本文整理匯總了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)