From c1c84a1e4490c6b970aeb8a98fc976ce7b0b919e Mon Sep 17 00:00:00 2001 From: David Andreev Date: Tue, 6 Sep 2016 09:45:38 +0200 Subject: [PATCH] Search: Use GET instead of POST in Search Form Closes #33 --- search/indico_search/blueprint.py | 6 +++--- search/indico_search/controllers.py | 2 +- search/indico_search/forms.py | 4 ++++ search/indico_search/templates/results.html | 2 +- search/indico_search/templates/searchbox_category.html | 2 +- search/indico_search/templates/searchbox_conference.html | 2 +- 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/search/indico_search/blueprint.py b/search/indico_search/blueprint.py index 1d333c4..8e94a6d 100644 --- a/search/indico_search/blueprint.py +++ b/search/indico_search/blueprint.py @@ -23,8 +23,8 @@ from indico_search.controllers import RHSearch, RHSearchCategoryTitles blueprint = IndicoPluginBlueprint('search', 'indico_search') -blueprint.add_url_rule('/search', 'search', RHSearch, methods=('GET', 'POST')) -blueprint.add_url_rule('/category//search', 'search', RHSearch, methods=('GET', 'POST')) -blueprint.add_url_rule('/event//search', 'search', RHSearch, methods=('GET', 'POST')) +blueprint.add_url_rule('/search', 'search', RHSearch) +blueprint.add_url_rule('/category//search', 'search', RHSearch) +blueprint.add_url_rule('/event//search', 'search', RHSearch) blueprint.add_url_rule('/category/search-titles', 'category_names', RHSearchCategoryTitles) diff --git a/search/indico_search/controllers.py b/search/indico_search/controllers.py index 11a3913..559703d 100644 --- a/search/indico_search/controllers.py +++ b/search/indico_search/controllers.py @@ -45,7 +45,7 @@ class RHSearch(RHCustomizable): def _process(self): with current_plugin.engine_plugin.plugin_context(): - form = current_plugin.search_form(prefix='search-', csrf_enabled=False) + form = current_plugin.search_form(formdata=request.args, prefix='search-', csrf_enabled=False) result = None if form.validate_on_submit(): result = current_plugin.perform_search(form.data, self.obj) diff --git a/search/indico_search/forms.py b/search/indico_search/forms.py index 4dc17f8..54869e9 100644 --- a/search/indico_search/forms.py +++ b/search/indico_search/forms.py @@ -16,6 +16,7 @@ from __future__ import unicode_literals +from flask import request from wtforms.ext.dateutil.fields import DateField from wtforms.fields.core import StringField, SelectField from wtforms.validators import Optional @@ -38,3 +39,6 @@ class SearchForm(IndicoForm): field = SelectField(_('Search in'), choices=FIELD_CHOICES, default='') start_date = DateField('Start Date', [Optional()], parse_kwargs={'dayfirst': True}) end_date = DateField('End Date', [Optional()], parse_kwargs={'dayfirst': True}) + + def is_submitted(self): + return 'search-phrase' in request.args diff --git a/search/indico_search/templates/results.html b/search/indico_search/templates/results.html index 0ba1d9e..1c5996a 100644 --- a/search/indico_search/templates/results.html +++ b/search/indico_search/templates/results.html @@ -24,7 +24,7 @@ {% block banner %}{% endblock %} - {{ form_header(form, i_form=false) }} + {{ form_header(form, method='get', i_form=false) }}
{{ form.phrase() }} diff --git a/search/indico_search/templates/searchbox_category.html b/search/indico_search/templates/searchbox_category.html index ab56e91..0324c3d 100644 --- a/search/indico_search/templates/searchbox_category.html +++ b/search/indico_search/templates/searchbox_category.html @@ -1,6 +1,6 @@ {% from 'forms/_form.html' import form_header, form_footer %} -{{ form_header(form, action=url_for_plugin('search.search'), id='category-search-form', i_form=false) }} +{{ form_header(form, method='get', action=url_for_plugin('search.search'), id='category-search-form', i_form=false) }}