Add conference search box

This commit is contained in:
Adrian Moennich 2014-10-23 11:09:26 +02:00
parent bb32bcef8f
commit 627625d20b
6 changed files with 57 additions and 7 deletions

View File

@ -21,7 +21,7 @@ from flask_pluginengine import current_plugin
from MaKaC.conference import ConferenceHolder, Conference, CategoryManager
from MaKaC.webinterface.rh.conferenceBase import RHCustomizable
from indico_search.views import WPSearchCategory, WPSearchEvent
from indico_search.views import WPSearchCategory, WPSearchConference
class RHSearch(RHCustomizable):
@ -43,8 +43,8 @@ class RHSearch(RHCustomizable):
def _process(self):
with current_plugin.engine_plugin.plugin_context():
form = current_plugin.search_form()
view_class = WPSearchEvent if isinstance(self.obj, Conference) else WPSearchCategory
form = current_plugin.search_form(prefix='search-')
view_class = WPSearchConference if isinstance(self.obj, Conference) else WPSearchCategory
result = None
if form.validate_on_submit():
result = current_plugin.perform_search(form.data, self.obj, self.page)

View File

@ -35,6 +35,6 @@ FIELD_CHOICES = [('', _('Anywhere')),
class SearchForm(IndicoForm):
phrase = StringField(_('Phrase'), filters=[strip_whitespace])
field = SelectField(_('Search in'), choices=FIELD_CHOICES)
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})

View File

@ -21,6 +21,7 @@ from flask_pluginengine import plugins_loaded
from indico.core.plugins import IndicoPlugin
from indico_search.blueprint import blueprint
from indico_search.util import render_engine_or_search_template
class SearchPlugin(IndicoPlugin):
@ -35,6 +36,7 @@ class SearchPlugin(IndicoPlugin):
def init(self):
super(SearchPlugin, self).init()
self.connect(plugins_loaded, self._plugins_loaded, sender=self.app)
self.template_hook('conference-header', self._add_conference_search_box)
def _plugins_loaded(self, sender, **kwargs):
if not self.engine_plugin:
@ -52,3 +54,8 @@ class SearchPlugin(IndicoPlugin):
def get_blueprints(self):
return blueprint
def _add_conference_search_box(self, event, **kwargs):
if event.getDisplayMgr().getSearchEnabled():
form = self.engine_plugin.search_form(prefix='search-')
return render_engine_or_search_template('searchbox_conference.html', event=event, form=form)

View File

@ -0,0 +1,7 @@
<div class="confSearchBox">
<form class="UIForm" method="post" action="{{ url_for_plugin('search.search', event) }}" style="margin: 0; padding: 0;">
<input class="searchButton" type="submit" value="{% trans %}Search{% endtrans %}">
{{ form.phrase(class_='searchField', id='conference-search-phrase') }}
{% block extra_fields %}{% endblock %}
</form>
</div>

View File

@ -0,0 +1,37 @@
# This file is part of Indico.
# Copyright (C) 2002 - 2014 European Organization for Nuclear Research (CERN).
#
# Indico is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# Indico is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Indico; if not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from flask_pluginengine import render_plugin_template, current_plugin
def render_engine_or_search_template(template_name, **context):
"""Renders a template from the engine plugin or the search plugin
If the template is available in the engine plugin, it's taken
from there, otherwise the template from this plugin is used.
:param template_name: name of the template
:param context: the variables that should be available in the
context of the template.
"""
from indico_search.plugin import SearchPlugin
assert current_plugin == SearchPlugin.instance
templates = ('{}:{}'.format(SearchPlugin.instance.engine_plugin.name, template_name),
template_name)
return render_plugin_template(templates, **context)

View File

@ -18,7 +18,7 @@ from __future__ import unicode_literals
from indico.core.plugins import WPJinjaMixinPlugin
from MaKaC.webinterface.pages.category import WPCategoryDisplayBase
from MaKaC.webinterface.pages.conferences import WPConferenceDisplayBase
from MaKaC.webinterface.pages.conferences import WPConferenceDefaultDisplayBase
class WPSearchCategory(WPJinjaMixinPlugin, WPCategoryDisplayBase):
@ -26,7 +26,6 @@ class WPSearchCategory(WPJinjaMixinPlugin, WPCategoryDisplayBase):
return self._getPageContent(params)
class WPSearchEvent(WPJinjaMixinPlugin, WPConferenceDisplayBase):
# XXX shouldn't this inhert from WPConferenceDefaultDisplayBase?!
class WPSearchConference(WPJinjaMixinPlugin, WPConferenceDefaultDisplayBase):
def _getBody(self, params):
return self._getPageContent(params)