def resolve(self, context, resolved_object=None):
        request = Variable('request').resolve(context)
        current_path = request.META['PATH_INFO']
        current_view = resolve(current_path).view_name

        # ACL is tested agains the resolved_object or just {{ object }} if not
        if not resolved_object:
            try:
                resolved_object = Variable('object').resolve(context=context)
            except VariableDoesNotExist:
                pass

        # If this link has a required permission check that the user have it
        # too
        if self.permissions:
            try:
                Permission.check_permissions(request.user, self.permissions)
            except PermissionDenied:
                # If the user doesn't have the permission, and we are passed
                # an instance, check to see if the user has at least ACL
                # access to the instance.
                if resolved_object:
                    try:
                        AccessControlList.objects.check_access(
                            self.permissions, request.user, resolved_object
                        )
                    except PermissionDenied:
                        return None
                else:
                    return 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

        resolved_link = ResolvedLink(current_view=current_view, link=self)

        view_name = Variable('"{}"'.format(self.view))
        if isinstance(self.args, list) or isinstance(self.args, tuple):
            # TODO: Don't check for instance check for iterable in try/except
            # block. This update required changing all 'args' argument in
            # links.py files to be iterables and not just strings.
            args = [Variable(arg) for arg in self.args]
        else:
            args = [Variable(self.args)]

        # If we were passed an instance of the view context object we are
        # resolving, inject it into the context. This help resolve links for
        # object lists.
        if resolved_object:
            context['resolved_object'] = resolved_object

        try:
            kwargs = self.kwargs(context)
        except TypeError:
            # Is not a callable
            kwargs = self.kwargs

        kwargs = {key: Variable(value) for key, value in kwargs.iteritems()}

        # Use Django's exact {% url %} code to resolve the link
        node = URLNode(
            view_name=view_name, args=args, kwargs=kwargs, asvar=None
        )

        try:
            resolved_link.url = node.render(context)
        except Exception as exception:
            logger.error(
                'Error resolving link "%s" URL; %s', self.text, exception
            )

        # This is for links that should be displayed but that are not clickable
        if self.conditional_disable:
            resolved_link.disabled = self.conditional_disable(context)
        else:
            resolved_link.disabled = False

        # Lets a new link keep the same URL query string of the current URL
        if self.keep_query:
            # Sometimes we are required to remove a key from the URL QS
            previous_path = smart_unicode(
                urllib.unquote_plus(
                    smart_str(
                        request.get_full_path()
                    ) or smart_str(
                        request.META.get(
                            'HTTP_REFERER',
                            reverse(settings.LOGIN_REDIRECT_URL)
                        )
                    )
                )
            )
            query_string = urlparse.urlparse(previous_path).query
            parsed_query_string = urlparse.parse_qs(query_string)

            for key in self.remove_from_query:
                try:
                    del parsed_query_string[key]
                except __HOLE__:
                    pass

            resolved_link.url = '%s?%s' % (
                urlquote(resolved_link.url),
                urlencode(parsed_query_string, doseq=True)
            )

        return resolved_link
dataset/ETHPy150Open mayan-edms/mayan-edms/mayan/apps/navigation/classes.py/Link.resolve