diff --git a/combo/apps/search/forms.py b/combo/apps/search/forms.py index 5bc5f4be..55b49974 100644 --- a/combo/apps/search/forms.py +++ b/combo/apps/search/forms.py @@ -25,7 +25,7 @@ from .models import SearchCell class SearchCellForm(forms.ModelForm): class Meta: model = SearchCell - fields = ('_search_services',) + fields = ('_search_services', 'autofocus') def __init__(self, *args, **kwargs): super(SearchCellForm, self).__init__(*args, **kwargs) diff --git a/combo/apps/search/migrations/0005_searchcell_autofocus.py b/combo/apps/search/migrations/0005_searchcell_autofocus.py new file mode 100644 index 00000000..2980904e --- /dev/null +++ b/combo/apps/search/migrations/0005_searchcell_autofocus.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.18 on 2019-11-20 13:06 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('search', '0004_remove_searchcell__search_service'), + ] + + operations = [ + migrations.AddField( + model_name='searchcell', + name='autofocus', + field=models.BooleanField(default=False, verbose_name='Autofocus'), + ), + ] diff --git a/combo/apps/search/models.py b/combo/apps/search/models.py index 4859c4a6..5dcd794e 100644 --- a/combo/apps/search/models.py +++ b/combo/apps/search/models.py @@ -17,6 +17,7 @@ import os from django.conf import settings +from django.db import models from django.utils.translation import ugettext_lazy as _ from django import template from django.http import HttpResponse @@ -42,6 +43,7 @@ class SearchCell(CellBase): manager_form_template = 'combo/manager/search-cell-form.html' _search_services = JSONField(_('Search Services'), default=dict, blank=True) + autofocus = models.BooleanField(_('Autofocus'), default=False) class Meta: verbose_name = _('Search') diff --git a/combo/apps/search/templates/combo/search-cell.html b/combo/apps/search/templates/combo/search-cell.html index b9789ca7..0f71f4fc 100644 --- a/combo/apps/search/templates/combo/search-cell.html +++ b/combo/apps/search/templates/combo/search-cell.html @@ -3,7 +3,7 @@ {% block search-form %}
- +
{% endblock %} diff --git a/tests/test_search.py b/tests/test_search.py index 58c11c4f..5ed2f55c 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -65,6 +65,12 @@ def test_search_cell(app): resp = cell.render({}) assert 'input' in resp assert 'id="combo-search-input-%s"' % cell.pk in resp + assert 'autofocus' not in resp + + cell.autofocus = True + cell.save() + resp = cell.render({}) + assert 'autofocus' in resp cell.slug = 'var-name' context = {'request': RequestFactory().get('/?q_var_name=searchme')}