Example #1
0
def render_widget(request, link):
    context = RequestContext(request)

    request = Variable('request').resolve(context)
    current_path = request.META['PATH_INFO']
    current_view = resolve_to_name(current_path)

    query_string = urlparse.urlparse(
        request.get_full_path()).query or urlparse.urlparse(
            request.META.get('HTTP_REFERER', u'/')).query
    parsed_query_string = urlparse.parse_qs(query_string)

    links = resolve_links(context, [link], current_view, current_path,
                          parsed_query_string)
    if links:
        link = links[0]
        return mark_safe(
            u'<a style="text-decoration:none; margin-right: 10px;" href="%(url)s"><button style="vertical-align: top; padding: 1px; width: 110px; height: 100px; margin: 10px;"><img src="%(static_url)simages/icons/%(icon)s" alt="%(image_alt)s" /><p style="margin: 0px 0px 0px 0px;">%(string)s</p></button></a>'
            % {
                'url':
                reverse(link['view']) if 'view' in link else link['url'],
                'icon': link.get('icon', 'link_button.png'),
                'static_url': settings.STATIC_URL,
                'string': capfirst(link['text']),
                'image_alt': _(u'icon'),
            })
    else:
        return u''
Example #2
0
 def render(self, context):
     request = Variable("request").resolve(context)
     for tab in self.tabs:
         tab.is_active = request.get_full_path().startswith(tab.url)
         tab.visible = tab.has_permission(request.user)                    
     
     context[self.varname] = self.tabs
     return ""
Example #3
0
 def render(self, context):
     request = Variable("request").resolve(context)
     domain = Variable("domain").resolve(context)
     
     tabs = [Tab(*args, domain=domain) for args in settings.TABS]
     for tab in tabs:
         tab.is_active = request.get_full_path().startswith(tab.url)
         tab.visible = tab.has_permission(request)
     context[self.varname] = tabs
     return ""
Example #4
0
    def render(self, context):
        # try to find a request variable, but don't blow up entirely if we don't find it
        # (this no blow up property is mostly used during testing)
        try:
            request = Variable("request").resolve(context)
        except Exception as e:
            return ""

        for tab in self.tabs:
            if tab.url != '/':
                # Keep tab active if the url is a sub-directoy of the current tab
                tab.is_active = request.get_full_path().startswith(tab.url)
            else:
                # Make a small exception for the server root since all
                # urls are below the server root
                tab.is_active = tab.url == request.get_full_path()                
            tab.visible = tab.has_permission(request.user)                    
        
        context[self.varname] = self.tabs
        return ""
Example #5
0
    def render(self, context):
        # try to find a request variable, but don't blow up entirely if we don't find it
        # (this no blow up property is mostly used during testing)
        try:
            request = Variable("request").resolve(context)
        except Exception as e:
            return ""

        for tab in self.tabs:
            tab.is_active = tab.url == request.get_full_path()
        context[self.varname] = self.tabs
        return ""
    def render(self, context):
        # try to find a request variable, but don't blow up entirely if we don't find it
        # (this no blow up property is mostly used during testing)
        try:
            request = Variable("request").resolve(context)
        except Exception:
            return ""

        for tab in self.tabs:
            tab.is_active = tab.url == request.get_full_path()
        context[self.varname] = self.tabs
        return ""
Example #7
0
def _get_object_navigation_links(context, menu_name=None, links_dict=object_navigation):
    request = Variable('request').resolve(context)
    current_path = request.META['PATH_INFO']
    current_view = resolve_to_name(current_path)
    context_links = []

    # Don't fudge with the original global dictionary
    links_dict = links_dict.copy()

    # Preserve unicode data in URL query
    previous_path = smart_unicode(urllib.unquote_plus(smart_str(request.get_full_path()) or smart_str(request.META.get('HTTP_REFERER', u'/'))))
    query_string = urlparse.urlparse(previous_path).query
    parsed_query_string = urlparse.parse_qs(query_string)

    try:
        """
        Override the navigation links dictionary with the provided
        link list
        """
        navigation_object_links = Variable('overrided_object_links').resolve(context)
        if navigation_object_links:
            return [link for link in resolve_links(context, navigation_object_links, current_view, current_path, parsed_query_string)]
    except VariableDoesNotExist:
        pass

    try:
        """
        Check for and inject a temporary navigation dictionary
        """
        temp_navigation_links = Variable('temporary_navigation_links').resolve(context)
        if temp_navigation_links:
            links_dict.update(temp_navigation_links)
    except VariableDoesNotExist:
        pass

    try:
        links = links_dict[menu_name][current_view]['links']
        for link in resolve_links(context, links, current_view, current_path, parsed_query_string):
            context_links.append(link)
    except KeyError:
        pass

    obj, object_name = get_navigation_object(context)

    try:
        links = links_dict[menu_name][type(obj)]['links']
        for link in resolve_links(context, links, current_view, current_path, parsed_query_string):
            context_links.append(link)
    except KeyError:
        pass

    return context_links
Example #8
0
def _get_object_navigation_links(context,
                                 menu_name=None,
                                 links_dict=object_navigation):
    request = Variable('request').resolve(context)
    current_path = request.META['PATH_INFO']
    current_view = resolve_to_name(current_path)
    context_links = []

    # Don't fudge with the original global dictionary
    links_dict = links_dict.copy()

    # Preserve unicode data in URL query
    previous_path = smart_unicode(
        urllib.unquote_plus(
            smart_str(request.get_full_path())
            or smart_str(request.META.get('HTTP_REFERER', u'/'))))
    query_string = urlparse.urlparse(previous_path).query
    parsed_query_string = urlparse.parse_qs(query_string)

    try:
        """
        Check for and inject a temporary navigation dictionary
        """
        temp_navigation_links = Variable('temporary_navigation_links').resolve(
            context)
    except VariableDoesNotExist:
        pass
    else:
        if temp_navigation_links:
            links_dict.update(temp_navigation_links)

    # Match view links
    try:
        links = links_dict[menu_name][current_view]['links']
        for link in resolve_links(context, links, current_view, current_path,
                                  parsed_query_string):
            context_links.append(link)
    except KeyError:
        pass

    obj, object_name = get_navigation_object(context)

    # Match context navigation object links
    for source, data in links_dict[menu_name].items():
        if inspect.isclass(source) and isinstance(obj, source):
            for link in resolve_links(context, data['links'], current_view,
                                      current_path, parsed_query_string):
                context_links.append(link)
            break

    return context_links
Example #9
0
def _get_object_navigation_links(context, menu_name=None, links_dict=object_navigation):
    request = Variable('request').resolve(context)
    current_path = request.META['PATH_INFO']
    current_view = resolve_to_name(current_path)
    context_links = []

    query_string = urlparse.urlparse(request.get_full_path()).query or urlparse.urlparse(request.META.get('HTTP_REFERER', u'/')).query
    parsed_query_string = urlparse.parse_qs(query_string)

    try:
        """
        Override the navigation links dictionary with the provided
        link list
        """
        navigation_object_links = Variable('overrided_object_links').resolve(context)
        if navigation_object_links:
            return [link for link in resolve_links(context, navigation_object_links, current_view, current_path, parsed_query_string)]
    except VariableDoesNotExist:
        pass

    try:
        object_name = Variable('navigation_object_name').resolve(context)
    except VariableDoesNotExist:
        object_name = 'object'

    try:
        obj = Variable(object_name).resolve(context)
    except VariableDoesNotExist:
        obj = None

    try:
        links = links_dict[menu_name][current_view]['links']
        for link in resolve_links(context, links, current_view, current_path, parsed_query_string):
            context_links.append(link)
    except KeyError:
        pass

    try:
        links = links_dict[menu_name][type(obj)]['links']
        for link in resolve_links(context, links, current_view, current_path, parsed_query_string):
            context_links.append(link)
    except KeyError:
        pass

    return context_links
Example #10
0
def _get_object_navigation_links(context, menu_name=None, links_dict=object_navigation):
    request = Variable('request').resolve(context)
    current_path = request.META['PATH_INFO']
    current_view = resolve_to_name(current_path)
    context_links = []

    query_string = urlparse.urlparse(request.get_full_path()).query or urlparse.urlparse(request.META.get('HTTP_REFERER', u'/')).query
    parsed_query_string = urlparse.parse_qs(query_string)

    try:
        """
        Override the navigation links dictionary with the provided
        link list
        """
        navigation_object_links = Variable('navigation_object_links').resolve(context)
        if navigation_object_links:
            return [link for link in resolve_links(context, navigation_object_links, current_view, current_path, parsed_query_string)]
    except VariableDoesNotExist:
        pass

    try:
        object_name = Variable('navigation_object_name').resolve(context)
    except VariableDoesNotExist:
        object_name = 'object'

    try:
        obj = Variable(object_name).resolve(context)
    except VariableDoesNotExist:
        obj = None

    try:
        links = links_dict[menu_name][current_view]['links']
        for link in resolve_links(context, links, current_view, current_path, parsed_query_string):
            context_links.append(link)
    except KeyError:
        pass

    try:
        links = links_dict[menu_name][type(obj)]['links']
        for link in resolve_links(context, links, current_view, current_path, parsed_query_string):
            context_links.append(link)
    except KeyError:
        pass

    return context_links
Example #11
0
def _get_object_navigation_links(context, menu_name=None, links_dict=object_navigation):
    request = Variable('request').resolve(context)
    current_path = request.META['PATH_INFO']
    current_view = resolve_to_name(current_path)
    context_links = []

    # Don't fudge with the original global dictionary
    links_dict = links_dict.copy()

    # Preserve unicode data in URL query
    previous_path = smart_unicode(urllib.unquote_plus(smart_str(request.get_full_path()) or smart_str(request.META.get('HTTP_REFERER', u'/'))))
    query_string = urlparse.urlparse(previous_path).query
    parsed_query_string = urlparse.parse_qs(query_string)

    try:
        """
        Check for and inject a temporary navigation dictionary
        """
        temp_navigation_links = Variable('temporary_navigation_links').resolve(context)
    except VariableDoesNotExist:
        pass
    else:
        if temp_navigation_links:
            links_dict.update(temp_navigation_links)

    # Match view links
    try:
        links = links_dict[menu_name][current_view]['links']
        for link in resolve_links(context, links, current_view, current_path, parsed_query_string):
            context_links.append(link)
    except KeyError:
        pass

    obj, object_name = get_navigation_object(context)

    # Match context navigation object links
    for source, data in links_dict[menu_name].items():
        if inspect.isclass(source) and isinstance(obj, source):
            for link in resolve_links(context, data['links'], current_view, current_path, parsed_query_string):
                context_links.append(link)
            break

    return context_links
Example #12
0
def render_widget(request, link):
    context = RequestContext(request)

    request = Variable('request').resolve(context)
    current_path = request.META['PATH_INFO']
    current_view = resolve_to_name(current_path)

    query_string = urlparse.urlparse(request.get_full_path()).query or urlparse.urlparse(request.META.get('HTTP_REFERER', u'/')).query
    parsed_query_string = urlparse.parse_qs(query_string)

    links = resolve_links(context, [link], current_view, current_path, parsed_query_string)
    if links:
        link = links[0]
        return mark_safe(u'<a style="text-decoration:none; margin-right: 10px;" href="%(url)s"><button style="vertical-align: top; padding: 1px; width: 110px; height: 100px; margin: 10px;"><img src="%(static_url)simages/icons/%(icon)s" alt="%(image_alt)s" /><p style="margin: 0px 0px 0px 0px;">%(string)s</p></button></a>' % {
            'url': reverse(link['view']) if 'view' in link else link['url'],
            'icon': link.get('icon', 'link_button.png'),
            'static_url': settings.STATIC_URL,
            'string': capfirst(link['text']),
            'image_alt': _(u'icon'),
        })
    else:
        return u''
Example #13
0
    def resolve(self, context, resolved_object=None):
        AccessControlList = apps.get_model(
            app_label='acls', model_name='AccessControlList'
        )

        # Try to get the request object the faster way and fallback to the
        # slower method.
        try:
            request = context.request
        except AttributeError:
            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 has it
        # too
        if self.permissions:
            if resolved_object:
                try:
                    AccessControlList.objects.check_access(
                        permissions=self.permissions, user=request.user,
                        obj=resolved_object, related=self.permissions_related
                    )
                except PermissionDenied:
                    return None
            else:
                try:
                    Permission.check_permissions(
                        requester=request.user, permissions=self.permissions
                    )
                except PermissionDenied:
                    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)

        if self.view:
            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.items()}

            # 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
                )
        elif self.url:
            resolved_link.url = self.url

        # 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
            parsed_url = furl(
                force_str(
                    request.get_full_path() or request.META.get(
                        'HTTP_REFERER', resolve_url(settings.LOGIN_REDIRECT_URL)
                    )
                )
            )

            for key in self.remove_from_query:
                try:
                    parsed_url.query.remove(key)
                except KeyError:
                    pass

            # Use the link's URL but with the previous URL querystring
            new_url = furl(resolved_link.url)
            new_url.args = parsed_url.querystr
            resolved_link.url = new_url.url

        resolved_link.context = context
        return resolved_link
Example #14
0
    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 KeyError:
                    pass

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

        return resolved_link
Example #15
0
 def render(self, context):
     request = Variable("request").resolve(context)
     for tab in self.tabs:
         tab.is_active = tab.url == request.get_full_path()
     context[self.varname] = self.tabs
     return ""
Example #16
0
def _get_object_navigation_links(context,
                                 menu_name=None,
                                 links_dict=object_navigation):
    request = Variable('request').resolve(context)
    current_path = request.META['PATH_INFO']
    current_view = resolve_to_name(current_path)
    context_links = []

    # Don't fudge with the original global dictionary
    links_dict = links_dict.copy()

    # Preserve unicode data in URL query
    previous_path = smart_unicode(
        urllib.unquote_plus(
            smart_str(request.get_full_path())
            or smart_str(request.META.get('HTTP_REFERER', u'/'))))
    query_string = urlparse.urlparse(previous_path).query
    parsed_query_string = urlparse.parse_qs(query_string)

    try:
        """
        Override the navigation links dictionary with the provided
        link list
        """
        navigation_object_links = Variable('overrided_object_links').resolve(
            context)
        if navigation_object_links:
            return [
                link for link in
                resolve_links(context, navigation_object_links, current_view,
                              current_path, parsed_query_string)
            ]
    except VariableDoesNotExist:
        pass

    try:
        """
        Check for and inject a temporary navigation dictionary
        """
        temp_navigation_links = Variable('temporary_navigation_links').resolve(
            context)
        if temp_navigation_links:
            links_dict.update(temp_navigation_links)
    except VariableDoesNotExist:
        pass

    try:
        links = links_dict[menu_name][current_view]['links']
        for link in resolve_links(context, links, current_view, current_path,
                                  parsed_query_string):
            context_links.append(link)
    except KeyError:
        pass

    obj, object_name = get_navigation_object(context)

    try:
        links = links_dict[menu_name][type(obj)]['links']
        for link in resolve_links(context, links, current_view, current_path,
                                  parsed_query_string):
            context_links.append(link)
    except KeyError:
        pass

    return context_links
Example #17
0
    def resolve(self, context, resolved_object=None):
        AccessControlList = apps.get_model(app_label='acls',
                                           model_name='AccessControlList')

        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 has it
        # too
        if self.permissions:
            if resolved_object:
                try:
                    AccessControlList.objects.check_access(
                        permissions=self.permissions,
                        user=request.user,
                        obj=resolved_object,
                        related=self.permissions_related)
                except PermissionDenied:
                    return None
            else:
                try:
                    Permission.check_permissions(requester=request.user,
                                                 permissions=self.permissions)
                except PermissionDenied:
                    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)

        if self.view:
            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.items()}

            # 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)
        elif self.url:
            resolved_link.url = self.url

        # 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
            parsed_url = furl(
                force_str(request.get_full_path() or request.META.get(
                    'HTTP_REFERER', resolve_url(settings.LOGIN_REDIRECT_URL))))

            for key in self.remove_from_query:
                try:
                    parsed_url.query.remove(key)
                except KeyError:
                    pass

            # Use the link's URL but with the previous URL querystring
            new_url = furl(resolved_link.url)
            new_url.args = parsed_url.querystr
            resolved_link.url = new_url.url

        resolved_link.context = context
        return resolved_link
Example #18
0
 def render(self, context):
     request = Variable("request").resolve(context)
     for tab in self.tabs:
         tab.is_active = tab.url == request.get_full_path()
     context[self.varname] = self.tabs
     return ""
Example #19
0
    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 KeyError:
                    pass

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

        return resolved_link