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 generate_from_export_instance(export_instance, output_file): if isinstance(export_instance, CaseExportInstance): return generate_from_case_export_instance(export_instance, output_file) elif isinstance(export_instance, FormExportInstance): return generate_from_form_export_instance(export_instance, output_file) else: raise DETConfigError( _('Export instance type {name} not supported!').format( name=type(export_instance).__name__))
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]) _add_rows_for_table(main_input_table, main_output_table, path_transform_fn=_transform_path_for_case_properties) _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=[], ) _add_rows_for_table(input_table, output_table) _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=[], ) # note: this has to be defined here because it relies on closures def _strip_repeat_path(input_path): return input_path.replace(f'{input_table.readable_path}.', '') _add_rows_for_table(input_table, output_table, path_transform_fn=_strip_repeat_path) output.tables.append(output_table) output.export_to_file(output_file)