From a285fdf29e59c3b957247ea9241943c7202e9a28 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 13 Nov 2026 21:20:40 +0100 Subject: refactor(core): consolidate repeated helper logic Centralize SQL row counts, hostname parsing, and content-type normalization so tasks, forms, and scanners share consistent implementations. Simplify periodic task registration and admin lookups with table-driven setup and Flask-SQLAlchemy's built-in 404 helper. --- webmentions_ssg/views/admin.py | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'webmentions_ssg/views/admin.py') diff --git a/webmentions_ssg/views/admin.py b/webmentions_ssg/views/admin.py index 1ca06b5..794bcdf 100644 --- a/webmentions_ssg/views/admin.py +++ b/webmentions_ssg/views/admin.py @@ -54,10 +54,7 @@ def delete_received_webmention(identifier: uuid.UUID) -> ResponseReturnValue: if not form.validate_on_submit(): abort(400) - webmention = db.session.get(ReceivedWebmention, identifier) - - if webmention is None: - abort(404) + webmention = db.get_or_404(ReceivedWebmention, identifier) db.session.delete(webmention) db.session.commit() @@ -84,10 +81,7 @@ def reverify_received_webmention(identifier: uuid.UUID) -> ResponseReturnValue: if not form.validate_on_submit(): abort(400) - webmention = db.session.get(ReceivedWebmention, identifier) - - if webmention is None: - abort(404) + webmention = db.get_or_404(ReceivedWebmention, identifier) webmention.reset_for_verification() @@ -145,12 +139,7 @@ def sent_source(source_identifier: uuid.UUID) -> ResponseReturnValue: :param source_identifier: Identifier of the source to display. :return: Rendered source details page. """ - source = db.session.scalar( - sa.select(Source).where(Source.uuid == source_identifier) - ) - - if source is None: - abort(404) + source = db.get_or_404(Source, source_identifier) webmentions = db.paginate( sa.select(SentWebmention) @@ -189,9 +178,9 @@ def resend_sent_webmention( if not form.validate_on_submit(): abort(400) - webmention = db.session.get(SentWebmention, webmention_identifier) + webmention = db.get_or_404(SentWebmention, webmention_identifier) - if webmention is None or webmention.source_id != source_identifier: + if webmention.source_id != source_identifier: abort(404) # Requeue the existing desired revision instead of inventing a new source -- cgit v1.3.1