summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorIsmael Carnales <icarnales@gmail.com>2009-10-31 16:12:17 -0200
committerIsmael Carnales <icarnales@gmail.com>2009-11-09 22:24:52 -0200
commit150dfd72982da506dde445e0d88ac4d270f3003e (patch)
tree37704f334bbccbdb0d5a7030e148f189b72e40bd /packages
parent1c22bbc3f74f90a136b899c22bba327161c14763 (diff)
added missing packages views code from archweb_pub
Diffstat (limited to 'packages')
-rw-r--r--packages/views.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/packages/views.py b/packages/views.py
index 451b2bc5..8e2d1c74 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')