From 21a8fec980eb0613d3cce8aae7d6bfe6680c038a Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Wed, 12 Oct 2011 08:54:51 -0500 Subject: Package search and sort code cleanup Move initializations closer to where they are actually needed, and remove the sorting on multiple columns when a sort field is passed in. We don't do this for the default sort, so let's not do it here either. Signed-off-by: Dan McGee --- packages/views.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/views.py b/packages/views.py index a740e68..dab0691 100644 --- a/packages/views.py +++ b/packages/views.py @@ -293,24 +293,22 @@ def search(request, page=None): else: form = PackageSearchForm() - current_query = request.GET.urlencode() - page_dict = { - 'search_form': form, - 'current_query': current_query - } allowed_sort = ["arch", "repo", "pkgname", "pkgbase", "compressed_size", "installed_size", "build_date", "last_update", "flag_date"] allowed_sort += ["-" + s for s in allowed_sort] sort = request.GET.get('sort', None) - # TODO: sorting by multiple fields makes using a DB index much harder if sort in allowed_sort: - packages = packages.order_by( - request.GET['sort'], 'repo', 'arch', 'pkgname') + packages = packages.order_by(sort) page_dict['sort'] = sort else: packages = packages.order_by('pkgname') + current_query = request.GET.urlencode() + page_dict = { + 'search_form': form, + 'current_query': current_query + } return list_detail.object_list(request, packages, template_name="packages/search.html", page=page, -- cgit v1.2.3-24-g4f1b