Ticket #8723: search.diff
File search.diff, 9.6 KB (added by , 16 years ago) |
---|
-
djangodocs/views.py
5 5 from django.core import urlresolvers 6 6 from django.http import HttpResponseRedirect, Http404 7 7 from django.shortcuts import render_to_response 8 from django.template import RequestContext 8 9 from unipath import FSPath as Path 9 10 10 11 def index(request): … … 26 27 ) 27 28 28 29 def document(request, lang, version, url): 29 if lang != 'en' or version != 'dev' or url == "search/": raise Http404()30 if lang != 'en' or version != 'dev': raise Http404() 30 31 31 32 docroot = Path(settings.DOCS_PICKLE_ROOT) 32 33 … … 44 45 'docs/%s.html' % '-'.join([b for b in bits if b]), 45 46 'docs/doc.html' 46 47 ] 47 return render_to_response(template_names, {48 'doc': pickle.load(open(doc )),49 'env': pickle.load(open(docroot.child('globalcontext.pickle') )),48 return render_to_response(template_names, RequestContext(request, { 49 'doc': pickle.load(open(doc, 'rb')), 50 'env': pickle.load(open(docroot.child('globalcontext.pickle'), 'rb')), 50 51 'update_date': datetime.datetime.fromtimestamp(docroot.child('last_build').mtime()), 51 52 'home': urlresolvers.reverse(document, kwargs={'lang':lang, 'version':version, 'url':''}), 52 }) 53 'search': urlresolvers.reverse(search, kwargs={'lang':lang, 'version':version}), 54 })) 53 55 54 56 def images(request, lang, version, path): 55 57 if lang != 'en' or version != 'dev': raise Http404() … … 65 67 request, 66 68 document_root = Path(settings.DOCS_PICKLE_ROOT).child('_sources'), 67 69 path = path, 68 ) 69 No newline at end of file 70 ) 71 72 def search(request, lang, version): 73 if lang != 'en' or version != 'dev': raise Http404() 74 75 docroot = Path(settings.DOCS_PICKLE_ROOT) 76 77 # Remove the 'cof' GET variable from the query string so that the page 78 # linked to by the Javascript fallback doesn't think its inside an iframe. 79 mutable_get = request.GET.copy() 80 if 'cof' in mutable_get: 81 del mutable_get['cof'] 82 83 return render_to_response('docs/search.html', RequestContext(request, { 84 'query': request.GET.get('q'), 85 'query_string': mutable_get.urlencode(), 86 'env': pickle.load(open(docroot.child('globalcontext.pickle'), 'rb')), 87 'home': urlresolvers.reverse(document, kwargs={'lang':lang, 'version':version, 'url':''}), 88 'search': urlresolvers.reverse(search, kwargs={'lang':lang, 'version':version}), 89 })) 90 No newline at end of file -
djangodocs/settings.py
1 1 from django_website.settings import * 2 2 3 3 PREPEND_WWW = False 4 INSTALLED_APPS = [ ]4 INSTALLED_APPS = ['djangodocs'] 5 5 TEMPLATE_DIRS = [os.path.join(os.path.dirname(__file__), "templates")] + TEMPLATE_DIRS 6 TEMPLATE_CONTEXT_PROCESSORS = ['django.core.context_processors.request'] 6 7 ROOT_URLCONF = 'djangodocs.urls' 7 8 CACHE_MIDDLEWARE_KEY_PREFIX = 'djangodocs' 8 9 -
djangodocs/templatetags/docs.py
1 from django.template import Library 2 3 from djangodocs.forms import SearchForm 4 5 6 register = Library() 7 8 @register.inclusion_tag('docs/search_form.html', takes_context=True) 9 def search_form(context, search_form_id='search'): 10 request = context['request'] 11 auto_id = 'id_%s_%%s' % search_form_id 12 return { 13 'form': SearchForm(initial=request.GET, auto_id=auto_id), 14 'search_form_id': search_form_id, 15 'action': context['search'], 16 } 17 No newline at end of file -
djangodocs/urls.py
11 11 djangodocs.views.language, 12 12 ), 13 13 url( 14 r'^(?P<lang>[a-z-]+)/(?P<version>[\w.-]+)/ (?P<url>[\w./-]*)$',15 djangodocs.views. document,14 r'^(?P<lang>[a-z-]+)/(?P<version>[\w.-]+)/search/$', 15 djangodocs.views.search, 16 16 ), 17 17 url( 18 18 r'^(?P<lang>[a-z-]+)/(?P<version>[\w.-]+)/_images/(?P<path>.*)$', … … 22 22 r'^(?P<lang>[a-z-]+)/(?P<version>[\w.-]+)/_source/(?P<path>.*)$', 23 23 djangodocs.views.source, 24 24 ), 25 url( 26 r'^(?P<lang>[a-z-]+)/(?P<version>[\w.-]+)/(?P<url>[\w./-]*)$', 27 djangodocs.views.document, 28 ), 25 29 ) -
djangodocs/forms.py
1 from django import newforms as forms 2 3 AS_Q_CHOICES = ( 4 ('more:dev_docs', 'Latest'), 5 ('more:1.0_docs', '1.0'), 6 ('more:0.96_docs', '0.96'), 7 ('more:all_docs', 'All'), 8 ) 9 10 class SearchForm(forms.Form): 11 q = forms.CharField(widget=forms.TextInput({'class': 'query'})) 12 as_q = forms.ChoiceField(choices=AS_Q_CHOICES, widget=forms.RadioSelect, initial='more:dev_docs') 13 14 No newline at end of file -
djangodocs/templates/docs/doc.html
1 1 {% extends "base_docs.html" %} 2 2 3 {% load docs %} 4 3 5 {% block title %}{{ doc.title }} | Django Documentation{% endblock %} 4 6 5 7 {% block extrahead %} 6 8 {{ block.super }} 9 <style type="text/css" media="screen"> 10 #docs-search { 11 color: #000; 12 float: right; 13 } 14 #docs-search form { 15 font-size: 92%; 16 margin: 0; 17 padding: 1em 1em 0; 18 white-space: nowrap; 19 } 20 form.search ul { 21 list-style: none; 22 margin: 0; 23 padding: 0; 24 } 25 form.search li { 26 display: inline; 27 padding-right: 1em; 28 } 29 form.search .query { 30 width: 18em; 31 } 32 </style> 7 33 <link rel="stylesheet" href="http://media.djangoproject.com/css/pygments.css" type="text/css" /> 8 34 {% endblock %} 9 35 10 {% block billboard %}<h2><a href="{{ home }}">Django documentation</a></h2>{% endblock %} 36 {% block billboard %} 37 {% block search %} 38 <div id="docs-search"> 39 {% search_form %} 40 </div> 41 {% endblock %} 42 <h2><a href="{{ home }}">Django documentation</a></h2> 43 {% endblock %} 11 44 12 45 {% block content %} 13 46 … … 73 106 </ul> 74 107 {% endblock %} 75 108 76 <h3>Last update:</h3> 77 <div>{{ update_date|date:"F j, Y, P" }} (<a href="http://www.timeanddate.com/worldclock/city.html?n=64">CDT</a>)</div> 109 {% block last-update-wrapper %} 110 <h3>Last update:</h3> 111 <div>{{ update_date|date:"F j, Y, P" }} (<a href="http://www.timeanddate.com/worldclock/city.html?n=64">CDT</a>)</div> 112 {% endblock %} 78 113 {% endblock %} -
djangodocs/templates/docs/search.html
1 {% extends "docs/doc.html" %} 2 3 {% load docs %} 4 5 {% block title %}Search | Django Docuemtation{% endblock %} 6 7 {% block extrahead %} 8 {{ block.super }} 9 <style type="text/css" media="screen"> 10 #cse-search-results iframe { 11 width: 100%; 12 } 13 </style> 14 {% endblock %} 15 16 {% block toc-wrapper %}{% endblock %} 17 18 {% block breadcrumbs-wrapper %}{% endblock %} 19 20 {% block last-update-wrapper %}{% endblock %} 21 22 {% block body %} 23 {% if query %} 24 <h1>Search Results</h1> 25 <div id="cse-search-results"> 26 <div id="cse-search-results-js-required"> 27 The Django Documentation search uses a Google Custom Search, which 28 requires Javascript. If your results don't appear here shortly, please 29 <a href="http://www.google.com/cse?{{ query_string|escape }}">view the results on Google's site</a>. 30 </div> 31 </div> 32 <script type="text/javascript"> 33 var googleSearchMessage = document.getElementById("cse-search-results-js-required"); 34 googleSearchMessage.parentNode.removeChild(googleSearchMessage); 35 36 var googleSearchIframeName = "cse-search-results"; 37 var googleSearchFormName = "cse-search-box"; 38 var googleSearchDomain = "www.google.com"; 39 var googleSearchPath = "/cse"; 40 </script> 41 <script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script> 42 {% else %} 43 <h1>Search</h1> 44 {% search_form "search_page" %} 45 {% endif %} 46 {% endblock %} -
djangodocs/templates/docs/search_form.html
1 <form action="{{ action|escape }}" id="{{ search_form_id|escape }}" class="search"> 2 <div> 3 <input type="hidden" name="cx" value="014182425414053223532:sfhzyefydv8" /> 4 <input type="hidden" name="cof" value="FORID:11" /> 5 <input type="hidden" name="ie" value="UTF-8" /> 6 <input type="hidden" name="hl" value="{{ lang|escape }}" /> 7 {{ form.q }} 8 <input type="submit" name="sa" class="submit" value="Search" /> 9 {{ form.as_q }} 10 </div> 11 </form> 12 <script type="text/javascript" src="http://www.google.com/coop/cse/brand?form={{ search_form_id|escape }}&lang={{ lang|escape }}"></script>