From 691b1e98cc00f92c2505515614938fbf625e4957 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 30 Dec 2011 16:00:49 +0530 Subject: [PATCH] add OpenSearch lookup --- pandora/app/views.py | 32 ++++++++++++++++++++++++++++++++ pandora/templates/index.html | 1 + pandora/urls.py | 3 ++- requirements.txt | 4 ++-- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/pandora/app/views.py b/pandora/app/views.py index 4db2e1b43..f6ccaf955 100644 --- a/pandora/app/views.py +++ b/pandora/app/views.py @@ -1,5 +1,10 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 +try: + import xml.etree.ElementTree as ET +except: + import elementtree.ElementTree as ET + from django.shortcuts import render_to_response, redirect from django.template import RequestContext from django.conf import settings @@ -34,6 +39,33 @@ def embed(request, id): }) return render_to_response('embed.html', context) +def opensearch_xml(request): + osd = ET.Element('OpenSearchDescription') + osd.attrib['xmlns']="http://a9.com/-/spec/opensearch/1.1/" + e = ET.SubElement(osd, 'ShortName') + e.text = settings.SITENAME + e = ET.SubElement(osd, 'Description') + e.text = settings.SITENAME + e = ET.SubElement(osd, 'Image') + e.attrib['height'] = '16' + e.attrib['width'] = '16' + e.attrib['type'] = 'image/x-icon' + e.text = request.build_absolute_uri('/favicon.ico') + e = ET.SubElement(osd, 'Url') + e.attrib['type'] = 'text/html' + e.attrib['method'] = 'GET' + e.attrib['template'] = "%s/{searchTerms}" % request.build_absolute_uri('/') + ''' + e = ET.SubElement(osd, 'Url') + e.attrib['type'] = 'application/x-suggestions+json' + e.attrib['method'] = 'GET' + e.attrib['template'] = "%s?q={searchTerms}" % request.build_absolute_uri('/opensearch_suggest') + ''' + return HttpResponse( + '\n' + ET.tostring(osd), + 'application/xml' + ) + def getPage(request): ''' diff --git a/pandora/templates/index.html b/pandora/templates/index.html index d43b81839..b74d27511 100644 --- a/pandora/templates/index.html +++ b/pandora/templates/index.html @@ -8,6 +8,7 @@ +