Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
TJTS5901 K23 Template
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Startuplab
Courses
TJTS5901 Continuous Software Engineering
TJTS5901 K23 Template
Commits
ba17341b
Commit
ba17341b
authored
2 years ago
by
Teemu Autto
Browse files
Options
Downloads
Patches
Plain Diff
untested: added pagination.
parent
31f86579
No related branches found
Branches containing commit
No related tags found
1 merge request
!20
Merge of the changes done in propaedeutic.
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/tjts5901/items.py
+19
-5
19 additions, 5 deletions
src/tjts5901/items.py
src/tjts5901/templates/items/index.html
+48
-30
48 additions, 30 deletions
src/tjts5901/templates/items/index.html
with
67 additions
and
35 deletions
src/tjts5901/items.py
+
19
−
5
View file @
ba17341b
...
...
@@ -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
'
))
...
...
This diff is collapsed.
Click to expand it.
src/tjts5901/templates/items/index.html
+
48
−
30
View file @
ba17341b
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment