Make the history view pagination prettier.
This commit is contained in:
parent
35471d3c3f
commit
242e317e65
|
@ -64,14 +64,14 @@ def revert():
|
||||||
def history(name):
|
def history(name):
|
||||||
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
|
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
|
||||||
return current_app.login_manager.unauthorized()
|
return current_app.login_manager.unauthorized()
|
||||||
ITEMS_PER_PAGE = 15
|
items_per_page = 15
|
||||||
page = int(request.args.get('page', 1))
|
page = int(request.args.get('page', 1))
|
||||||
start_index = (page - 1) * ITEMS_PER_PAGE
|
start_index = (page - 1) * items_per_page
|
||||||
hist = g.current_wiki.get_page(name).get_history()
|
hist = g.current_wiki.get_page(name).history
|
||||||
# Grab one extra item to see if there is a next page
|
# Grab one extra item to see if there is a next page
|
||||||
items = hist[start_index:start_index+ITEMS_PER_PAGE+1]
|
items = list(itertools.islice(hist, start_index, start_index+items_per_page+1))
|
||||||
more = False
|
more = False
|
||||||
if len(items) > ITEMS_PER_PAGE:
|
if len(items) > items_per_page:
|
||||||
more = True
|
more = True
|
||||||
items.pop()
|
items.pop()
|
||||||
if page > 1 and not items:
|
if page > 1 and not items:
|
||||||
|
|
|
@ -15,6 +15,27 @@
|
||||||
<th>Date</th>
|
<th>Date</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
{% if pagination.page > 1 or pagination.more %}
|
||||||
|
<tfoot>
|
||||||
|
<tr><td colspan="4">
|
||||||
|
<ul class="pagination" style="float: right">
|
||||||
|
<li class="paginate_button previous{% if pagination.page == 1 %} disabled{% endif %}">
|
||||||
|
<a href="{{ url_for('.history', name=name, page=pagination.page - 1) }}">Previous</a>
|
||||||
|
</li>
|
||||||
|
{% for p in range(1, pagination.page + 1) %}
|
||||||
|
<li class="paginate_button{% if p == pagination.page %} active{% endif %}">
|
||||||
|
<a href="{{ url_for('.history', name=name, page=p) }}">{{ p }}</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
{% if pagination.more %}<li class="paginate_button disabled"><a>…</a></li>{% endif %}
|
||||||
|
<li class="paginate_button next{% if not pagination.more %} disabled{% endif %}">
|
||||||
|
<a href="{{ url_for('.history', name=name, page=pagination.page + 1) }}">Next</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</td></tr>
|
||||||
|
</tfoot>
|
||||||
|
{% endif %}
|
||||||
|
<tbody>
|
||||||
{% for h in history %}
|
{% for h in history %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="checkbox-cell text-center">
|
<td class="checkbox-cell text-center">
|
||||||
|
@ -27,23 +48,8 @@
|
||||||
<td>{{ h.time|datetime }}</td>
|
<td>{{ h.time|datetime }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<!-- TODO: make this pagination look good -->
|
|
||||||
{% if pagination.page > 1 or pagination.more %}
|
|
||||||
<div>
|
|
||||||
{% if pagination.page > 1 %}
|
|
||||||
<a href="{{ url_for('.history', name=name, page=pagination.page - 1) }}"><</a>
|
|
||||||
{% else %}
|
|
||||||
<
|
|
||||||
{% endif %}
|
|
||||||
{{ pagination.page }}
|
|
||||||
{% if pagination.more %}
|
|
||||||
<a href="{{ url_for('.history', name=name, page=pagination.page + 1) }}">></a>
|
|
||||||
{% else %}
|
|
||||||
>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
<p>
|
<p>
|
||||||
<a class="btn btn-default btn-sm compare-revisions">Compare Revisions</a>
|
<a class="btn btn-default btn-sm compare-revisions">Compare Revisions</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
Loading…
Reference in a new issue