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>
This commit is contained in:
parent
b06efbe343
commit
b59e79f387
@ -7,7 +7,7 @@
|
||||
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 .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):
|
||||
|
BIN
sitestatic/logos/icon-transparent-64x64.png
Normal file
BIN
sitestatic/logos/icon-transparent-64x64.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
@ -1,13 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
{% load static from staticfiles %}<?xml version="1.0" encoding="UTF-8"?>
|
||||
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
|
||||
<ShortName>Arch Linux Packages</ShortName>
|
||||
<Description>Search the Arch Linux package repositories.</Description>
|
||||
<ShortName>Arch Packages</ShortName>
|
||||
<LongName>Arch Linux Package Repository Search</LongName>
|
||||
<Description>Search the Arch Linux package repositories by keyword in package names and descriptions.</Description>
|
||||
<Tags>linux archlinux package software</Tags>
|
||||
<Image height="16" width="16" type="image/x-icon">{{domain}}/static/favicon.ico</Image>
|
||||
<Image height="16" width="16" type="image/x-icon">{{ domain }}{% static "favicon.ico" %}</Image>
|
||||
<Image height="64" width="64" type="image/png">{{ domain }}{% static "logos/icon-transparent-64x64.png" %}</Image>
|
||||
<Language>en-us</Language>
|
||||
<InputEncoding>UTF-8</InputEncoding>
|
||||
<OutputEncoding>UTF-8</OutputEncoding>
|
||||
<Query role="example" searchTerms="initscripts"/>
|
||||
<Url type="text/html" template="{{domain}}/packages/?q={searchTerms}"/>
|
||||
<Url rel="self" type="application/opensearchdescription+xml" template="{{domain}}/opensearch/packages/"/>
|
||||
<Url type="text/html" template="{{ domain }}/packages/?q={searchTerms}"/>
|
||||
<Url rel="suggestions" type="application/x-suggestions+json"
|
||||
template="{{ domain }}/opensearch/packages/suggest?q={searchTerms}"/>
|
||||
<Url rel="self" type="application/opensearchdescription+xml"
|
||||
template="{{ domain }}/opensearch/packages/"/>
|
||||
</OpenSearchDescription>
|
||||
|
2
urls.py
2
urls.py
@ -91,6 +91,8 @@
|
||||
(r'^visualize/', include('visualize.urls')),
|
||||
(r'^opensearch/packages/$', 'packages.views.opensearch',
|
||||
{}, 'opensearch-packages'),
|
||||
(r'^opensearch/packages/suggest$', 'packages.views.opensearch_suggest',
|
||||
{}, 'opensearch-packages-suggest'),
|
||||
(r'^todolists/$','todolists.views.public_list'),
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user