Various fixes/improvements

This commit is contained in:
Adrian Moennich 2014-10-29 15:14:36 +01:00
parent ec3a3ec8a8
commit 1289f3faeb
7 changed files with 84 additions and 42 deletions

View File

@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with Indico; if not, see <http://www.gnu.org/licenses/>.
__all__ = ('SearchPluginBase', 'SearchEngine')
__all__ = ('SearchPluginBase', 'SearchEngine', 'SearchForm')
from .base import SearchPluginBase, SearchEngine
from .forms import SearchForm

View File

@ -41,33 +41,27 @@ class SearchPluginBase(IndicoPlugin):
"""If the search engine only returns public events"""
return session.user is None
def perform_search(self, values, obj=None, page=1):
def perform_search(self, values, obj=None):
"""Performs the search.
For documentation on the parameters and return value, see
the documentation of the :class:`SearchEngine` class.
"""
return self.engine_class(values, obj, page).process()
return self.engine_class(values, obj).process()
class SearchEngine(object):
"""Base class for a search engine"""
def __init__(self, values, obj, page):
def __init__(self, values, obj):
"""
:param values: the values sent by the user
:param obj: object to search in (a `Category` or `Conference`)
:param page: the result page to show (if supported)
"""
self.values = values
self.obj = obj
self.page = page
self.user = session.user
def build_url(self, **query_params):
"""Creates the URL for the search request"""
raise NotImplementedError
def process(self):
"""Executes the search

View File

@ -43,18 +43,13 @@ class RHSearch(RHCustomizable):
self.obj = CategoryManager().getRoot()
self.obj_type = None
try:
self.page = int(request.values['page'])
except (ValueError, KeyError):
self.page = 1
def _process(self):
with current_plugin.engine_plugin.plugin_context():
form = current_plugin.search_form(prefix='search-')
result = None
if form.validate_on_submit():
result = current_plugin.perform_search(form.data, self.obj, self.page)
if isinstance(result, Response): # probably a redirect
result = current_plugin.perform_search(form.data, self.obj)
if isinstance(result, Response): # probably a redirect or a json response
return result
view_class = WPSearchConference if isinstance(self.obj, Conference) else WPSearchCategory
return view_class.render_template('results.html', self.obj, only_public=current_plugin.only_public,

View File

@ -69,6 +69,6 @@ class SearchPlugin(IndicoPlugin):
return render_engine_or_search_template('searchbox_conference.html', event=event, form=form)
def _add_category_search_box(self, category, **kwargs):
if category is not None and request.blueprint != 'plugin_search':
if request.blueprint != 'plugin_search':
form = self.engine_plugin.search_form(prefix='search-')
return render_engine_or_search_template('searchbox_category.html', category=category, form=form)

View File

@ -14,17 +14,59 @@
}
}
.search-public-warning {
color: #FF4444;
padding: 10px;
}
.search-container {
.search-public-warning {
float: right;
padding: 10px;
color: #FF4444;
}
.search-title {
font-size: 2em;
color: #B14300;
font-weight: normal;
margin: 0;
padding: 0;
.search-banner {
float: right;
margin-top: 10px;
& > span {
color: #777;
}
img {
vertical-align: middle;
border: 0;
}
}
.content {
form {
width: 400px;
#search-phrase {
width: 300px;
height: 20px;
font-size: 17px;
vertical-align: middle;
}
input[type=submit] {
vertical-align: middle;
}
.toggle-advanced-options-container {
padding-top: 4px;
}
.advanced-options > table {
text-align: right;
}
}
}
h1 {
font-size: 2em;
color: #B14300;
font-weight: normal;
margin: 0;
padding: 0;
}
}
#category-search-form {

View File

@ -1,11 +1,11 @@
<div class="container">
<div class="container search-container">
{% if only_public %}
<div class="search-public-warning" style="float: right;">
<div class="search-public-warning">
{% trans %}Warning: since you are not logged in, only results from public events will appear.{% endtrans %}
</div>
{% endif %}
<h1 class="search-title">
<h1>
{% trans %}Search{% endtrans %}
{% if obj_type == 'event' %}
{% trans %}Event{% endtrans %}
@ -17,24 +17,24 @@
<div class="topBar">
<div class="content">
<div>
<div style="float: right; margin-top:10px;">
<span style="color:#777">Search powered by</span>
<div class="search-banner">
<span>Search powered by</span>
{% block banner %}{% endblock %}
</div>
<form method="post" action="" style="width: 400px;">
<form method="post" action="">
<div>
{{ form.phrase(style='width: 300px; height: 20px; font-size: 17px; vertical-align: middle;') }}
<input type="submit" value="{% trans %}Search{% endtrans %}" style="vertical-align: middle;">
{{ form.phrase() }}
<input type="submit" value="{% trans %}Search{% endtrans %}">
{% block tooltip %}{% endblock %}
</div>
<div style="padding-top: 4px;">
<div class="toggle-advanced-options-container">
<a id="toggle-advanced-options" href="#">{% trans %}Show advanced options{% endtrans %}</a>
</div>
<div id="advanced-options" style="display: none;">
<table style="text-align: right;">
<div id="advanced-options" class="advanced-options" style="display: none;">
<table>
<tr>
<td>{{ form.field.label() }}</td>
<td>{{ form.field() }}</td>
@ -54,7 +54,17 @@
</form>
</div>
</div>
{% block results %}{% endblock %}
{% set errors = form.error_list %}
{% if errors %}
<ul>
{% for error in errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{% if form.validate_on_submit() %}
{% block results %}{% endblock %}
{% endif %}
</div>
</div>

View File

@ -35,7 +35,7 @@
categoryNamesUrl: {{ url_for_plugin('search.category_names') | tojson }},
searchUrl: {{ url_for_plugin('search.search') | tojson }},
searchCategoryUrl: {{ url_for_plugin('search.search', category) | tojson }},
categoryName: {{ category.name | tojson }},
isRoot: {{ category.isRoot() | tojson }}
categoryName: {{ (category.name if category else None) | tojson }},
isRoot: {{ (not category or category.isRoot()) | tojson }}
});
</script>