Projet

Général

Profil

0001-search-add-possibility-to-specify-templates-for-hits.patch

Frédéric Péters, 09 août 2018 11:41

Télécharger (1,66 ko)

Voir les différences:

Subject: [PATCH] search: add possibility to specify templates for hits
 (#25614)

 combo/apps/search/models.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)
combo/apps/search/models.py
21 21
from django.core.exceptions import PermissionDenied
22 22
from django.core.urlresolvers import reverse
23 23
from django.utils.http import quote
24
from django.template import Context, Template
24 25

  
25 26
from jsonfield import JSONField
26 27

  
......
132 133
        kwargs['cache_duration'] = service.get('cache_duration', 0)
133 134
        kwargs['remote_service'] = 'auto' if service.get('signature') else None
134 135
        results = requests.get(url, **kwargs).json()
136
        hit_templates = {}
137
        if service.get('hit_url_template'):
138
            hit_templates['url'] = Template(service['hit_url_template'])
139
        if service.get('hit_label_template'):
140
            hit_templates['text'] = Template(service['hit_label_template'])
141
        if service.get('hit_description_template'):
142
            hit_templates['description'] = Template(service['hit_description_template'])
143
        if hit_templates:
144
            for hit in results.get('data'):
145
                for k, v in hit_templates.items():
146
                    hit[k] = v.render(Context(hit))
135 147
        return render_response(service, results)
136
-