當前位置: 首頁>>代碼示例>>Python>>正文


Python ObjectDict.lattice_id方法代碼示例

本文整理匯總了Python中tornado.util.ObjectDict.lattice_id方法的典型用法代碼示例。如果您正苦於以下問題:Python ObjectDict.lattice_id方法的具體用法?Python ObjectDict.lattice_id怎麽用?Python ObjectDict.lattice_id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tornado.util.ObjectDict的用法示例。


在下文中一共展示了ObjectDict.lattice_id方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _form_upload_post

# 需要導入模塊: from tornado.util import ObjectDict [as 別名]
# 或者: from tornado.util.ObjectDict import lattice_id [as 別名]

#.........這裏部分代碼省略.........
            file_content[file_id] = data_file.body

        # check that all the data files specified by the
        # lattice have been submitted as attachments
        for filename in lattice.files:
            for f in ctx.lattice.files:
                if f.filename == filename:
                    break
            else:
                ctx.errors.data_file = "Missing data file: " + filename
                send_status(400, ctx)
                return

        attachment_path = self.settings.get("attachment_path", "")
        if len(attachment_path) == 0:
            LOGGER.warn("setting 'attachment_path' not found")
            ctx.errors._global = "Attachment directory not specified"
            send_status(500, ctx)
            return

        if not os.path.isdir(attachment_path):
            LOGGER.error("attachment path '%s' not found", attachment_path)
            ctx.errors._global = "Attachment directory not found"
            send_status(500, ctx)
            return

        try:
            yield data.validate_lattice(ctx.lattice)
        except Exception as e:
            LOGGER.error("lattice validation error: %s", e)
            ctx.errors._global = "Lattice validation error"
            send_status(500, ctx)
            return

        lattice_elements = []
        for idx, element in enumerate(lattice.elements):
            lattice_element = ObjectDict()
            lattice_element.lattice_id = ctx.lattice._id
            lattice_element.order = idx+1
            lattice_element.name = element.name
            lattice_element.type = element.etype
            lattice_element.length = element.length
            lattice_element.position = element.position
            lattice_element.properties = []
            lattice_element.properties.append(dict(
                name="ITYPE",
                value=element.itype
            ))
            lattice_element.properties.append(dict(
                name="STEPS",
                value=element.steps
            ))
            for field in element.fields:
                lattice_element.properties.append(dict(
                    name = field.name,
                    unit = field.unit,
                    value = element.getfield(field.name)
                ))

            try:
                yield data.validate_lattice_element(lattice_element)
            except Exception as e:
                LOGGER.error("lattice element validation error: %s", e)
                ctx.errors._global = "Lattice element validation error"
                send_status(500, ctx)
                return

            lattice_elements.append(lattice_element)

        try:
            lattice_id = yield data.insert_lattice(ctx.lattice, validate=False)
        except Exception as e:
            LOGGER.error("lattice database insert error: %s", e)
            ctx.errors._global = "Lattice database insert error"
            send_status(500, ctx)
            return

        try:
            for lattice_element in lattice_elements:
                lattice_element.lattice_id = lattice_id
                data.insert_lattice_element(lattice_element, validate=False)
        except Exception as e:
            LOGGER.error("lattice element database insert error: %s", e)
            ctx.errors._global = "Lattice element database insert error"
            # Rollback?
            send_status(500, ctx)
            return

        try:
            for f in ctx.lattice.files:
                _write_file_content(attachment_path, f.location, file_content[f.id])
        except Exception as e:
            LOGGER.exception("lattice file write error: %s", e)
            ctx.errors._global = "Lattice file write error"
            #Rollback?
            send_status(500, ctx)
            return

        send_status(201, ctx)
        return
開發者ID:frib-high-level-controls,項目名稱:phyhlc,代碼行數:104,代碼來源:impact.py


注:本文中的tornado.util.ObjectDict.lattice_id方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。