(cls, schema, saved_export=None, auto_select=True, export_settings=None)
return instance
Given an ExportDataSchema, this will generate an ExportInstance
Given an ExportDataSchema, this will generate an ExportInstance
Given an ExportDataSchema this will generate an ExportInstance
def generate_instance_from_schema(cls, schema, saved_export=None, auto_select=True, export_settings=None):
        """Given an ExportDataSchema, this will generate an ExportInstance"""
        if saved_export:
            instance = saved_export
        else:
            instance = cls._new_from_schema(schema, export_settings)

        instance.name = instance.name or instance.defaults.get_default_instance_name(schema)
        instance.app_id = schema.app_id
        instance.schema_id = schema._id

        latest_app_ids_and_versions = get_latest_app_ids_and_versions(
            schema.domain,
            getattr(schema, 'app_id', None),
        )
        group_schemas = schema.group_schemas

        for group_schema in group_schemas:
            table = instance.get_table(group_schema.path) or TableConfiguration(
                path=group_schema.path,
                label=instance.defaults.get_default_table_name(group_schema.path),
                selected=instance.defaults.default_is_table_selected(group_schema.path),
            )
            table.is_deleted = is_occurrence_deleted(
                group_schema.last_occurrences,
                latest_app_ids_and_versions,
            ) and not group_schema.inferred

            prev_index = 0
            for item in group_schema.items:
                index, column = table.get_column(
                    item.path, item.doc_type, None
                )
                if not column:
                    column = ExportColumn.create_default_from_export_item(
                        table.path,
                        item,
                        latest_app_ids_and_versions,
                        auto_select
                    )
                    if prev_index:
                        # if it's a new column, insert it right after the previous column
                        index = prev_index + 1
                        table.columns.insert(index, column)
                    else:
                        table.columns.append(column)

                # Ensure that the item is up to date
                column.item = item

                # Need to rebuild tags and other flags based on new build ids
                column.update_properties_from_app_ids_and_versions(latest_app_ids_and_versions)
                prev_index = index

            instance._insert_system_properties(instance.domain, schema.type, table)
            table.columns = cls._move_selected_columns_to_top(table.columns)

            if not instance.get_table(group_schema.path):
                instance.tables.append(table)

        return instance
def generate_instance_from_schema ( cls , schema , saved_export = None , auto_select = True , export_settings = None ) : if saved_export : instance = saved_export else : instance = cls . _new_from_schema ( schema , export_settings ) instance . name = instance . name or instance . defaults . get_default_instance_name ( schema ) instance . app_id = schema . app_id instance . schema_id = schema . _id latest_app_ids_and_versions = get_latest_app_ids_and_versions ( schema . domain , getattr ( schema , 'app_id' , None ) , ) group_schemas = schema . group_schemas for group_schema in group_schemas : table = instance . get_table ( group_schema . path ) or TableConfiguration ( path = group_schema . path , label = instance . defaults . get_default_table_name ( group_schema . path ) , selected = instance . defaults . default_is_table_selected ( group_schema . path ) , ) table . is_deleted = is_occurrence_deleted ( group_schema . last_occurrences , latest_app_ids_and_versions , ) and not group_schema . inferred prev_index = 0 for item in group_schema . items : index , column = table . get_column ( item . path , item . doc_type , None ) if not column : column = ExportColumn . create_default_from_export_item ( table . path , item , latest_app_ids_and_versions , auto_select ) if prev_index : # if it's a new column, insert it right after the previous column index = prev_index + 1 table . columns . insert ( index , column ) else : table . columns . append ( column ) # Ensure that the item is up to date column . item = item # Need to rebuild tags and other flags based on new build ids column . update_properties_from_app_ids_and_versions ( latest_app_ids_and_versions ) prev_index = index instance . _insert_system_properties ( instance . domain , schema . type , table ) table . columns = cls . _move_selected_columns_to_top ( table . columns ) if not instance . get_table ( group_schema . path ) : instance . tables . append ( table ) return instance