Don't parse the URL if it's not going to be used. Convert tools to CBV.

This commit is contained in:
Roberto Rosario
2015-04-07 01:11:33 -04:00
parent c59695e197
commit 735cd64db2
3 changed files with 16 additions and 17 deletions

View File

@@ -4,7 +4,7 @@ from django.conf.urls import patterns, url
from django.contrib.staticfiles.templatetags.staticfiles import static from django.contrib.staticfiles.templatetags.staticfiles import static
from django.views.generic import RedirectView from django.views.generic import RedirectView
from .views import AboutView from .views import AboutView, ToolsListView
urlpatterns = patterns('common.views', urlpatterns = patterns('common.views',
@@ -22,7 +22,7 @@ urlpatterns = patterns('common.views',
url(r'^user/locale/edit/$', 'current_user_locale_profile_edit', (), name='current_user_locale_profile_edit'), url(r'^user/locale/edit/$', 'current_user_locale_profile_edit', (), name='current_user_locale_profile_edit'),
url(r'^setup/$', 'setup_list', (), 'setup_list'), url(r'^setup/$', 'setup_list', (), 'setup_list'),
url(r'^tools/$', 'tools_list', (), 'tools_list'), url(r'^tools/$', ToolsListView.as_view(), name='tools_list'),
) )
urlpatterns += patterns('', urlpatterns += patterns('',

View File

@@ -429,14 +429,16 @@ def setup_list(request):
context_instance=RequestContext(request)) context_instance=RequestContext(request))
def tools_list(request): class ToolsListView(TemplateView):
context = { template_name = 'appearance/generic_list_horizontal.html'
'object_navigation_links': menu_tools.resolve(context=RequestContext(request)),
'title': _('Tools'),
}
return render_to_response('appearance/generic_list_horizontal.html', context, def get_context_data(self, **kwargs):
context_instance=RequestContext(request)) data = super(ToolsListView, self).get_context_data(**kwargs)
data.update({
'object_navigation_links': menu_tools.resolve(context=RequestContext(self.request)),
'title': _('Tools'),
})
return data
def home(request): def home(request):

View File

@@ -92,9 +92,7 @@ class Menu(object):
resolved_link = link.resolve(context=context, resolved_object=resolved_navigation_object) resolved_link = link.resolve(context=context, resolved_object=resolved_navigation_object)
if resolved_link: if resolved_link:
result.append(resolved_link) result.append(resolved_link)
#break # No need for further content object match testing break # No need for further content object match testing
# TODO: profile this
except TypeError: except TypeError:
# When source is a dictionary # When source is a dictionary
pass pass
@@ -138,11 +136,6 @@ class Link(object):
current_path = request.META['PATH_INFO'] current_path = request.META['PATH_INFO']
current_view = resolve(current_path).view_name current_view = resolve(current_path).view_name
# 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', reverse(settings.LOGIN_REDIRECT_URL)))))
query_string = urlparse.urlparse(previous_path).query
parsed_query_string = urlparse.parse_qs(query_string)
# If this link has a required permission check that the user have it # If this link has a required permission check that the user have it
# too # too
if self.permissions: if self.permissions:
@@ -201,6 +194,10 @@ class Link(object):
# Lets a new link keep the same URL query string of the current URL # Lets a new link keep the same URL query string of the current URL
if self.keep_query: if self.keep_query:
# Sometimes we are required to remove a key from the URL QS # 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: for key in self.remove_from_query:
try: try:
del parsed_query_string[key] del parsed_query_string[key]