Changeset - 4105ff43034b
[Not reviewed]
0 1 0
Lance Edgar (lance) - 4 months ago 2024-07-04 20:31:50
lance@edbob.org
fix: add `get_cmd()` method for import handlers

now that we have no direct reference to command/subcommand objects,
must deduce them some other way for sake of locating correct email
profile config
1 file changed with 23 insertions and 5 deletions:
0 comments (0 inline, 0 general)
rattail/importing/handlers.py
Show inline comments
 
@@ -35,6 +35,7 @@ import humanize
 
import markupsafe
 

	
 
from rattail.util import get_object_spec
 
from rattail.exceptions import ConfigurationError
 

	
 

	
 
log = logging.getLogger(__name__)
 
@@ -523,6 +524,23 @@ class ImportHandler(object):
 
    def commit_local_transaction(self):
 
        pass
 

	
 
    def get_cmd(self, ignore_errors=False):
 
        handler_key = self.get_key()
 

	
 
        cmd = self.config.getlist('rattail.importing', f'{handler_key}.cmd')
 
        if not cmd or len(cmd) != 2:
 
            cmd = self.config.getlist('rattail.importing',
 
                                      f'{handler_key}.default_cmd')
 

	
 
            if not cmd or len(cmd) != 2:
 
                msg = (f"Missing or invalid config; please set '{handler_key}.default_cmd' in the "
 
                       "[rattail.importing] section of your config file")
 
                if ignore_errors:
 
                    return
 
                raise ConfigurationError(msg)
 

	
 
        return cmd
 

	
 
    def process_changes(self, changes):
 
        """
 
        This method is called any time changes occur, regardless of whether the
 
@@ -549,16 +567,16 @@ class ImportHandler(object):
 
            'max_display': self.diff_max_display,
 
        }
 

	
 
        command = getattr(self, 'command', None)
 
        command = self.get_cmd(ignore_errors=True)
 
        if command:
 
            data['command'] = '{} {}'.format(command.parent.name, command.name)
 
        else:
 
            data['command'] = None
 
            command, subcommand = command
 

	
 
        if command:
 
            key = '{}_{}_updates'.format(command.parent.name, command.name)
 
            data['command'] = f'{command} {subcommand}'
 
            key = f'{command}_{subcommand}_updates'
 
            key = key.replace('-', '_')
 
        else:
 
            data['command'] = None
 
            key = 'rattail_import_updates'
 

	
 
        self.app.send_email(key, fallback_key='rattail_import_updates', data=data)
0 comments (0 inline, 0 general)