diff --git a/aurweb/routers/trusted_user.py b/aurweb/routers/trusted_user.py index fd5ebb04..61cfec6c 100644 --- a/aurweb/routers/trusted_user.py +++ b/aurweb/routers/trusted_user.py @@ -5,7 +5,6 @@ import typing from datetime import datetime from http import HTTPStatus -from urllib.parse import quote_plus from fastapi import APIRouter, Form, HTTPException, Request from fastapi.responses import RedirectResponse, Response @@ -106,12 +105,12 @@ async def trusted_user(request: Request, context["current_by_next"] = "asc" if current_by == "desc" else "desc" context["past_by_next"] = "asc" if past_by == "desc" else "desc" - context["q"] = '&'.join([ - f"coff={current_off}", - f"cby={quote_plus(current_by)}", - f"poff={past_off}", - f"pby={quote_plus(past_by)}" - ]) + context["q"] = { + "coff": current_off, + "cby": current_by, + "poff": past_off, + "pby": past_by + } return render_template(request, "tu/index.html", context) diff --git a/aurweb/templates.py b/aurweb/templates.py index 4a9927fb..6a1b6a1c 100644 --- a/aurweb/templates.py +++ b/aurweb/templates.py @@ -30,7 +30,6 @@ _env.filters["tn"] = l10n.tn # Utility filters. _env.filters["dt"] = util.timestamp_to_datetime _env.filters["as_timezone"] = util.as_timezone -_env.filters["dedupe_qs"] = util.dedupe_qs _env.filters["extend_query"] = util.extend_query _env.filters["urlencode"] = util.to_qs _env.filters["quote_plus"] = quote_plus diff --git a/aurweb/util.py b/aurweb/util.py index e993c440..f9181811 100644 --- a/aurweb/util.py +++ b/aurweb/util.py @@ -6,10 +6,9 @@ import re import secrets import string -from collections import OrderedDict from datetime import datetime from typing import Any, Dict -from urllib.parse import quote_plus, urlencode, urlparse +from urllib.parse import urlencode, urlparse from zoneinfo import ZoneInfo import fastapi @@ -126,31 +125,8 @@ def as_timezone(dt: datetime, timezone: str): return dt.astimezone(tz=ZoneInfo(timezone)) -def dedupe_qs(query_string: str, *additions): - """ Dedupe keys found in a query string by rewriting it without - duplicates found while iterating from the end to the beginning, - using an ordered memo to track keys found and persist locations. - - That is, query string 'a=1&b=1&a=2' will be deduped and converted - to 'b=1&a=2'. - - :param query_string: An HTTP URL query string. - :param *additions: Optional additional fields to add to the query string. - :return: Deduped query string, including *additions at the tail. - """ - for addition in list(additions): - query_string += f"&{addition}" - - qs = OrderedDict() - for item in reversed(query_string.split('&')): - key, value = item.split('=') - if key not in qs: - qs[key] = value - return '&'.join([f"{k}={quote_plus(v)}" for k, v in reversed(qs.items())]) - - def extend_query(query: Dict[str, Any], *additions) -> Dict[str, Any]: - """ Add additionally key value pairs to query. """ + """ Add additional key value pairs to query. """ for k, v in list(additions): query[k] = v return query diff --git a/templates/partials/tu/proposals.html b/templates/partials/tu/proposals.html index ab90444e..40eba22b 100644 --- a/templates/partials/tu/proposals.html +++ b/templates/partials/tu/proposals.html @@ -24,7 +24,7 @@