shuup.importer.importing package

Submodules

shuup.importer.importing.importing module

System Message: WARNING/2 (/home/docs/checkouts/readthedocs.org/user_builds/shuup/checkouts/latest/doc/api/shuup.importer.importing.rst, line 10)

error while formatting arguments for shuup.importer.importing.importing.ImporterContext: name ‘Shop’ is not defined

System Message: WARNING/2 (/home/docs/checkouts/readthedocs.org/user_builds/shuup/checkouts/latest/doc/api/shuup.importer.importing.rst, line 10)

error while formatting arguments for shuup.importer.importing.importing.DataImporter.get_importer_context: name ‘Shop’ is not defined
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[source]

Bases: object

shop = None
language = None
supplier = None
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 = set()
relation_map_cache = {}
example_files = []
help_template = None
model = None
classmethod get_importer_context()[source]

Returns a context object for the given request that will be used on the importer process.

request parameter is deprecated

Return type:ImporterContext
classmethod get_permission_identifier()[source]
classmethod transform_file(mode, filename, data=None)[source]

That method will be called if cls.custom_file_transformer is True

process_data()[source]
create_mapping()[source]
map_data_to_fields(model_mapping)[source]

Map fields.

If field is not found it will be saved into unmapped :return:

manually_match(imported_field_name, target_field_name)[source]
do_remap()[source]
matcher(value)[source]
set_extra_match(sess, value, mapping)[source]
do_import(import_mode)[source]
resolve_object(cls, value)[source]
process_row(row)[source]
save_row(new, row_session)[source]
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:list
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.

is_multi_model
find_matching_model(row)[source]

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 has_example_file()[source]
classmethod get_example_file(file_name)[source]

:param file_name str :rtype ImporterExampleFile

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’],

System Message: WARNING/2 (/home/docs/checkouts/readthedocs.org/user_builds/shuup/checkouts/latest/shuup/importer/importing/meta.py:docstring of shuup.importer.importing.meta.ImportMetaBase.aliases, line 16)

Definition list ends without a blank line; unexpected unindent.

}

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”]

System Message: WARNING/2 (/home/docs/checkouts/readthedocs.org/user_builds/shuup/checkouts/latest/shuup/importer/importing/meta.py:docstring of shuup.importer.importing.meta.ImportMetaBase.global_aliases, line 9)

Definition list ends without a blank line; unexpected unindent.

}

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,

System Message: WARNING/2 (/home/docs/checkouts/readthedocs.org/user_builds/shuup/checkouts/latest/shuup/importer/importing/meta.py:docstring of shuup.importer.importing.meta.ImportMetaBase.get_import_defaults, line 10)

Definition list ends without a blank line; unexpected unindent.

}

Returns:Dict of field name -> default value.
Return type:dict[str, str]|dict
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

Parameters:row (dict) – Current row data
Returns:True if the row should get skipped, False otherwise
Return type:bool
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.

Parameters:row (dict) – Current row data
Returns:the row modified, if needed
Return type:dict
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
mutate_normal_field_set(row_session, field, value, original)[source]
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:Boolean
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

class shuup.importer.importing.session.DataImporterRowSession(importer, row, instance, shop)[source]

Bases: object

defer(key, model, using=None)[source]
defer_call(func, *args, **kwargs)[source]
get_deferred(key)[source]
save()[source]
log(message)[source]

Module contents

System Message: WARNING/2 (/home/docs/checkouts/readthedocs.org/user_builds/shuup/checkouts/latest/doc/api/shuup.importer.importing.rst, line 35)

error while formatting arguments for shuup.importer.importing.DataImporter.get_importer_context: name ‘Shop’ is not defined
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.

create_mapping()[source]
custom_file_transformer = False
do_import(import_mode)[source]
do_remap()[source]
example_files = []
extra_matches = {}
find_matching_model(row)[source]
classmethod get_example_file(file_name)[source]

:param file_name str :rtype ImporterExampleFile

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:list
classmethod get_help_context_data(request)[source]

Returns the context data that should be used for help texts in admin.

classmethod get_importer_context()[source]

Returns a context object for the given request that will be used on the importer process.

request parameter is deprecated

Return type:ImporterContext
classmethod get_permission_identifier()[source]
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.
classmethod has_example_file()[source]
help_template = None
identifier = None
is_multi_model
manually_match(imported_field_name, target_field_name)[source]
map_data_to_fields(model_mapping)[source]

Map fields.

If field is not found it will be saved into unmapped :return:

matcher(value)[source]
meta_base_class

alias of ImportMetaBase

meta_class_getter_name = 'get_import_meta'
model = None
name = None
process_data()[source]

Process Related values.

Parameters:field – Django Field object.
Returns:Found value
process_row(row)[source]
relation_map_cache = {}
resolve_object(cls, value)[source]
save_row(new, row_session)[source]
set_extra_match(sess, value, mapping)[source]
classmethod transform_file(mode, filename, data=None)[source]

That method will be called if cls.custom_file_transformer is True

unique_fields = {}
unmatched_fields = set()
class shuup.importer.importing.DataImporterRowSession(importer, row, instance, shop)[source]

Bases: object

defer(key, model, using=None)[source]
defer_call(func, *args, **kwargs)[source]
get_deferred(key)[source]
log(message)[source]
save()[source]
class shuup.importer.importing.ImportMetaBase(handler, model)[source]

Bases: object

aliases = {}
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,

System Message: WARNING/2 (/home/docs/checkouts/readthedocs.org/user_builds/shuup/checkouts/latest/shuup/importer/importing/__init__.py:docstring of shuup.importer.importing.ImportMetaBase.get_import_defaults, line 10)

Definition list ends without a blank line; unexpected unindent.

}

Returns:Dict of field name -> default value.
Return type:dict[str, str]|dict
global_aliases = {}
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:Boolean
mutate_normal_field_set(row_session, field, value, original)[source]
post_save_handlers = {}
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.

Parameters:row (dict) – Current row data
Returns:the row modified, if needed
Return type:dict
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
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

Parameters:row (dict) – Current row data
Returns:True if the row should get skipped, False otherwise
Return type:bool
class shuup.importer.importing.ImporterExampleFile(file_name, content_type, template_name=None)[source]

Bases: object

content_type = ''
file_name = ''
template_name = ''