示例#1
0
 def _enhance_datapoints_with_options(
     workbook: Workbook, schema: SchemaContent
 ) -> SchemaContent:
     for sheet_name in workbook.sheetnames:
         if not sheet_name.startswith(OPTIONS_SHEET_PREFIX):
             continue
         id_ = sheet_name[len(OPTIONS_SHEET_PREFIX) :]
         sheet = workbook[sheet_name]
         sheet_rows = sheet.values
         next(sheet_rows)
         options = [{"value": item[0], "label": item[1]} for item in sheet_rows]
         schema = transform.traverse_datapoints(
             schema, transform.substitute_options, id_=id_, options=options
         )
     return schema
示例#2
0
    def _construct_objects_from_workbook(self, workbook: Workbook) -> SchemaContent:
        schema_sheet = workbook[SCHEMA_SHEET_NAME]
        sheet_rows = ([_safe_strip(cell) for cell in columns] for columns in schema_sheet.values)
        attribute_types = self._extract_attribute_types(next(sheet_rows)[ATTRS_INDEX:])

        schema: SchemaContent = []
        for columns in sheet_rows:
            id_, parent_id, category, attrs = self._extract_attributes(columns)

            schema = transform.traverse_datapoints(
                schema,
                transform.add,
                parent_id=parent_id,
                datapoint_to_add=self._excel_row_to_datapoint(
                    id_, category, attrs, attribute_types
                ),
            )

        return schema