当前位置: 首页>>代码示例>>Python>>正文


Python Submission.query方法代码示例

本文整理汇总了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}))        
开发者ID:babus,项目名称:mirror-api,代码行数:34,代码来源:service.py

示例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))
开发者ID:MarcosBermudez,项目名称:mirror-api,代码行数:43,代码来源:service.py

示例3: getSubmissions

# 需要导入模块: from models import Submission [as 别名]
# 或者: from models.Submission import query [as 别名]
	def getSubmissions(self):
		submissions = Submission.query()
		return self._copyToSubmissionForms(submissions)
开发者ID:codegress,项目名称:code-gress,代码行数:5,代码来源:main.py


注:本文中的models.Submission.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。