shuup.importer.importing package

Submodules

shuup.importer.importing.importing module

class shuup.importer.importing.importing.DataImporter(data, shop, language)[source]

Bases: object

meta_class_getter_name = 'get_import_meta'
meta_base_class

alias of ImportMetaBase

extra_matches = {}
unique_fields = {}
unmatched_fields = set()
relation_map_cache = {}
model = None
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
is_multi_model
find_matching_model(row)[source]

Process Related values

Parameters:field – Django Field object
Returns:Found value

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/v2.0.0/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/v2.0.0/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/v2.0.0/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
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

class shuup.importer.importing.DataImporter(data, shop, language)[source]

Bases: object

create_mapping()[source]
do_import(import_mode)[source]
do_remap()[source]
extra_matches = {}
find_matching_model(row)[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
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
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]
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/v2.0.0/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
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