Django

Code

Changeset 8844

Show
Ignore:
Timestamp:
09/01/08 23:09:40 (4 months ago)
Author:
jacob
Message:

[djangoproject.com] Fixed #8723: added search, via a Google coop search. Thanks to frasern for figuring this out and providing detailed instructions.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • djangoproject.com/djangodocs/settings.py

    r8468 r8844  
    22 
    33PREPEND_WWW = False 
    4 INSTALLED_APPS = [
     4INSTALLED_APPS = ['djangodocs'
    55TEMPLATE_DIRS = [os.path.join(os.path.dirname(__file__), "templates")] + TEMPLATE_DIRS 
     6TEMPLATE_CONTEXT_PROCESSORS = ['django.core.context_processors.request'] 
    67ROOT_URLCONF = 'djangodocs.urls' 
    78CACHE_MIDDLEWARE_KEY_PREFIX = 'djangodocs' 
  • djangoproject.com/djangodocs/templates/docs/doc.html

    r8470 r8844  
    55{% block extrahead %} 
    66  {{ block.super }} 
     7  <style type="text/css" media="screen"> 
     8    #docs-search { 
     9      color: #000; 
     10      float: right; 
     11    } 
     12    #docs-search form { 
     13      font-size: 92%; 
     14      margin: 0; 
     15      padding: 1em 1em 0; 
     16      white-space: nowrap; 
     17    } 
     18    form.search ul { 
     19      list-style: none; 
     20      margin: 0; 
     21      padding: 0; 
     22    } 
     23    form.search li { 
     24      display: inline; 
     25      padding-right: 1em; 
     26    } 
     27    form.search .query { 
     28      width: 18em; 
     29    } 
     30  </style> 
    731  <link rel="stylesheet" href="http://media.djangoproject.com/css/pygments.css" type="text/css" /> 
    832{% endblock %} 
    933 
    10 {% block billboard %}<h2><a href="{{ home }}">Django documentation</a></h2>{% endblock %} 
     34{% block billboard %} 
     35  <h2><a href="{{ home }}">Django documentation</a></h2> 
     36{% endblock %} 
    1137 
    1238{% block content %} 
     
    3864      {{ doc.toc }} 
    3965    {% endblock %} 
     66  {% endblock %} 
     67   
     68  {% block search %} 
     69    <h2>Search</h2> 
     70    {% load docs %} 
     71    {% search_form %} 
    4072  {% endblock %} 
    4173   
     
    74106  {% endblock %} 
    75107   
    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> 
     108  {% block last-update-wrapper %} 
     109    <h3>Last update:</h3> 
     110    <div>{{ update_date|date:"F j, Y, P" }} (<a href="http://www.timeanddate.com/worldclock/city.html?n=64">CDT</a>)</div> 
     111  {% endblock %} 
    78112{% endblock %} 
  • djangoproject.com/djangodocs/urls.py

    r8624 r8844  
    1212    ), 
    1313    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
    1616    ), 
    1717    url( 
     
    2323        djangodocs.views.source, 
    2424    ), 
     25    url( 
     26        r'^(?P<lang>[a-z-]+)/(?P<version>[\w.-]+)/(?P<url>[\w./-]*)$', 
     27        djangodocs.views.document, 
     28    ), 
    2529) 
  • djangoproject.com/djangodocs/views.py

    r8470 r8844  
    66from django.http import HttpResponseRedirect, Http404 
    77from django.shortcuts import render_to_response 
     8from django.template import RequestContext 
    89from unipath import FSPath as Path 
    910 
     
    2728 
    2829def 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() 
    3031 
    3132    docroot = Path(settings.DOCS_PICKLE_ROOT) 
     
    4546        'docs/doc.html' 
    4647    ] 
    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')), 
    5051        'update_date': datetime.datetime.fromtimestamp(docroot.child('last_build').mtime()), 
    5152        'home': urlresolvers.reverse(document, kwargs={'lang':lang, 'version':version, 'url':''}), 
    52     }) 
     53        'search': urlresolvers.reverse(search, kwargs={'lang':lang, 'version':version}), 
     54    })) 
    5355 
    5456def images(request, lang, version, path): 
     
    6769        path = path, 
    6870    ) 
     71 
     72def 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    }))