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


Python ObjectDict.type方法代码示例

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


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

示例1: _form_upload_post

# 需要导入模块: from tornado.util import ObjectDict [as 别名]
# 或者: from tornado.util.ObjectDict import type [as 别名]
    def _form_upload_post(self, send_status):
        """Process the request and create new Lattice resource.

        :param send_status: callback method to signal completion
        """
        data = self.application.data
        ctx = yield self._create_upload_context()

        content_type = self.handler.request.headers["Content-Type"]
        if not content_type.startswith("multipart/form-data;"):
            send_status(415)
            return

        ctx.lattice.particle_type = self.handler.get_argument("particle_type", "")
        if len(ctx.lattice.particle_type) == 0:
            ctx.errors.particle_type = "Particle Type is required"
        else:
            for p in ctx.particle_types:
                if p["type"] == ctx.lattice.particle_type:
                    particle_type = ObjectDict(p)
                    break
            else:
                ctx.errors.particle_type = "Particle Type '{}' is invalid" \
                                             .format(ctx.lattice.particle_type)

        ctx.lattice.name = self.handler.get_argument("name", "")
        if len(ctx.lattice.name) == 0:
            ctx.errors.name = "Name is required"

        ctx.lattice.branch = self.handler.get_argument("branch", "")
        if len(ctx.lattice.branch) == 0:
            ctx.errors.branch = "Branch is required"

        if self.handler.get_argument("autoversion", "off") == "on":
            ctx.lattice_autoversion = True
        else:
            ctx.lattice_autoversion = False

        ctx.lattice.version = self.handler.get_argument("version", "")
        if not ctx.lattice_autoversion:
            if len(ctx.lattice.version) == 0:
                ctx.errors.version = "Version is required"
            else:
                try:
                    ctx.lattice.version = int(ctx.lattice.version)
                except ValueError:
                    ctx.lattice.version = self._INITIAL_VERSION
                    ctx.errors.version = "Version must be an integer"
                if ctx.lattice.version <= 0:
                    ctx.errors.version = "Version must be greater than zero"

        ctx.lattice.description = self.handler.get_argument("description", "")

        ctx.lattice.status_type = self.handler.get_argument("status_type", "")

        ctx.lattice.created_by = self.handler.current_user

        ctx.lattice.created_date = datetime.now()

        ctx.lattice._id = ObjectId()

        request_files = self.handler.request.files

        if "lattice_file" not in request_files:
            ctx.errors.lattice_file = "Lattice File is required"

        elif len(request_files["lattice_file"]) == 0:
            ctx.errors.lattice_file = "Lattice File is required"

        if ctx.errors:
            send_status(400, ctx)
            return

        # check for another lattice with name, branch and version
        if ctx.lattice_autoversion:
            lattice = yield data.find_lattice_by_name(ctx.lattice.name,
                                                        ctx.lattice.branch)
        else:
            lattice = yield data.find_lattice_by_name(ctx.lattice.name,
                                    ctx.lattice.branch, ctx.lattice.version)

        if ctx.lattice_autoversion:
            if lattice:
                ctx.lattice.version = lattice.version + 1
            else:
                ctx.lattice.version = self._INITIAL_VERSION
        else:
            if lattice:
                ctx.errors.version = "Version already exists"

        if ctx.errors:
            send_status(400, ctx)
            return

        lattice_file = request_files["lattice_file"][0]

        try:
            lattice = read_lattice(StringIO(lattice_file.body))
        except Exception as e:
            LOGGER.warning("Error reading lattice: %s", e)
#.........这里部分代码省略.........
开发者ID:frib-high-level-controls,项目名称:phyhlc,代码行数:103,代码来源:impact.py


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