From 8c077a4caa73c7e4a5e148195f1d6d3cdae572cf Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 7 Feb 2010 09:57:26 -0600 Subject: 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 --- packages/views.py | 14 +++++++++++++- templates/base.html | 1 + templates/packages/opensearch.xml | 13 +++++++++++++ urls.py | 1 + 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 templates/packages/opensearch.xml diff --git a/packages/views.py b/packages/views.py index a514617d..910af94a 100644 --- a/packages/views.py +++ b/packages/views.py @@ -3,7 +3,7 @@ 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 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 bbdfe74a..39b2a625 100644 --- a/templates/base.html +++ b/templates/base.html @@ -7,6 +7,7 @@ + {% block head %} {% endblock %} diff --git a/templates/packages/opensearch.xml b/templates/packages/opensearch.xml new file mode 100644 index 00000000..711b36a2 --- /dev/null +++ b/templates/packages/opensearch.xml @@ -0,0 +1,13 @@ + + + Arch Linux Packages + Search the Arch Linux package repositories. + linux archlinux package software + {{domain}}/media/favicon.ico + en-us + UTF-8 + UTF-8 + + + + diff --git a/urls.py b/urls.py index 4a52998c..e0df2da2 100644 --- a/urls.py +++ b/urls.py @@ -108,6 +108,7 @@ (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: -- cgit v1.2.3-54-g00ecf