shuup.importer.importing package
Submodules
shuup.importer.importing.importing module
- class shuup.importer.importing.importing.ImporterExampleFile(file_name, content_type, template_name=None)[source]
Bases:
object
- file_name = ''
- content_type = ''
- template_name = ''
- class shuup.importer.importing.importing.ImporterContext(shop: Shop, language: str, supplier: Supplier = None, user: User = None, **kwargs)[source]
Bases:
object
- __init__(shop: Shop, language: str, supplier: Supplier = None, user: User = None, **kwargs)[source]
- language = None
- user: User = None
- class shuup.importer.importing.importing.DataImporter(data, context)[source]
Bases:
object
- identifier = None
- name = None
- meta_class_getter_name = 'get_import_meta'
- meta_base_class
alias of
ImportMetaBase
- extra_matches = {}
- custom_file_transformer = False
- unique_fields = {}
- unmatched_fields = {}
- relation_map_cache = {}
- example_files = []
- help_template = None
- model = None
- classmethod get_importer_context(request=None, shop: Shop = None, language: str = None, supplier: Supplier = None, user: User = None, **kwargs)[source]
Returns a context object for the given
request
that will be used on the importer process.request
parameter is deprecated- Return type:
- classmethod transform_file(mode, filename, data=None)[source]
That method will be called if
cls.custom_file_transformer
is True
- map_data_to_fields(model_mapping)[source]
Map fields.
If field is not found it will be saved into unmapped :return:
- get_fields_for_mapping(only_non_mapped=True)[source]
Get fields for manual mapping.
- Returns:
List of fields
module_name.Model:field
or empty list- Return type:
- get_row_model(row)[source]
Get model that matches the row.
Can be used in cases where you have multiple types of data in same import.
- Parameters:
row – A row dict.
- can_create_object(obj)[source]
Returns whether the importer can create the given object. This is useful to handle related objects creation and skip them when needed.
- property is_multi_model
Process Related values.
- Parameters:
field – Django Field object.
- Returns:
Found value
- classmethod get_help_context_data(request)[source]
Returns the context data that should be used for help texts in admin.
- classmethod get_example_file_content(example_file, request)[source]
Returns a binary file that will be served through the request. This base implementation just renders a template and returns the result as BytesIO or StringIO. Override this method to return a custom file content.
:param request HttpRequest :rtype StringIO|BytesIO
shuup.importer.importing.meta module
- class shuup.importer.importing.meta.ImportMetaBase(handler, model)[source]
Bases:
object
- fk_matchers = {}
- aliases = {}
Post save handlers
You can directly assign post save handler for a field. Field That has post save handler assigned won’t be available for mapping and won’t cause it to appear in unmapped fields in importer.
The handler is being triggered if any of the given values in trigger list is being encountered while iterating.
- This is a dictionary that contains list of values:
{function_name: [list_of_triggers]}
Example
- post_save_handlers = {
“handle_row_address”: [‘city’, ‘country’, ‘postal code’, ‘region code’, ‘street’],
}
In this example the
handle_row_address
is being called when any of the triggers is being encountered.
- post_save_handlers = {}
Fields to skip
It’s sometimes necessary to skip fields in importer.
For now we are using this to skip image fields in
ProductMetaBase
.
- fields_to_skip = []
- global_aliases = {}
Aliases for keys usually used in the importing meta
- This is dictionary that contains list of values:
{shuup_field: [expected_fields]}
Example
- aliases = {
“name_ext”: [“extension”, “ext”]
}
- get_import_defaults()[source]
Get default values for importing
If a certain value is required in import but does not exist in the imported file this method completes said missing data.
Example
- return {
“type_id”: ProductType.objects.first().id, “tax_class_id”: TaxClass.objects.first().id,
}
- should_skip_row(row)[source]
Allows you to skip a row from getting imported
Used to set up a condition for a row to get imported
- pre_process_row(row)[source]
Do a pre-processing task on the given row and change the data in place.
This method is called befor the row_session is created to allow to override values on the row or to create related objects.
- presave_hook(row_session)[source]
Pre-save Hook
This method is called before the row session is saved. This can be used to add data into
row_session.instance
- Parameters:
row_session (shuup.importer.importing.session.DataImporterRowSession) – Current row session
- Returns:
None
- postsave_hook(row_session)[source]
Post-save Hook
This method is called after the row session is saved. This can be used to create related objects.
- Parameters:
row_session (shuup.importer.importing.session.DataImporterRowSession) – Current row session
- Returns:
None
- has_post_save_handler(field_name)[source]
See if meta has Post-Save handler
- Parameters:
field_name – Name of the field to lookup
- Returns:
True or False if has post save handler
- Return type:
- property field_aliases
Get all field aliases
If local aliases are being set, global aliases are extended. :return: Dict key => list of aliases :rtype: dict[str, list]|dict
shuup.importer.importing.session module
Module contents
- class shuup.importer.importing.DataImporter(data, context)[source]
Bases:
object
- can_create_object(obj)[source]
Returns whether the importer can create the given object. This is useful to handle related objects creation and skip them when needed.
- custom_file_transformer = False
- example_files = []
- extra_matches = {}
- classmethod get_example_file_content(example_file, request)[source]
Returns a binary file that will be served through the request. This base implementation just renders a template and returns the result as BytesIO or StringIO. Override this method to return a custom file content.
:param request HttpRequest :rtype StringIO|BytesIO
- get_fields_for_mapping(only_non_mapped=True)[source]
Get fields for manual mapping.
- Returns:
List of fields
module_name.Model:field
or empty list- Return type:
- classmethod get_help_context_data(request)[source]
Returns the context data that should be used for help texts in admin.
- classmethod get_importer_context(request=None, shop: Shop = None, language: str = None, supplier: Supplier = None, user: User = None, **kwargs)[source]
Returns a context object for the given
request
that will be used on the importer process.request
parameter is deprecated- Return type:
- get_row_model(row)[source]
Get model that matches the row.
Can be used in cases where you have multiple types of data in same import.
- Parameters:
row – A row dict.
- help_template = None
- identifier = None
- property is_multi_model
- map_data_to_fields(model_mapping)[source]
Map fields.
If field is not found it will be saved into unmapped :return:
- meta_base_class
alias of
ImportMetaBase
- meta_class_getter_name = 'get_import_meta'
- model = None
- name = None
Process Related values.
- Parameters:
field – Django Field object.
- Returns:
Found value
- relation_map_cache = {}
- classmethod transform_file(mode, filename, data=None)[source]
That method will be called if
cls.custom_file_transformer
is True
- unique_fields = {}
- unmatched_fields = {}
- class shuup.importer.importing.DataImporterRowSession(importer, row, instance, shop)[source]
Bases:
object
- class shuup.importer.importing.ImportMetaBase(handler, model)[source]
Bases:
object
- aliases = {}
Post save handlers
You can directly assign post save handler for a field. Field That has post save handler assigned won’t be available for mapping and won’t cause it to appear in unmapped fields in importer.
The handler is being triggered if any of the given values in trigger list is being encountered while iterating.
- This is a dictionary that contains list of values:
{function_name: [list_of_triggers]}
Example
- post_save_handlers = {
“handle_row_address”: [‘city’, ‘country’, ‘postal code’, ‘region code’, ‘street’],
}
In this example the
handle_row_address
is being called when any of the triggers is being encountered.
- property field_aliases
Get all field aliases
If local aliases are being set, global aliases are extended. :return: Dict key => list of aliases :rtype: dict[str, list]|dict
- fields_to_skip = []
- fk_matchers = {}
- get_import_defaults()[source]
Get default values for importing
If a certain value is required in import but does not exist in the imported file this method completes said missing data.
Example
- return {
“type_id”: ProductType.objects.first().id, “tax_class_id”: TaxClass.objects.first().id,
}
- global_aliases = {}
Aliases for keys usually used in the importing meta
- This is dictionary that contains list of values:
{shuup_field: [expected_fields]}
Example
- aliases = {
“name_ext”: [“extension”, “ext”]
}
- has_post_save_handler(field_name)[source]
See if meta has Post-Save handler
- Parameters:
field_name – Name of the field to lookup
- Returns:
True or False if has post save handler
- Return type:
- post_save_handlers = {}
Fields to skip
It’s sometimes necessary to skip fields in importer.
For now we are using this to skip image fields in
ProductMetaBase
.
- postsave_hook(row_session)[source]
Post-save Hook
This method is called after the row session is saved. This can be used to create related objects.
- Parameters:
row_session (shuup.importer.importing.session.DataImporterRowSession) – Current row session
- Returns:
None
- pre_process_row(row)[source]
Do a pre-processing task on the given row and change the data in place.
This method is called befor the row_session is created to allow to override values on the row or to create related objects.
- presave_hook(row_session)[source]
Pre-save Hook
This method is called before the row session is saved. This can be used to add data into
row_session.instance
- Parameters:
row_session (shuup.importer.importing.session.DataImporterRowSession) – Current row session
- Returns:
None