diff options
| author | Dennis Fink | 2026-11-16 22:21:19 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-11-16 22:21:19 +0100 |
| commit | 354a5b449077478b141683bafbab47c9dc169d21 (patch) | |
| tree | b2d0be9cb848faf2f9944bb69a63f9fd9a857dbd /webmentions_ssg/forms | |
| parent | f7d846b66ae4286518ecc20537ba19c5afadf7f4 (diff) | |
| download | webmentions-ssg-354a5b449077478b141683bafbab47c9dc169d21.tar.gz webmentions-ssg-354a5b449077478b141683bafbab47c9dc169d21.zip | |
feat(receiver): add sorting and page size controls
Allow received Webmentions to be sorted by status, source, target,
received time, or updated time with stable pagination and accessible
sortable headers.
Add configurable per-page sizing and preserve sorting, filters, and page
size across pagination and administrative actions.
Diffstat (limited to '')
| -rw-r--r-- | webmentions_ssg/forms.py | 53 |
1 files changed, 41 insertions, 12 deletions
diff --git a/webmentions_ssg/forms.py b/webmentions_ssg/forms.py index d97cc69..ae969b3 100644 --- a/webmentions_ssg/forms.py +++ b/webmentions_ssg/forms.py @@ -12,6 +12,8 @@ from flask_wtf import FlaskForm from wtforms import ( DateField, Field, + HiddenField, + IntegerField, PasswordField, SearchField, SelectField, @@ -20,11 +22,25 @@ from wtforms import ( ValidationError, ) from wtforms.form import BaseForm -from wtforms.validators import InputRequired, Optional, StopValidation +from wtforms.validators import ( + AnyOf, + InputRequired, + NumberRange, + Optional, + StopValidation, +) from .net import is_public_address, normalized_hostname from .validation import is_control_character +RECEIVED_STATUS_CHOICES = { + "": "All statuses", + "pending": "Pending", + "verifying": "Verifying", + "verified": "Verified", + "declined": "Declined", +} + class MaxURLBytes: """Check the UTF-8 byte length of a submitted URL using the current config.""" @@ -186,25 +202,38 @@ class CanonicalDate: raise ValidationError(field.gettext("Invalid date.")) +def default_received_page_size() -> int: + """Use 25 rows unless the configured maximum is lower.""" + return min(25, current_app.config["RECEIVED_MAX_PAGE_SIZE"]) + + class ReceivedWebmentionFilterForm(FlaskForm): """GET filters for the received Webmention list.""" - status = SelectField( - "Status", - choices={ - "": "All statuses", - "pending": "Pending", - "verifying": "Verifying", - "verified": "Verified", - "declined": "Declined", - }, - default="", - ) + status = SelectField("Status", choices=RECEIVED_STATUS_CHOICES, default="") q = SearchField("Source or target") date_from = DateField( "Updated from (UTC)", validators=[Optional(), CanonicalDate()] ) date_to = DateField("Updated to (UTC)", validators=[Optional(), CanonicalDate()]) + sort = HiddenField( + default="received", + validators=[AnyOf(("received", "updated", "status", "source", "target"))], + ) + order = HiddenField(default="desc", validators=[AnyOf(("asc", "desc"))]) + per_page = IntegerField( + "Rows per page", + default=default_received_page_size, + validators=[NumberRange(min=1)], + ) + + def validate_per_page(self, field: IntegerField) -> None: + """Enforce the deployment's maximum received-list page size.""" + if ( + field.data is not None + and field.data > current_app.config["RECEIVED_MAX_PAGE_SIZE"] + ): + raise ValidationError("Rows per page exceeds the configured maximum.") def validate_date_to(self, field: DateField) -> None: """Require the end date to be on or after the start date.""" |
