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):