From 6b360ba467c20829060588dbba5ca18010e05f73 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 11 Nov 2021 16:59:36 +0100 Subject: [PATCH] search: use description template from settings for users (#58548) --- combo/apps/search/forms.py | 6 ++++++ tests/test_search.py | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/combo/apps/search/forms.py b/combo/apps/search/forms.py index a3f47acf..9f5677b9 100644 --- a/combo/apps/search/forms.py +++ b/combo/apps/search/forms.py @@ -167,6 +167,12 @@ class UsersEngineSettingsUpdateForm(forms.ModelForm): def __init__(self, *args, **kwargs): self.engine_slug = kwargs.pop('engine_slug') super().__init__(*args, **kwargs) + try: + users_engine_settings = engines.get('users') + except KeyError: + users_engine_settings = {} + if 'hit_description_template' in users_engine_settings: + self.fields['description_template'].initial = users_engine_settings['hit_description_template'] def get_title(self): return _('Update "Users" engine') diff --git a/tests/test_search.py b/tests/test_search.py index e8d8b2f5..23cd57a8 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -1149,8 +1149,18 @@ def test_profile_add_search_engines(settings, app, admin_user): not in resp.text ) + # check default value from settings is retained in configuration form + users_engine = engines.get('users').copy() + settings.COMBO_SEARCH_SERVICES = {'users': users_engine} + with mock.patch.dict( + users_engine, {'hit_description_template': users_engine['hit_description_template'] + ' xxx'} + ): + form_resp = resp.click(href='.*/search_searchcell-%s/engine/users/add/' % cell.pk) + assert form_resp.form['description_template'].value.endswith(' xxx') + resp = resp.click(href='.*/search_searchcell-%s/engine/users/add/' % cell.pk) resp.form['title'] = 'Custom Title' + assert not resp.form['description_template'].value.endswith(' xxx') resp.form['description_template'] = 'Foo Bar' resp = resp.form.submit('submit') assert resp.status_int == 302 -- 2.33.0