search: use context_processors for results template (#16452)

This commit is contained in:
Thomas NOËL 2017-05-23 13:36:48 +02:00
parent 54a60e584a
commit bd2df6fb70
3 changed files with 15 additions and 5 deletions

View File

@ -23,6 +23,7 @@ from django.core.exceptions import PermissionDenied
from django.core.urlresolvers import reverse
from django.forms import models as model_forms, Select
from django.utils.http import quote
from django.template import RequestContext
from combo.utils import requests
from combo.data.models import CellBase
@ -114,9 +115,6 @@ class SearchCell(CellBase):
if cell.slug:
template_names.insert(0, 'combo/cells/%s/search-cell-results.html' % cell.slug)
tmpl = template.loader.select_template(template_names)
context = {
'request': request,
'cell': cell,
'results': results
}
context = RequestContext(request)
context.push({'request': request, 'cell': cell, 'results': results})
return HttpResponse(tmpl.render(context), content_type='text/html')

View File

@ -0,0 +1,2 @@
searchfoo results.data={{ results.data }}
search_url={{ search_url }}

View File

@ -1,4 +1,5 @@
import json
import os
import pytest
import mock
@ -99,6 +100,15 @@ def test_search_cell(app):
resp = client.get('/ajax/search/%s/?q=foo' % cell.pk, status=200)
assert requests_get.call_args[0][0] == 'http://search.example.net/?q=foo'
# TEMPLATE_VARS are accessible in template
cell.slug = 'searchfoo'
cell.save()
with override_settings(TEMPLATE_DIRS=['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]):
resp = client.get('/ajax/search/%s/?q=bar' % cell.pk, status=200)
assert requests_get.call_args[0][0] == 'http://search.example.net/?q=bar'
assert 'searchfoo results.data=[]' in resp.content
assert 'search_url=http://search.example.net/' in resp.content
def test_search_global_context(app):
with SearchServices(SEARCH_SERVICES):
page = Page(title='Search', slug='search_page', template_name='standard')