Skip to content

Commit

Permalink
v2: redirect to "canonical" shorter filter URL. #318
Browse files Browse the repository at this point in the history
  • Loading branch information
lemon24 committed Jan 25, 2025
1 parent 6ca4ae4 commit 83b9348
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/reader/_app/v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from flask import current_app
from flask import redirect
from flask import request
from flask import url_for
from jinja2_fragments.flask import render_block

from .. import get_reader
Expand All @@ -26,6 +27,10 @@ def entries():
# TODO: read time

form = EntryFilter(request.args)

if form.args != request.args.to_dict():
return redirect(url_for('.entries', **form.args))

kwargs = dict(form.data)
del kwargs['search']

Expand Down
9 changes: 9 additions & 0 deletions src/reader/_app/v2/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ def presets(self):
def active_presets(self):
return [p for p in self.presets if p.active]

@property
def args(self):
rv = {}
for field in self:
value = get_formdata(field)
if value and (not field.default or value != field.default):
rv[field.name] = value
return rv


@dataclass
class Preset:
Expand Down

0 comments on commit 83b9348

Please sign in to comment.