diff options
author | Dan McGee <dan@archlinux.org> | 2012-05-01 17:13:33 -0500 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2012-05-01 17:13:33 -0500 |
commit | b59e79f3878d59b83c6867eb5c6196f8f003dcd9 (patch) | |
tree | 5168439fa4620d6e5ec60ca03a0606a9a6ce4549 /packages | |
parent | b06efbe343eb6cd5cafe4c121d53a538302f9156 (diff) |
Opensearch enhancements
* Add a 64x64 icon as indicated in the Opensearch specification.
* Add suggestions capability and a new view providing suggestions based
on package name starting with the typed value.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'packages')
-rw-r--r-- | packages/views/__init__.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/packages/views/__init__.py b/packages/views/__init__.py index 6a9c5275..21d17470 100644 --- a/packages/views/__init__.py +++ b/packages/views/__init__.py @@ -7,7 +7,7 @@ from django.contrib.auth.models import User from django.http import HttpResponse, Http404 from django.shortcuts import get_object_or_404, redirect from django.utils import simplejson -from django.views.decorators.http import require_POST +from django.views.decorators.http import require_GET, require_POST from django.views.decorators.vary import vary_on_headers from django.views.generic.simple import direct_to_template @@ -24,6 +24,7 @@ from .search import search, search_json from .signoff import signoffs, signoff_package, signoff_options, signoffs_json +@require_GET def opensearch(request): if request.is_secure(): domain = "https://%s" % request.META['HTTP_HOST'] @@ -34,6 +35,21 @@ def opensearch(request): {'domain': domain}, mimetype='application/opensearchdescription+xml') + +@require_GET +def opensearch_suggest(request): + search_term = request.GET.get('q', '') + if search_term == '': + return HttpResponse('', mimetype='application/x-suggestions+json') + + names = Package.objects.filter( + pkgname__startswith=search_term).values_list( + 'pkgname', flat=True).order_by('pkgname').distinct()[:10] + results = [search_term, list(names)] + to_json = simplejson.dumps(results, ensure_ascii=False) + return HttpResponse(to_json, mimetype='application/x-suggestions+json') + + @permission_required('main.change_package') @require_POST def update(request): |