Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix search and search pagination #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fbone/frontend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def search():
pagination = None
if keywords:
page = int(request.args.get('page', 1))
pagination = User.search(keywords).paginate(page, 1)
pagination = User.search(keywords).paginate(page, 20)
else:
flash(_('Please input keyword(s)'), 'error')
return render_template('frontend/search.html', pagination=pagination, keywords=keywords)
Expand Down
4 changes: 2 additions & 2 deletions fbone/templates/frontend/search.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% from 'macros/_misc.html' import render_pagination, render_user_table %}
{% from 'macros/_misc.html' import render_pagination_search, render_user_table %}

{% extends 'layouts/base.html' %}

Expand All @@ -12,7 +12,7 @@
{% if pagination and pagination.pages > 0 %}
<p>{% trans total=pagination.total, keywords=keywords %}<strong>{{ total }}</strong> found for your search "<strong>{{ keywords }}</strong>".{% endtrans %}</p>
{{ render_user_table(pagination.items, 'zebra-striped') }}
{{ render_pagination(pagination, 'frontend.search') }}
{{ render_pagination_search(pagination, 'frontend.search', keywords=keywords) }}
{% else %}
<p>{% trans keywords=keywords %}Sorry, Nothing found for your search "<strong>{{ keywords }}</strong>".{% endtrans %}</p>
{% trans %}
Expand Down
29 changes: 26 additions & 3 deletions fbone/templates/macros/_misc.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
<table class='{{ class }}'>
<thead>
<tr>
<td>#</td>
<td>Username</td>
<td>Email</td>
</tr>
</thead>
<tbody>
{% for user in users %}
<tr>
<td>{{ loop.index }}</td>
<td><a href="{{ url_for('user.profile', name=user.name) }}">{{ user.name }}</a></td>
<td><a href="{{ url_for('user.profile', user_id=user.id) }}">{{ user.name }}</a></td>
<td>{{ user.email }}</td>
</tr>
{% endfor %}
Expand All @@ -21,6 +19,7 @@

{% macro render_pagination(pagination, endpoint) %}
{% if pagination.pages > 1 %}

<div class='pagination'>
<ul>
<li class="prev {% if not pagination.has_prev %}disabled{% endif %}"><a href="{{ url_for(endpoint, page=pagination.page-1) }}">&larr; Previous</a></li>
Expand All @@ -40,3 +39,27 @@
</div>
{% endif %}
{% endmacro %}


{% macro render_pagination_search(pagination, endpoint) %}
{% if pagination.pages > 1 %}

<div class='pagination'>
<ul>
<li class="prev {% if not pagination.has_prev %}disabled{% endif %}"><a href="{{ url_for(endpoint, keywords=kwargs.keywords, page=pagination.page-1) }}">&larr; Previous</a></li>
{% for page in pagination.iter_pages() %}
{% if page %}
<li class='{% if page == pagination.page %}active{% endif %}'>
<a href='{{ url_for(endpoint, keywords=kwargs.keywords, page=page) }}'>{{ page }}</a>
</li>
{% else %}
<li>
<a href='#'>...</a>
</li>
{% endif %}
{% endfor %}
<li class="next {% if not pagination.has_next %}disabled{% endif %}"><a href="{{ url_for(endpoint, keywords=kwargs.keywords ,page=pagination.page+1) }}">Next &rarr;</a></li>
</ul>
</div>
{% endif %}
{% endmacro %}