aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/views/admin.py
diff options
context:
space:
mode:
authorDennis Fink2026-11-13 21:20:40 +0100
committerDennis Fink2026-11-13 21:20:40 +0100
commita285fdf29e59c3b957247ea9241943c7202e9a28 (patch)
tree17ceeb703de23af1e67081d99a8864bbe353fb46 /webmentions_ssg/views/admin.py
parent78ecd8bc227bdcbbd0e45eea025f7223252ed0da (diff)
downloadwebmentions-ssg-a285fdf29e59c3b957247ea9241943c7202e9a28.tar.gz
webmentions-ssg-a285fdf29e59c3b957247ea9241943c7202e9a28.zip
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.
Diffstat (limited to 'webmentions_ssg/views/admin.py')
-rw-r--r--webmentions_ssg/views/admin.py21
1 files changed, 5 insertions, 16 deletions
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