add OpenSearch lookup

This commit is contained in:
j 2011-12-30 16:00:49 +05:30
parent e26812bf5d
commit 691b1e98cc
4 changed files with 37 additions and 3 deletions

View file

@ -1,5 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # 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.shortcuts import render_to_response, redirect
from django.template import RequestContext from django.template import RequestContext
from django.conf import settings from django.conf import settings
@ -34,6 +39,33 @@ def embed(request, id):
}) })
return render_to_response('embed.html', context) 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(
'<?xml version="1.0" encoding="UTF-8"?>\n' + ET.tostring(osd),
'application/xml'
)
def getPage(request): def getPage(request):
''' '''

View file

@ -8,6 +8,7 @@
<link rel="icon" href="/static/png/icon64.png" sizes="48x48"/> <link rel="icon" href="/static/png/icon64.png" sizes="48x48"/>
<meta name="application-name" content="{{settings.SITENAME}}"/> <meta name="application-name" content="{{settings.SITENAME}}"/>
<meta name="application-url" content="{{base_url}}"/> <meta name="application-url" content="{{base_url}}"/>
<link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="{{settings.SITENAME}}" />
<script> <script>
if (localStorage && !localStorage.OxTheme) if (localStorage && !localStorage.OxTheme)
localStorage.OxTheme = '{{settings.CONFIG.user.ui.theme}}'; localStorage.OxTheme = '{{settings.CONFIG.user.ui.theme}}';

View file

@ -27,10 +27,11 @@ urlpatterns = patterns('',
(r'^api$', include('api.urls')), (r'^api$', include('api.urls')),
(r'^api/$', include('api.urls')), (r'^api/$', include('api.urls')),
(r'^resetUI$', 'user.views.reset_ui'), (r'^resetUI$', 'user.views.reset_ui'),
(r'', include('item.urls')),
(r'^list/(?P<id>.*?)/icon(?P<size>\d*).jpg$', 'itemlist.views.icon'), (r'^list/(?P<id>.*?)/icon(?P<size>\d*).jpg$', 'itemlist.views.icon'),
(r'^robots.txt$', serve_static_file, {'location': os.path.join(settings.STATIC_ROOT, 'robots.txt'), 'content_type': 'text/plain'}), (r'^robots.txt$', serve_static_file, {'location': os.path.join(settings.STATIC_ROOT, 'robots.txt'), 'content_type': 'text/plain'}),
(r'^favicon.ico$', serve_static_file, {'location': os.path.join(settings.STATIC_ROOT, 'png/icon.16.png'), 'content_type': 'image/x-icon'}), (r'^favicon.ico$', serve_static_file, {'location': os.path.join(settings.STATIC_ROOT, 'png/icon.16.png'), 'content_type': 'image/x-icon'}),
(r'^opensearch.xml$', 'app.views.opensearch_xml'),
(r'', include('item.urls')),
) )
#if settings.DEBUG: #if settings.DEBUG:
#sould this not be enabled by default? nginx should handle those #sould this not be enabled by default? nginx should handle those

View file

@ -4,8 +4,8 @@
-e bzr+http://code.0x2620.org/oxtimeline/#egg=oxtimeline -e bzr+http://code.0x2620.org/oxtimeline/#egg=oxtimeline
simplejson simplejson
chardet chardet
celery>2.1.1 celery>2.4.2
django-celery>2.1.1 django-celery>2.4.2
#django_extensions #django_extensions
#-e git+https://github.com/django-extensions/django-extensions.git#egg=django_extensions #-e git+https://github.com/django-extensions/django-extensions.git#egg=django_extensions
#use fork fixing some postgresql issues #use fork fixing some postgresql issues