Browse files

Fix some search URL constructions I missed in 1914a6d. Address bug 83…

…4509.

There still needs to be a SPOT for this.
  • Loading branch information...
1 parent 450d172 commit 038332eb681ea189b59ab4fb528d17d1f20c15c5 @erikrose erikrose committed Mar 14, 2013
Showing with 26 additions and 13 deletions.
  1. +1 −1 docs/templating.mkd
  2. +5 −4 dxr/app.py
  3. +5 −3 dxr/plugins/clang/htmlifier.py
  4. +2 −2 dxr/static/file.js
  5. +1 −1 dxr/templates/layout.html
  6. +0 −2 dxr/templates/search.html
  7. +12 −0 dxr/utils.py
View
2 docs/templating.mkd
@@ -112,7 +112,7 @@ File Template Variables
All instances of this template are rendered statically when the index is generated.
Please note that the template should have Javascript support for handling the
querystring `?q={{query}}` where users should be offered to see search results at
-`{{wwwroot}}/search?q?{{query}}&tree={{tree}}&force`, as `?q={{query}}`
+`{{ wwwroot }}/{{ tree }}/search?q={{ query }}&force`, as `?q={{ query }}`
indicates that the user was redirected to a direct result.
Note: the `query` variable is **not** available in the this template, and must
be parsed from querystring using Javascript.
View
9 dxr/app.py
@@ -9,7 +9,7 @@
from dxr.query import Query
from dxr.server_utils import connect_db
-from dxr.utils import non_negative_int
+from dxr.utils import non_negative_int, search_url
# Look in the 'dxr' package for static files, templates, etc.:
@@ -48,7 +48,6 @@ def search(tree):
offset = non_negative_int(querystring.get('offset'), 0)
limit = non_negative_int(querystring.get('limit'), 100)
- # Get and validate tree:
config = current_app.config
# Arguments for the template:
@@ -101,8 +100,10 @@ def search(tree):
if not error:
# Search template variables:
arguments['query'] = qtext
- # quote_plus needs a string.
- arguments['quoted_query'] = quote_plus(qtext.encode('utf-8'))
+ arguments['search_url'] = search_url(arguments['wwwroot'],
+ arguments['tree'],
+ qtext,
+ redirect=False)
arguments['results'] = results
arguments['offset'] = offset
arguments['limit'] = limit
View
8 dxr/plugins/clang/htmlifier.py
@@ -4,6 +4,8 @@
import clang.tokenizers as tokenizers
import urllib, re
+from dxr.utils import search_url
+
class ClangHtmlifier:
""" Pygmentizer add syntax regions for file """
@@ -251,9 +253,9 @@ def refs(self):
def search(self, query):
""" Auxiliary function for getting the search url for query """
- url = self.tree.config.wwwroot + "/search?tree=" + self.tree.name
- url += "&q=" + urllib.quote(query)
- return url
+ return search_url(self.tree.config.wwwroot,
+ self.tree.name,
+ query)
def quote(self, qualname):
""" Wrap qualname in quotes if it contains spaces """
View
4 dxr/static/file.js
@@ -75,7 +75,7 @@ function init_menu(){
icon: 'search',
text: "Search for \"" + htmlEntities(word) + "\"",
title: "Search for documents with the substring \"" + htmlEntities(word) + "\"",
- href: wwwroot + "/search?tree=" + encodeURIComponent(dxr.tree()) + "&q=" + encodeURIComponent(word)
+ href: wwwroot + "/" + encodeURIComponent(dxr.tree()) + "/search?q=" + encodeURIComponent(word)
});
}
// Append menu from target, if any
@@ -144,7 +144,7 @@ function init_tip(){
}
if(query){
// Set a nice search tip, so people can go the results
- var url = wwwroot + "/search?tree=" + dxr.tree() + "&q=" + query + "&redirect=false";
+ var url = wwwroot + "/" + encodeURIComponent(dxr.tree()) + "/search?q=" + encodeURIComponent(query) + "&redirect=false";
text = ("You've been taken to a direct result " +
"<a href='{{url}}'>click here</a>" +
" to see all search results").replace("{{url}}", url);
View
2 dxr/templates/layout.html
@@ -41,7 +41,7 @@
<img src="{{ wwwroot }}/static/magmoz.svg" id="big-logo">
<div id="search-background">
<a id="dxr" href="{{ wwwroot }}/"><img src="{{ wwwroot }}/static/magmoz.svg" id="small-logo"></a>
- <form method="get" action="{{ wwwroot }}/search" id="width-limiter">
+ <form method="get" action="{{ wwwroot }}/{{ tree }}/search" id="width-limiter">
{% set showing_tree_menu = trees|length > 1 %}
<div class="hidden-with-results">
You can search
View
2 dxr/templates/search.html
@@ -134,8 +134,6 @@
{# We don't show next link if there's no more results,
# and show prev link if offset != 0. Note that these links will
# only be available to non-javascript users. #}
- {% set search_url = wwwroot + '/' + tree + '/search?q=' +
- quoted_query + '&redirect=false' %}
{% set prev = offset - results|length %}
{% set next = offset + results|length %}
<div id="result-page-switch">
View
12 dxr/utils.py
@@ -7,6 +7,7 @@
import string
import subprocess
import sys
+from urllib import quote, quote_plus
from datetime import datetime
import dxr
@@ -256,3 +257,14 @@ def non_negative_int(s, default):
except (ValueError, TypeError):
pass
return default
+
+
+def search_url(www_root, tree, query, redirect=None):
+ """Return the URL to the search endpoint."""
+ ret = '%s/%s/search?q=%s' % (www_root,
+ quote(tree),
+ # quote_plus needs a string.
+ quote_plus(query.encode('utf-8')))
+ if redirect is not None:
+ ret += 'redirect=%s' % ('true' if redirect else 'false')
+ return ret

0 comments on commit 038332e

Please sign in to comment.