Skip to content
Snippets Groups Projects
Commit ba17341b authored by Teemu Autto's avatar Teemu Autto
Browse files

untested: added pagination.

parent 31f86579
No related branches found
No related tags found
1 merge request!20Merge of the changes done in propaedeutic.
......@@ -22,12 +22,26 @@ def get_item(id):
abort(403)
@bp.route('/')
def index():
items = Item.objects.all()
@bp.route("/", defaults={'page': 1})
@bp.route("/items/<int:page>")
def index(page=1):
"""
Index page for items on sale.
Lists only items that are currently sale, with pagination.
"""
# Function used on propaedeutic
# items = Item.objects.all()
# Fetch items that are on sale currently, and paginate
# See: http://docs.mongoengine.org/projects/flask-mongoengine/en/latest/custom_queryset.html
items = Item.objects.filter(closes_at__gt=datetime.utcnow()) \
.order_by('-closes_at') \
.paginate(page=page, per_page=10)
return render_template('items/index.html',
items=items
)
items=items)
@bp.route('/sell', methods=('GET', 'POST'))
......
......@@ -9,34 +9,52 @@
{% block content %}
<table class="table">
<thead class="thead-light">
<tr>
<th>Title</th>
<th>Description</th>
<th>Starting Bid</th>
<th>Seller</th>
<th>Created At</th>
<th>Closed At</th>
</tr>
</thead>
<tbody>
{% for item in items %}
<tr>
<td>
{{ item.title }}
{% if g.user == item.seller %}
<a class="action btn btn-primary" href="{{ url_for('items.update', id=item['id']) }}">Edit</a>
{% endif %}
</td>
<td>{{ item.description }}</td>
<td>{{ item.starting_bid }}</td>
<td>{{ item.seller.email }}</td>
<td>{{ item.created_at }}</td>
<td>{{ item.closed_at }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="container">
<div class="row">
<div class="col-md-12">
<table class="table">
<thead class="thead-light">
<tr>
<th>Title</th>
<th>Description</th>
<th>Starting Bid</th>
<th>Seller</th>
<th>Created At</th>
<th>Closes At</th>
</tr>
</thead>
<tbody>
{% for item in items.items %}
<tr>
<td>
{{ item.title }}
{% if g.user == item.seller %}
<a class="action btn btn-primary" href="{{ url_for('items.update', id=item['id']) }}">Edit</a>
{% endif %}
</td>
<td>{{ item.description }}</td>
<td>{{ item.starting_bid }}</td>
<td>{{ item.seller.email }}</td>
<td>{{ item.created_at }}</td>
<td>{{ item.closes_at }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col-md-12">
<nav aria-label="Page navigation">
<ul class="pagination justify-content-center">
{% for page in items.iter_pages() %}
<li class="page-item {% if page == items.page %}active{% endif %}">
<a class="page-link" href="{{ url_for('items.index', page=page) }}">{{ page }}</a>
</li>
{% endfor %}
</ul>
</nav>
</div>
</div>
</div>
{% endblock %}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment