Changeset - 8cebc88068ab
[Not reviewed]
0 1 0
Lance Edgar (lance) - 4 years ago 2020-08-12 15:10:33
lance@edbob.org
Fix how we obtain local system title for importers

we just can't go around assuming a handler is always in use
1 file changed with 11 insertions and 3 deletions:
0 comments (0 inline, 0 general)
rattail/importing/importers.py
Show inline comments
 
@@ -127,12 +127,20 @@ class Importer(object):
 
                                     "for {}".format(field, self.__class__.__name__))
 
        self.model_name = kwargs.pop('model_name', self.model_name)
 
        if not self.model_name and self.model_class:
 
            self.model_name = self.model_class.__name__
 
        self._setup(**kwargs)
 

	
 
    def get_local_system_title(self):
 
        """
 
        Retrieve the system title for the local/target side.
 
        """
 
        if hasattr(self, 'handler'):
 
            return self.handler.local_title
 
        return self.local_system_title or "??"
 

	
 
    def include_fields(self, *args):
 
        """
 
        Add the given fields to the supported field list for the importer.  May
 
        be used at runtime to customize behavior.
 
        """
 
        for field in args:
 
@@ -293,13 +301,13 @@ class Importer(object):
 
            # flush changes every so often
 
            if not self.batch_size or (len(created) + len(updated)) % self.batch_size == 0:
 
                self.flush_create_update()
 

	
 
        try:
 
            self.progress_loop(import_, data, message="{}ing {} data to {}".format(
 
                self.direction.capitalize(), self.model_name, self.handler.local_title))
 
                self.direction.capitalize(), self.model_name, self.get_local_system_title()))
 
        except ImportLimitReached:
 
            pass
 
        self.flush_create_update_final()
 
        return created, updated
 

	
 
    # def _populate_create_update(self, row_table, data):
 
@@ -466,20 +474,20 @@ class Importer(object):
 
            data = self.normalize_local_object(obj)
 
            key = self.get_key(data)
 
            cached[key] = {'object': obj, 'data': data}
 

	
 
        self.progress_loop(cache, objects,
 
                           message="Reading {} data from {}".format(
 
                               self.model_name, self.handler.local_title))
 
                               self.model_name, self.get_local_system_title()))
 
        return cached
 

	
 
    def cache_local_message(self):
 
        """
 
        Must return a message to be used for progress when fetching "local" data.
 
        """
 
        return "Reading {} data from {}".format(self.model_name, self.handler.local_title)
 
        return "Reading {} data from {}".format(self.model_name, self.get_local_system_title())
 

	
 
    def get_cache_key(self, obj, normal):
 
        """
 
        Get the primary cache key for a given object and normalized data.
 

	
 
        Note that this method's signature is designed for use with the
0 comments (0 inline, 0 general)