Persist list sorting in session
This commit is contained in:
2
Makefile
2
Makefile
@@ -54,7 +54,7 @@ test-x :
|
|||||||
test-wip :
|
test-wip :
|
||||||
poetry run python -m pytest tests -m 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 \
|
db-init db-migrate db-upgrad db-downgrade \
|
||||||
lint shell serve \
|
lint shell serve \
|
||||||
requirements.txt requirements-dev.txt \
|
requirements.txt requirements-dev.txt \
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from flask import (
|
|||||||
redirect,
|
redirect,
|
||||||
render_template,
|
render_template,
|
||||||
request,
|
request,
|
||||||
|
session,
|
||||||
url_for,
|
url_for,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -73,13 +74,21 @@ def detail(id):
|
|||||||
if not sList:
|
if not sList:
|
||||||
raise NotFoundError(f'List {id} not found')
|
raise NotFoundError(f'List {id} not found')
|
||||||
|
|
||||||
sortBy = request.args.get('sort', 'none')
|
# Load sorting from request (or session)
|
||||||
sortStore = request.args.get('store', '')
|
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'):
|
if sortBy not in ('none', 'category', 'store'):
|
||||||
flash(f'Invalid sorting mode {sortBy}', 'warning')
|
flash(f'Invalid sorting mode {sortBy}', 'warning')
|
||||||
sortBy = 'category'
|
sortBy = 'category'
|
||||||
|
|
||||||
|
# Store sorting back to the session
|
||||||
|
session[f'sorting-{id}'] = {
|
||||||
|
'sort': sortBy,
|
||||||
|
'store': sortStore,
|
||||||
|
}
|
||||||
|
|
||||||
groups = dict()
|
groups = dict()
|
||||||
for e in sList.entries:
|
for e in sList.entries:
|
||||||
if sortBy == 'category':
|
if sortBy == 'category':
|
||||||
|
|||||||
Reference in New Issue
Block a user