Skip to content
This repository has been archived by the owner on Jun 29, 2020. It is now read-only.

Commit

Permalink
検索フォームの未入力をバリデーションするようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
giginet committed Jul 27, 2014
1 parent 8c54d63 commit 3ad6f75
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
3 changes: 1 addition & 2 deletions src/kawaz/core/search/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ def build_schema(self, fields):
field_mapping = mapping[field_class.index_fieldname]

if field_mapping['type'] == 'string' and field_class.indexed:
if not hasattr(field_class, 'facet_for') and not \
field_class.field_type in('ngram', 'edge_ngram'):
if not hasattr(field_class, 'facet_for') and not field_class.field_type in('ngram', 'edge_ngram'):
field_mapping['analyzer'] = self.DEFAULT_ANALYZER
mapping.update({field_class.index_fieldname: field_mapping})
return (content_field_name, mapping)
Expand Down
38 changes: 20 additions & 18 deletions src/kawaz/templates/search/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,31 @@
<form type="get" action="." role="form">
<div class="form-group">
<label for="q" class="sr-only">検索ワード</label>
<input type="text" class="form-control" name="q">
<input type="text" class="form-control" name="q" value="{{ query }}" required>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-large">Search</button>
</div>
</form>
</div>
<div class="search-results">
<h1>「{{ query }}」の検索結果</h1>
<div>
{% if not page.object_list|length_is:0 %}
<div class="alert alert-info" role="alert"><strong>{{ page.object_list|length }}</strong>件の検索結果が見つかりました</div>
{% for result in page.object_list %}
<article class="search-result">
<h1><a href="{{ result.object.get_absolute_url }}">{{ result.title }}</a></h1>
<p>
{% highlight result.body with query html_tag "mark" %}
</p>
</article>
{% endfor %}
{% else %}
<div class="alert alert-info" role="alert">検索結果は見つかりませんでした</div>
{% endif %}
{% if query %}
<div class="search-results">
<h1>「{{ query }}」の検索結果</h1>
<div>
{% if not page.object_list|length_is:0 %}
<div class="alert alert-info" role="alert"><strong>{{ page.object_list|length }}</strong>件の検索結果が見つかりました</div>
{% for result in page.object_list %}
<article class="search-result">
<h1><a href="{{ result.object.get_absolute_url }}">{{ result.title }}</a></h1>
<p>
{% highlight result.body with query html_tag "mark" %}
</p>
</article>
{% endfor %}
{% else %}
<div class="alert alert-info" role="alert">検索結果は見つかりませんでした</div>
{% endif %}
</div>
</div>
</div>
{% endif %}
{% endblock %}

0 comments on commit 3ad6f75

Please sign in to comment.