Skip to content

Commit 7c8f447

Browse files
committed
INTEGRITY: Add configuration page with a feature to select items per page.
1 parent 8602689 commit 7c8f447

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

fileset.py

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
render_template_string,
77
jsonify,
88
render_template,
9+
make_response,
910
)
11+
1012
import pymysql.cursors
1113
import json
1214
import html as html_lib
@@ -139,6 +141,7 @@ def fileset():
139141
<a href="{{{{ url_for('ready_for_review') }}}}">Ready for review</a>
140142
<a href="{{{{ url_for('fileset_search') }}}}">Fileset Search</a>
141143
<a href="{{{{ url_for('logs') }}}}">Logs</a>
144+
<a href="{{{{ url_for('config') }}}}">Config</a>
142145
</div>
143146
</nav>
144147
<h2 style="margin-top: 80px;"><u>Fileset: {id}</u></h2>
@@ -502,6 +505,7 @@ def merge_fileset(id):
502505
<a href="{{{{ url_for('ready_for_review') }}}}">Ready for review</a>
503506
<a href="{{{{ url_for('fileset_search') }}}}">Fileset Search</a>
504507
<a href="{{{{ url_for('logs') }}}}">Logs</a>
508+
<a href="{{{{ url_for('config') }}}}">Config</a>
505509
</div>
506510
</nav>
507511
<h2 style="margin-top: 80px;">Search Results for '{search_query}'</h2>
@@ -549,6 +553,7 @@ def merge_fileset(id):
549553
<a href="{{ url_for('ready_for_review') }}">Ready for review</a>
550554
<a href="{{ url_for('fileset_search') }}">Fileset Search</a>
551555
<a href="{{ url_for('logs') }}">Logs</a>
556+
<a href="{{ url_for('config') }}">Config</a>
552557
</div>
553558
</nav>
554559
<h2 style="margin-top: 80px;">Search Fileset to Merge</h2>
@@ -616,6 +621,7 @@ def possible_merge_filesets(id):
616621
<a href="{{{{ url_for('ready_for_review') }}}}">Ready for review</a>
617622
<a href="{{{{ url_for('fileset_search') }}}}">Fileset Search</a>
618623
<a href="{{{{ url_for('logs') }}}}">Logs</a>
624+
<a href="{{{{ url_for('config') }}}}">Config</a>
619625
</div>
620626
</nav>
621627
<h2 style="margin-top: 80px;">Possible Merges for fileset-'{id}'</h2>
@@ -818,6 +824,7 @@ def highlight_differences(source, target):
818824
<a href="{{ url_for('ready_for_review') }}">Ready for review</a>
819825
<a href="{{ url_for('fileset_search') }}">Fileset Search</a>
820826
<a href="{{ url_for('logs') }}">Logs</a>
827+
<a href="{{ url_for('config') }}">Config</a>
821828
</div>
822829
</nav>
823830
<h2 style="margin-top: 80px;">Confirm Merge</h2>
@@ -1368,6 +1375,34 @@ def mark_as_full(id):
13681375
return redirect(f"/fileset?id={id}")
13691376

13701377

1378+
@app.route("/config", methods=["GET", "POST"])
1379+
def config():
1380+
"""
1381+
Stores the user configurations in the cookies
1382+
"""
1383+
if request.method == "POST":
1384+
items_per_page = request.form.get("items_per_page", "25")
1385+
1386+
try:
1387+
items_per_page_int = int(items_per_page)
1388+
if items_per_page_int < 1:
1389+
items_per_page = "1"
1390+
except ValueError:
1391+
items_per_page = "25"
1392+
1393+
resp = make_response(redirect(url_for("config")))
1394+
resp.set_cookie("items_per_page", items_per_page, max_age=365 * 24 * 60 * 60)
1395+
return resp
1396+
1397+
items_per_page = int(request.cookies.get("items_per_page", "25"))
1398+
1399+
return render_template("config.html", items_per_page=items_per_page)
1400+
1401+
1402+
def get_items_per_page():
1403+
return int(request.cookies.get("items_per_page", "25"))
1404+
1405+
13711406
@app.route("/validate", methods=["POST"])
13721407
def validate():
13731408
error_codes = {
@@ -1506,8 +1541,19 @@ def games_list():
15061541
"engine.id": "game.engine",
15071542
"game.id": "fileset.game",
15081543
}
1544+
1545+
items_per_page = get_items_per_page()
1546+
15091547
return render_template_string(
1510-
create_page(filename, 25, records_table, select_query, order, filters, mapping)
1548+
create_page(
1549+
filename,
1550+
items_per_page,
1551+
records_table,
1552+
select_query,
1553+
order,
1554+
filters,
1555+
mapping,
1556+
)
15111557
)
15121558

15131559

@@ -1524,8 +1570,11 @@ def logs():
15241570
"user": "log",
15251571
"text": "log",
15261572
}
1573+
items_per_page = get_items_per_page()
15271574
return render_template_string(
1528-
create_page(filename, 25, records_table, select_query, order, filters)
1575+
create_page(
1576+
filename, items_per_page, records_table, select_query, order, filters
1577+
)
15291578
)
15301579

15311580

@@ -1558,8 +1607,17 @@ def fileset_search():
15581607
"engine.id": "game.engine",
15591608
"fileset.id": "transactions.fileset",
15601609
}
1610+
items_per_page = get_items_per_page()
15611611
return render_template_string(
1562-
create_page(filename, 25, records_table, select_query, order, filters, mapping)
1612+
create_page(
1613+
filename,
1614+
items_per_page,
1615+
records_table,
1616+
select_query,
1617+
order,
1618+
filters,
1619+
mapping,
1620+
)
15631621
)
15641622

15651623

pagination.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def create_page(
155155
<a href="{{ url_for('ready_for_review') }}">Ready for review</a>
156156
<a href="{{ url_for('fileset_search') }}">Fileset Search</a>
157157
<a href="{{ url_for('logs') }}">Logs</a>
158+
<a href="{{ url_for('config') }}">Config</a>
158159
</div>
159160
</nav>
160161
<form id='filters-form' method='GET' onsubmit='remove_empty_inputs()'>

0 commit comments

Comments
 (0)