From 90a61648616a42515bb4c33c133367803822fe0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Mon, 26 Feb 2018 10:19:51 +0100 Subject: [PATCH] Fix search engine URL generation --- profiles/models.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/profiles/models.py b/profiles/models.py index d5765c4..c8ffea7 100644 --- a/profiles/models.py +++ b/profiles/models.py @@ -185,8 +185,8 @@ class SearchEngine(models.Model): url = models.URLField() query_pattern = models.CharField(max_length=256) # This field is the # query pattern. It should contain a `{}`, which, when substituted with a - # search term (using `.format()`), must yield a URL that can be resolved to - # perform the search + # search term (using `.format()`), must yield a URL tail that can be + # concatenated with `url` to perform a search (eg. `?q={}` for ddg). def __str__(self): return self.name @@ -194,9 +194,10 @@ class SearchEngine(models.Model): def search_url(self, search_term): ''' Obtain a url to search `search_term` with this search engine ''' pattern = str(self.query_pattern) + search_term = str(search_term).replace(' ', '+') if '{}' not in pattern: raise InvalidData("Search engine {}: bad pattern".format(self)) - return str(self.query_pattern).format(search_term) + return self.url + (str(self.query_pattern).format(search_term)) class Interest(models.Model):