diff --git a/menu_generator/menu.py b/menu_generator/menu.py index 5e1015c..6fb219e 100755 --- a/menu_generator/menu.py +++ b/menu_generator/menu.py @@ -39,20 +39,18 @@ def _is_validated(self, item_dict): if not isinstance(validators, (list, tuple)): raise ImproperlyConfigured("validators must be a list") - result_validations = [] for validator in validators: if isinstance(validator, tuple): - if len(validator) <= 1: + func_or_path, *args = validator + if not args: raise ImproperlyConfigured("You are passing a tuple validator without args %s" % str(validator)) - func = get_callable(validator[0]) - # Using a python slice to get all items after the first to build function args - args = validator[1:] - # Pass the request as first arg by default - result_validations.append(func(self.request, *args)) else: - func = get_callable(validator) - result_validations.append(func(self.request)) # pragma: no cover - return all(result_validations) + func_or_path, args = validator, [] + + func = get_callable(func_or_path) + if not func(self.request, *args): + return False + return True def _has_attr(self, item_dict, attr): """ diff --git a/menu_generator/tests/test_menu.py b/menu_generator/tests/test_menu.py index bbfb897..2ccc957 100755 --- a/menu_generator/tests/test_menu.py +++ b/menu_generator/tests/test_menu.py @@ -362,3 +362,11 @@ def test_subsequent_requests(self): nav2 = get_menu(ctx, 'NAV_MENU') # Both menus should be equal self.assertEqual(nav1, nav2) + + def test_menu_multiple_validators_skip_on_false(self): + menu_dict = { + "validators": ["menu_generator.validators.is_staff", "this-is-never-evaluated"], + } + self.request.user = TestUser(authenticated=True) + self.menu.save_user_state(self.request) + self.assertFalse(self.menu._is_validated(menu_dict))