diff options
author | Dan McGee <dan@archlinux.org> | 2010-02-07 16:57:26 +0100 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2010-02-09 04:01:15 +0100 |
commit | 8c077a4caa73c7e4a5e148195f1d6d3cdae572cf (patch) | |
tree | c69b42fdf68773894baf45b1f1feefe1f20eb849 | |
parent | f445754db57f37dcb1821a9330aa238632457146 (diff) | |
download | archweb-8c077a4caa73c7e4a5e148195f1d6d3cdae572cf.tar.gz archweb-8c077a4caa73c7e4a5e148195f1d6d3cdae572cf.tar.xz |
Add OpenSearch support to the site
Implements FS#14185. It is a bit more complex than listed there as I wanted
to not hardcode the URLs in the descriptor file; to do this we need to make
it a template and fill some things in. We also need to serve the file using
the correct mime type.
Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r-- | packages/views.py | 14 | ||||
-rw-r--r-- | templates/base.html | 1 | ||||
-rw-r--r-- | templates/packages/opensearch.xml | 13 | ||||
-rw-r--r-- | urls.py | 1 |
4 files changed, 28 insertions, 1 deletions
diff --git a/packages/views.py b/packages/views.py index a514617..910af94 100644 --- a/packages/views.py +++ b/packages/views.py @@ -3,7 +3,7 @@ from django import forms from django.core.mail import send_mail from django.shortcuts import render_to_response from django.template import loader, Context, RequestContext -from django.http import HttpResponseRedirect +from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import get_object_or_404 from django.contrib.auth.models import User from django.contrib.auth.decorators import permission_required @@ -15,6 +15,18 @@ from archweb.main.models import Package, PackageFile from archweb.main.models import Arch, Repo, Signoff from archweb.main.utils import make_choice +def opensearch(request): + if request.is_secure(): + d = "https://%s" % request.META['HTTP_HOST'] + else: + d = "http://%s" % request.META['HTTP_HOST'] + response = HttpResponse(mimetype='application/opensearchdescription+xml') + t = loader.get_template('packages/opensearch.xml') + c = Context({ + 'domain': d, + }) + response.write(t.render(c)) + return response @permission_required('main.change_package') def update(request): diff --git a/templates/base.html b/templates/base.html index bbdfe74..39b2a62 100644 --- a/templates/base.html +++ b/templates/base.html @@ -7,6 +7,7 @@ <link rel="stylesheet" type="text/css" href="/media/arch.css" /> <link rel="icon" type="image/x-icon" href="/media/favicon.ico" /> <link rel="shortcut icon" type="image/x-icon" href="/media/favicon.ico" /> + <link rel="search" type="application/opensearchdescription+xml" href="/opensearch/packages/" title="Arch Linux Packages" /> {% block head %} {% endblock %} </head> diff --git a/templates/packages/opensearch.xml b/templates/packages/opensearch.xml new file mode 100644 index 0000000..711b36a --- /dev/null +++ b/templates/packages/opensearch.xml @@ -0,0 +1,13 @@ +<?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> + <Tags>linux archlinux package software</Tags> + <Image height="16" width="16" type="image/x-icon">{{domain}}/media/favicon.ico</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/"/> +</OpenSearchDescription> @@ -108,6 +108,7 @@ urlpatterns = patterns('', (r'^irc/$', direct_to_template, {'template': 'public/irc.html'}), (r'^moreforums/$', 'archweb.public.views.moreforums'), (r'^projects/$', 'archweb.public.views.projects'), + (r'^opensearch/packages/$', 'archweb.packages.views.opensearch'), ) if settings.DEBUG == True: |