def resolve(self, context, source=None):
        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']

        # Get sources: view name, view objects
        current_view = resolve(current_path).view_name
        resolved_navigation_object_list = []

        result = []

        if source:
            resolved_navigation_object_list = [source]
        else:
            navigation_object_list = context.get(
                'navigation_object_list', ('object',)
            )

            # Multiple objects
            for navigation_object in navigation_object_list:
                try:
                    resolved_navigation_object_list.append(
                        Variable(navigation_object).resolve(context)
                    )
                except VariableDoesNotExist:
                    pass

        for resolved_navigation_object in resolved_navigation_object_list:
            resolved_links = []

            for bound_source, links in self.bound_links.iteritems():
                try:
                    if inspect.isclass(bound_source) and type(resolved_navigation_object) == bound_source:
                        for link in links:
                            resolved_link = link.resolve(
                                context=context,
                                resolved_object=resolved_navigation_object
                            )
                            if resolved_link:
                                resolved_links.append(resolved_link)
                        # No need for further content object match testing
                        break
                except __HOLE__:
                    # When source is a dictionary
                    pass

            if resolved_links:
                result.append(resolved_links)

        resolved_links = []
        # View links
        for link in self.bound_links.get(current_view, []):
            resolved_link = link.resolve(context)
            if resolved_link:
                resolved_links.append(resolved_link)

        if resolved_links:
            result.append(resolved_links)

        resolved_links = []

        # Main menu links
        for link in self.bound_links.get(None, []):
            resolved_link = link.resolve(context)
            if resolved_link:
                resolved_links.append(resolved_link)

        if resolved_links:
            result.append(resolved_links)

        if result:
            unbound_links = []
            unbound_links.extend(self.unbound_links.get(source, ()))
            unbound_links.extend(self.unbound_links.get(current_view, ()))

            for resolved_link in result[0]:
                if resolved_link.link in unbound_links:
                    result[0].remove(resolved_link)

            # Sort links by position value passed during bind
            result[0] = sorted(
                result[0], key=lambda item: self.link_positions.get(item.link)
            )

        return result
dataset/ETHPy150Open mayan-edms/mayan-edms/mayan/apps/navigation/classes.py/Menu.resolve