Fix search engine URL generation
This commit is contained in:
parent
b7be4f4df4
commit
90a6164861
1 changed files with 4 additions and 3 deletions
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue