From a08859007350fdf088393285639c42e03a37d28a Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sun, 8 Jan 2012 07:38:12 -0400 Subject: [PATCH] Process horizontal list links with the same logic as all other links --- apps/navigation/widgets.py | 47 ++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/apps/navigation/widgets.py b/apps/navigation/widgets.py index 57934c7909..78c6923e43 100644 --- a/apps/navigation/widgets.py +++ b/apps/navigation/widgets.py @@ -1,29 +1,52 @@ +from __future__ import absolute_import + +import urlparse + from django.utils.safestring import mark_safe from django.conf import settings from django.utils.translation import ugettext_lazy as _ from django.core.urlresolvers import reverse from django.template.defaultfilters import capfirst from django.core.exceptions import PermissionDenied - +from django.template import RequestContext +from django.template import (TemplateSyntaxError, Library, + VariableDoesNotExist, Node, Variable) + from permissions.models import Permission +from .templatetags.navigation_tags import resolve_links, _get_object_navigation_links +from .utils import resolve_to_name + def button_navigation_widget(request, link): if 'permissions' in link: try: Permission.objects.check_permissions(request.user, link['permissions']) - return render_widget(link) + return render_widget(request, link) except PermissionDenied: return u'' else: - return render_widget(link) - + return render_widget(request, link) -def render_widget(link): - return mark_safe(u'' % { - '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'), - }) +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'' % { + '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''