Add Batch Support for Importer

This assumes you already have a working importer, and wish to add "dynamic batch" support to it.

As usual, the word "import" is used generically; in some cases "export" might make more sense.

Here are the specifics behind the example shown in these instructions:

Declare Batch Support

The first step is simple enough. You just need to declare support within the importer's class. (This is the 3rd bullet from above.)

In our example we would edit the ProductImporter class within ~/src/rattail/rattail/importing/sample.py:

   1 class ProductImporter(FromSample, importing.model.ProductImporter):
   2 
   3     # must add this
   4     batches_supported = True

Make Things Pretty

Each row within an import batch will have an "object description" which is displayed in the Tailbone UI for instance. By default this description is basically str(obj) where obj is the source "object" being imported. Many times that default object description is not very helpful or pretty, in which case you can override. To do so you must add the '_object_str' field to the normalized data returned by your importer (3rd bullet from above).

In our example we would edit the normalize_host_object() method of the ProductImporter class within ~/src/rattail/rattail/importing/sample.py:

   1 class ProductImporter(FromSample, importing.model.ProductImporter):
   2 
   3     def normalize_host_object(self, csvrow):
   4         data = super(ProductImporter, self).normalize_host_object(csvrow)
   5 
   6         # must add this
   7         data['_object_str'] = "custom description for object: {}".format(csvrow)
   8 
   9         return data

LilSnippets/AddBatchSupportForImporter (last edited 2018-11-23 02:39:31 by LanceEdgar)