def get_bulk_actions(): import re config = fetch_aristotle_settings() if not hasattr(get_bulk_actions, 'actions') or not get_bulk_actions.actions: actions = {} for action_name, form in config.get('BULK_ACTIONS', {}).items(): if not re.search('^[a-zA-Z0-9\_\.]+$', form): # pragma: no cover # Invalid download_type raise registry_exceptions.BadBulkActionModuleName( "Bulk action isn't a valid Python module name.") from django.utils.module_loading import import_string # module, form = form.rsplit('.', 1) # f = exec('from %s import %s as f' % (module, form)) f = import_string(form) # We need to make this a dictionary, not a class as otherwise # the template engine tries to instantiate it. frm = {'form': f} for prop in ['classes', 'can_use', 'text']: frm[prop] = getattr(f, prop, None) actions[action_name] = frm # Save to method to prevent having to reimport everytime get_bulk_actions.actions = actions return get_bulk_actions.actions
def get_bulk_actions(): import re config = fetch_aristotle_settings() actions = {} for action_name in config.get('BULK_ACTIONS', []): if not re.search('^[a-zA-Z0-9\_\.]+$', action_name): # pragma: no cover # Invalid download_type raise registry_exceptions.BadBulkActionModuleName("Bulk action isn't a valid Python module name.") from django.utils.module_loading import import_string f = import_string(action_name) # We need to make this a dictionary, not a class as otherwise # the template engine tries to instantiate it. frm = {'form': f} for prop in ['classes', 'can_use', 'text']: frm[prop] = getattr(f, prop, None) actions[action_name] = frm return actions