Skip to content

Commit

Permalink
Merge 6657d5e into afa9467
Browse files Browse the repository at this point in the history
  • Loading branch information
Fulbert committed Mar 21, 2015
2 parents afa9467 + 6657d5e commit faae54d
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 9 deletions.
Binary file added doc/source/images/search/opensearch-firefox.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions doc/source/utils/opensearch.rst
@@ -0,0 +1,8 @@
===================================================
Installer un plugin de recherche à votre navigateur
===================================================

Vous pouvez installer un plugin de recherche à votre navigateur en deux clics.

.. figure:: ../images/search/opensearch-firefox.png
:align: center
11 changes: 7 additions & 4 deletions templates/base.html
Expand Up @@ -111,6 +111,9 @@

{# RSS links #}
<link rel="alternate" type="application/rss+xml" title="Forum" href="{% url "post-feed-rss" %}">

{# OpenSearch plugin autodiscovery #}
<link rel="search" type="application/opensearchdescription+xml" title="{{ app.site.litteral_name }}" href="{% url "zds.search.views.opensearch" %}">
</head>
<body class="{% block body_class %}{% endblock %}"
itemscope
Expand Down Expand Up @@ -492,11 +495,11 @@
</ol>
</div>
<div class="search header-right" id="search">
<form action="/rechercher">
<input type="text" name="q" placeholder="Rechercher">
<button type="submit" class="ico-after search-submit" title="Lancer la recherche">{% trans "OK" %}</button>
<form action="{% url "haystack_search" %}">
<input type="text" name="q" placeholder="{% trans "Rechercher" %}">
<button type="submit" class="ico-after search-submit" title="{% trans "Lancer la recherche" %}">{% trans "OK" %}</button>
</form>
<a href="/rechercher" title="Recherche avancée" class="search-more"></a>
<a href="{% url "haystack_search" %}" title="{% trans "Recherche avancée" %}" class="search-more"></a>
</div>
</div>
</div>
Expand Down
19 changes: 19 additions & 0 deletions templates/search/opensearch.xml
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

{% load static %}

<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>{{ site_name }}</ShortName>
<Description>Rechercher sur {{ site_name}}</Description>
<InputEncoding>UTF-8</InputEncoding>
<OutputEncoding>UTF-8</OutputEncoding>
<AdultContent>false</AdultContent>
<Language>{{ language }}</Language>
<Contact>http://zestedesavoir.com/pages/contact/</Contact>
<Image height="57" width="57" type="image/png">{{ site_url }}{% static "images/favicon.png" %}</Image>
<Url type="text/html" method="GET" template="{{ search_url }}">
<Param name="q" value="{searchTerms}"/>
</Url>
<Url type="application/opensearchdescription+xml" rel="self" template="{{ site_url }}{% url "zds.search.views.opensearch" %}" />
</OpenSearchDescription>
13 changes: 8 additions & 5 deletions zds/search/urls.py
Expand Up @@ -8,9 +8,12 @@
from zds.search.forms import CustomSearchForm

urlpatterns = patterns('haystack.views',
url(r'^$', search_view_factory(
view_class=CustomSearchView,
template='search/search.html',
form_class=CustomSearchForm
), name='haystack_search'),
url(r'^$', search_view_factory(
view_class=CustomSearchView,
template='search/search.html',
form_class=CustomSearchForm
), name='haystack_search'))

urlpatterns += patterns('',
url(r'^opensearch.xml', 'zds.search.views.opensearch')
)
13 changes: 13 additions & 0 deletions zds/search/views.py
@@ -1,9 +1,11 @@
# coding: utf-8

from django.shortcuts import render
from django.core.urlresolvers import reverse

from haystack.views import SearchView

from zds import settings
from zds.search.constants import MODEL_NAMES
from zds.utils.paginator import paginator_range

Expand Down Expand Up @@ -31,3 +33,14 @@ def create_response(self):

context.update(self.extra_context())
return render(self.request, self.template, context)


def opensearch(request):
"""Generate OpenSearch Description file"""

return render(request, 'search/opensearch.xml', {
'site_name': settings.ZDS_APP['site']['litteral_name'],
'site_url': settings.ZDS_APP['site']['url'],
'language': settings.LANGUAGE_CODE,
'search_url': settings.ZDS_APP['site']['url'] + reverse('haystack_search')
}, content_type='application/opensearchdescription+xml')

0 comments on commit faae54d

Please sign in to comment.