Persist list sorting in session

This commit is contained in:
2022-07-15 11:18:39 -07:00
parent cff6d9cc50
commit 66777cfabc
2 changed files with 12 additions and 3 deletions

View File

@@ -54,7 +54,7 @@ test-x :
test-wip :
poetry run python -m pytest tests -m wip
.PHONY : css docker \
.PHONY : css docker docker-deploy \
db-init db-migrate db-upgrad db-downgrade \
lint shell serve \
requirements.txt requirements-dev.txt \

View File

@@ -12,6 +12,7 @@ from flask import (
redirect,
render_template,
request,
session,
url_for,
)
@@ -73,13 +74,21 @@ def detail(id):
if not sList:
raise NotFoundError(f'List {id} not found')
sortBy = request.args.get('sort', 'none')
sortStore = request.args.get('store', '')
# Load sorting from request (or session)
sSort = session.get(f'sorting-{id}', {})
sortBy = request.args.get('sort', sSort.get('sort', 'none'))
sortStore = request.args.get('store', sSort.get('store', ''))
if sortBy not in ('none', 'category', 'store'):
flash(f'Invalid sorting mode {sortBy}', 'warning')
sortBy = 'category'
# Store sorting back to the session
session[f'sorting-{id}'] = {
'sort': sortBy,
'store': sortStore,
}
groups = dict()
for e in sList.entries:
if sortBy == 'category':