working pagination only with urls

This commit is contained in:
deflax 2018-03-25 02:15:29 +02:00
parent 635e972cd1
commit 8efe280735
3 changed files with 14 additions and 20 deletions

View file

@ -1,7 +1,6 @@
from flask import render_template, abort, redirect, url_for, abort, flash, request, current_app, make_response, g
from flask_login import fresh_login_required, login_user, logout_user
from flask_sqlalchemy import get_debug_queries
from flask_paginate import Pagination, get_page_parameter
from . import admin
from .forms import ChargeForm, Addr2PoolForm, OrderForm
@ -72,19 +71,13 @@ def list_archive():
domains = Domain.query.filter_by(deleted=True).all()
return render_template('admin/list_archive.html', deployments=deployments, services=services, domains=domains)
@admin.route("/listusers", methods=['GET'])
@admin.route("/listusers/", defaults={'page': 1})
@admin.route("/listusers/<int:page>", methods=['GET'])
@fresh_login_required
@admin_required
def list_users():
search = False
q = request.args.get('q')
if q:
search = True
page = request.args.get(get_page_parameter(), type=int, default=1)
per_page = 20
sqlitems = User.query.filter_by(active=True).order_by(User.last_seen.desc()).all()
pagination = Pagination(page=page, per_page=per_page, format_total=True, format_number=True, total=len(sqlitems), search=search, css_framework='foundation', record_name='users')
return render_template('admin/list_users.html', users=sqlitems, page=page, per_page=per_page, pagination=pagination)
def list_users(page):
sqlquery = User.query.filter_by(active=True).order_by(User.last_seen.desc()).paginate(page, current_app.config['ITEMS_PER_PAGE'], error_out=False)
return render_template('admin/list_users.html', users=sqlquery.items, page=page)
@admin.route("/charge/<int:user_pid>", methods=['GET', 'POST'])
@fresh_login_required
@ -146,12 +139,13 @@ def list_servers():
allservers = Server.query.all()
return render_template('admin/list_servers.html', servers=allservers)
@admin.route("/listtransactions", methods=['GET'])
@admin.route("/listtransactions/", defaults={'page': 1})
@admin.route("/listtransactions/<int:page>", methods=['GET'])
@fresh_login_required
@admin_required
def list_transactions():
alltransactions = Transaction.query.order_by(Transaction.date_created.desc()).all()
return render_template('admin/list_transactions.html', transactions=alltransactions)
def list_transactions(page):
sqlquery = Transaction.query.order_by(Transaction.date_created.desc()).paginate(page, current_app.config['ITEMS_PER_PAGE'], error_out=False)
return render_template('admin/list_transactions.html', transactions=sqlquery.items, page=page)
@admin.route("/transaction/<int:user_pid>", methods=['GET'])
@fresh_login_required

View file

@ -42,6 +42,8 @@
</tbody>
{% endfor %}
</table>
{% if transactions.has_prev %}<a href="{{ url_for('view', page=transactions.prev_num) }}">&lt;&lt; Previous</a>{% else %}&lt;&lt; Previous{% endif %} |
{% if transactions.has_next %}<a href="{{ url_for('view', page=transactions.next_num) }}">Next &gt;&gt;</a>{% else %}Next &gt;&gt;{% endif %}
</div>
</div>

View file

@ -9,8 +9,6 @@
<div class="panel-heading">List Active Users</div>
<div class="panel-body"><p>
<div class="no-more-tables">
{{ pagination.info }}
{{ pagination.links }}
<table class="table table-hover table-striped table-condensed cf">
<thead>
<tr>
@ -24,7 +22,6 @@
</thead>
<tbody>
{% for usr in users %}
{% set rowloop = loop %}
<tr>
<td data-title="Email"><font {% if usr.is_administrator() == True %}color="red"{% endif %}>{{ usr.email }}</td>
<td data-title="Last Seen">{{ moment(usr.last_seen).format('lll') }}</td>
@ -38,7 +35,8 @@
{% endfor %}
</tbody>
</table>
{{ pagination.links }}
{% if users.has_prev %}<a href="{{ url_for('view', page=users.prev_num) }}">&lt;&lt; Previous</a>{% else %}&lt;&lt; Previous{% endif %} |
{% if users.has_next %}<a href="{{ url_for('view', page=users.next_num) }}">Next &gt;&gt;</a>{% else %}Next &gt;&gt;{% endif %}
</div>
</div>
</div>