diff options
author | Ismael Carnales <icarnales@gmail.com> | 2009-10-31 19:12:17 +0100 |
---|---|---|
committer | Ismael Carnales <icarnales@gmail.com> | 2009-11-10 01:24:52 +0100 |
commit | 150dfd72982da506dde445e0d88ac4d270f3003e (patch) | |
tree | 37704f334bbccbdb0d5a7030e148f189b72e40bd /packages | |
parent | 1c22bbc3f74f90a136b899c22bba327161c14763 (diff) | |
download | archweb-150dfd72982da506dde445e0d88ac4d270f3003e.tar.gz archweb-150dfd72982da506dde445e0d88ac4d270f3003e.tar.xz |
added missing packages views code from archweb_pub
Diffstat (limited to 'packages')
-rw-r--r-- | packages/views.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/packages/views.py b/packages/views.py index 451b2bc..8e2d1c7 100644 --- a/packages/views.py +++ b/packages/views.py @@ -100,6 +100,7 @@ class PackageSearchForm(forms.Form): self.fields['arch'].choices = self.fields[ 'arch'].widget.choices = [('', 'All')] + make_choice( [arch.name for arch in Arch.objects.all()]) + self.fields['q'].widget.attrs.update({"size": "30"}) self.fields['maintainer'].choices = self.fields[ 'maintainer'].widget.choices = [ ('', 'All'), ('orphan', 'Orphan')] + make_choice( @@ -111,7 +112,14 @@ def search(request, page=None): packages = Package.objects.all() if request.GET: - current_query += urllib.urlencode(request.GET) + # urlencode can't handle unicode. One fix for this is to call: + # urllib.urlencode(request.GET, doseq), which has a side effect of + # converting unicode to ascii, and replacing unknown characters with ?. + # Using UTF8 seems to work just as well without data loss. + encoded = {} + for key in request.GET: + encoded[key] = request.GET[key].encode('UTF8') + current_query += urllib.urlencode(encoded) form = PackageSearchForm(data=request.GET) if form.is_valid(): if form.cleaned_data['repo']: @@ -147,9 +155,13 @@ def search(request, page=None): if len(packages) == 1: return HttpResponseRedirect(packages[0].get_absolute_url()) - if 'sort' in request.GET: + allowed_sort = ["arch", "repo", "pkgname", "maintainer", "last_update"] + allowed_sort += ["-" + s for s in allowed_sort] + sort = request.GET.get('sort', None) + if sort in allowed_sort: packages = packages.order_by( request.GET['sort'], 'repo', 'arch', 'pkgname') + page_dict['sort'] = sort else: packages = packages.order_by('repo', 'arch', '-last_update', 'pkgname') |