diff --git a/mayan/apps/navigation/classes.py b/mayan/apps/navigation/classes.py index 474aa13284..a749e75c5a 100644 --- a/mayan/apps/navigation/classes.py +++ b/mayan/apps/navigation/classes.py @@ -159,10 +159,15 @@ class Menu(object): try: request = context.request except AttributeError: - # There is no request variable, most probable a 500 in a test view - # Don't return any resolved links then. - logger.warning('No request variable, aborting menu resolution') - return () + # Simple request extraction failed. Might not be a view context. + # Try alternate method. + try: + request = Variable('request').resolve(context) + except VariableDoesNotExist: + # There is no request variable, most probable a 500 in a test + # view. Don't return any resolved links then. + logger.warning('No request variable, aborting menu resolution') + return () current_path = request.META['PATH_INFO'] @@ -296,13 +301,6 @@ class Link(object): self.url = url def resolve(self, context, resolved_object=None): - # Check to see if link has conditional display function and only - # display it if the result of the conditional display function is - # True - if self.condition: - if not self.condition(context): - return None - AccessControlList = apps.get_model( app_label='acls', model_name='AccessControlList' ) @@ -380,6 +378,13 @@ class Link(object): elif self.url: resolved_link.url = self.url + # Check to see if link has conditional display function and only + # display it if the result of the conditional display function is + # True + if self.condition: + if not self.condition(context): + return None + # This is for links that should be displayed but that are not clickable if self.conditional_disable: resolved_link.disabled = self.conditional_disable(context) diff --git a/mayan/apps/navigation/tests/test_classes.py b/mayan/apps/navigation/tests/test_classes.py index 96661b8807..f6e13bd772 100644 --- a/mayan/apps/navigation/tests/test_classes.py +++ b/mayan/apps/navigation/tests/test_classes.py @@ -181,7 +181,6 @@ class MenuClassTestCase(GenericViewTestCase): response = self.get(TEST_VIEW_NAME) context = Context({'request': response.wsgi_request}) - self.assertEqual( self.menu.resolve(context=context)[0][0].link, self.link ) diff --git a/mayan/apps/tags/tests/test_actions.py b/mayan/apps/tags/tests/test_actions.py index 80630f4580..a4fdd883b6 100644 --- a/mayan/apps/tags/tests/test_actions.py +++ b/mayan/apps/tags/tests/test_actions.py @@ -17,7 +17,7 @@ class TagActionTestCase(ActionTestCase): def test_tag_attach_action(self): action = AttachTagAction(form_data={'tags': Tag.objects.all()}) - action.execute(context={'entry_log': self.entry_log}) + action.execute(context={'document': self.document}) self.assertEqual(self.tag.documents.count(), 1) self.assertEqual(list(self.tag.documents.all()), [self.document]) @@ -26,6 +26,6 @@ class TagActionTestCase(ActionTestCase): self.tag.attach_to(document=self.document) action = RemoveTagAction(form_data={'tags': Tag.objects.all()}) - action.execute(context={'entry_log': self.entry_log}) + action.execute(context={'document': self.document}) self.assertEqual(self.tag.documents.count(), 0)