def generate_from_case_export_instance(export_instance, output_file): assert isinstance(export_instance, CaseExportInstance) if not export_instance.selected_tables: raise DETConfigError( _('No Tables found in Export {name}').format( name=export_instance.name)) main_input_table = export_instance.selected_tables[0] main_output_table = DETTable( name=main_input_table.label, source='case', filter_name='type', filter_value=export_instance.case_type, rows=[], ) output = DETConfig(name=export_instance.name, tables=[main_output_table]) dd_property_types_by_name = _get_dd_property_types( export_instance.domain, export_instance.case_type) helper = CaseDETSchemaHelper(dd_property_types=dd_property_types_by_name) main_output_table.rows.append(DETRow(source_field='domain', field='domain')) _add_rows_for_table(main_input_table, main_output_table, helper=helper) _add_id_row_if_necessary(main_output_table, CASE_ID_SOURCE) # todo: add rows for other tables output.export_to_file(output_file)
def generate_from_form_export_instance(export_instance, output_file): assert isinstance(export_instance, FormExportInstance) if not export_instance.selected_tables: raise DETConfigError(_('No Tables found in Export {name}').format(name=export_instance.name)) output = DETConfig(name=export_instance.name) for input_table in export_instance.selected_tables: if _is_main_form_table(input_table): output_table = DETTable( name=input_table.label, source='form', filter_name='xmlns', filter_value=export_instance.xmlns, rows=[], ) output_table.rows.append(DETRow(source_field='domain', field='domain')) _add_rows_for_table(input_table, output_table, helper=FormDETSchemaHelper()) _add_id_row_if_necessary(output_table, FORM_ID_SOURCE) else: output_table = DETTable( name=input_table.label, source=f'form.{input_table.readable_path}[*]', filter_name='xmlns', filter_value=export_instance.xmlns, rows=[], ) helper = RepeatDETSchemaHelper(base_path=input_table.readable_path) _add_rows_for_table(input_table, output_table, helper=helper) output.tables.append(output_table) output.export_to_file(output_file)
def _add_id_row_if_necessary(output_table, source_value): # DET requires an "id" field to exist to use SQL export. # Insert one at the beginning of the table if it doesn't exist. if not any(row.field == ID_FIELD for row in output_table.rows): output_table.rows.insert(0, DETRow( source_field=source_value, field=ID_FIELD, ))
def _get_det_row_for_export_column(column, helper): return DETRow(source_field=helper.get_path(column), field=column.label, map_via=helper.get_map_via(column.item))
def _get_det_row_for_export_column(column, path_transform_fn): return DETRow( source_field=path_transform_fn(column.item.readable_path), field=column.label, map_via=_get_det_map_for_export_item_datatype(column.item.datatype) )