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


Python Message.key方法代码示例

本文整理汇总了Python中models.Message.key方法的典型用法代码示例。如果您正苦于以下问题:Python Message.key方法的具体用法?Python Message.key怎么用?Python Message.key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Message的用法示例。


在下文中一共展示了Message.key方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import key [as 别名]
  def post(self, channelid):
    """Handles a message publish to this channel"""
    channel = self._getentity(Channel, channelid)
    if channel is None: return

    contenttype = self.request.headers['Content-Type']

    # Save message
    message = Message(
      contenttype = contenttype,
      body = self.request.body,
      channel = channel,
    )
    message.put()

#   for subscriber in Subscriber.all().filter('channel =', channel):
    subscribers = Subscriber.all().filter('channel =', channel)
    if subscribers.count():
      for subscriber in subscribers:
  
        # Set up delivery of message to subscriber
        delivery = Delivery(
          message = message,
          recipient = subscriber,
        )
        delivery.put()
  
      # Kick off a task to distribute message
      taskqueue.Task(
        url='/distributor/' + str(message.key())
      ).add(QUEUE_DISTRIBUTION)

      logging.debug("Delivery queued for %d subscribers of channel %s" % (subscribers.count(), channelid))
    else:
      logging.debug("No subscribers for channel %s" % (channelid, ))

    # TODO should we return a 202 instead of a 302?
    # Actually I think it's just a 201, as we've created a new (message) resource
#   self.redirect(self.request.url + 'message/' + str(message.key()))

    # Try to detect whether we're from the coffeeshop browser, and if so, return a 302
    self.response.headers['Location'] = self.request.url + "message/%s" % str(message.key())
    if contenttype == "application/x-www-form-urlencoded" and self.request.get('messagesubmissionform') == "coffeeshop":
      self.response.set_status(302)
    else:
      self.response.set_status(201)
开发者ID:qmacro,项目名称:coffeeshop,代码行数:48,代码来源:coffeeshop.py

示例2: post

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import key [as 别名]
    def post(self):

        errors = list()
        post = self.request.POST

        if "namespace" in post:
            namespace_name = post["namespace"].lower()
            query = db.GqlQuery("SELECT * FROM Namespace WHERE name = :1", namespace_name)
            namespace = query.get()
            if not namespace:
                errors.append("Namespace: not found")
            else:
                namespace_owner = namespace.owner
            if "auth_key" in post:
                auth_key = post["auth_key"]
                if namespace:
                    if auth_key != namespace.auth_key:
                        errors.append("AuthKey: not authorised")
            else:
                errors.append("AuthKey: not specified")
        else:
            errors.append("Namespace: not specified")

        if "name" in post:
            name = str(post["name"].lower())
            name = name[:100]
            if len(name) < 4:
                errors.append("Name: too short")
        else:
            errors.append("Name: not specified")

        if "level" in post:
            level = post["level"]
            if level not in ["debug", "info", "warn", "error", "fatal"]:
                level = "info"
            level_int = level_string_to_number(level)
        else:
            errors.append("Level: not specified")

        if "body" in post:
            body = str(post["body"])
            if len(body) < 1:
                errors.append("Body: too short")
        else:
            errors.append("Body: not specified")

        success = (len(errors) == 0)
        message_key = None
        
        if success:
            message = Message(namespace=namespace, namespace_owner=namespace_owner, name=name, level=level_int, auth_key=auth_key, body=body)
            message.put()
            message_key = str(message.key())
            memcache.set("message_latest_%s" % (namespace_owner), {"key": message_key, "namespace": namespace.name, "name": message.name, "level": message.level_string().upper(), "body": message.body, "created": message.created.strftime("%Y-%m-%d %H:%M:%S")})

        self.generate("rest/message_create.xml", {"success": success, "errors": errors, "key": message_key}) 
开发者ID:jinglemansweep,项目名称:log4gae,代码行数:58,代码来源:message.py


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