From 605b161b92ec890b757daa41dac385b08e5cba80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Thu, 9 Aug 2018 10:31:20 +0200 Subject: [PATCH] search: add possibility to specify templates for hits (#25614) --- combo/apps/search/models.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/combo/apps/search/models.py b/combo/apps/search/models.py index a1e0885..29a4f55 100644 --- a/combo/apps/search/models.py +++ b/combo/apps/search/models.py @@ -21,6 +21,7 @@ from django.http import HttpResponse from django.core.exceptions import PermissionDenied from django.core.urlresolvers import reverse from django.utils.http import quote +from django.template import Context, Template from jsonfield import JSONField @@ -132,4 +133,15 @@ class SearchCell(CellBase): kwargs['cache_duration'] = service.get('cache_duration', 0) kwargs['remote_service'] = 'auto' if service.get('signature') else None results = requests.get(url, **kwargs).json() + hit_templates = {} + if service.get('hit_url_template'): + hit_templates['url'] = Template(service['hit_url_template']) + if service.get('hit_label_template'): + hit_templates['text'] = Template(service['hit_label_template']) + if service.get('hit_description_template'): + hit_templates['description'] = Template(service['hit_description_template']) + if hit_templates: + for hit in results.get('data'): + for k, v in hit_templates.items(): + hit[k] = v.render(Context(hit)) return render_response(service, results) -- 2.18.0