aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-09-03 14:53:06 -0500
committerFrederick Muriuki Muriithi2024-09-03 15:09:32 -0500
commit2876fe6251bd4dfceef06f638ee74c2728ad1207 (patch)
tree771a9665761e1c43f03734700b89cf55d83c200e
parentcc39af629928d7f707bb36befb28f5f3386ddf3a (diff)
downloadgn-uploader-2876fe6251bd4dfceef06f638ee74c2728ad1207.tar.gz
Extract common UI pattern to separate module for reusability.
-rw-r--r--uploader/species/views.py15
-rw-r--r--uploader/ui.py13
2 files changed, 16 insertions, 12 deletions
diff --git a/uploader/species/views.py b/uploader/species/views.py
index 6009f03..6f4d51f 100644
--- a/uploader/species/views.py
+++ b/uploader/species/views.py
@@ -4,9 +4,9 @@ from flask import (flash,
url_for,
redirect,
Blueprint,
- current_app as app,
- render_template as flask_render_template)
+ current_app as app)
+from uploader.ui import make_template_renderer
from uploader.authorisation import require_login
from uploader.db_utils import database_connection
@@ -14,16 +14,7 @@ from .models import all_species, save_species, species_by_id
speciesbp = Blueprint("species", __name__)
-
-
-def render_template(template, **kwargs):
- """Render template for species."""
- return flask_render_template(
- template,
- **{
- **kwargs,
- "activelink": kwargs.get("activelink", "species")
- })
+render_template = make_template_renderer("species")
@speciesbp.route("/", methods=["GET"])
diff --git a/uploader/ui.py b/uploader/ui.py
new file mode 100644
index 0000000..4115b02
--- /dev/null
+++ b/uploader/ui.py
@@ -0,0 +1,13 @@
+"""Utilities to handle the UI"""
+from flask import render_template as flask_render_template
+
+def make_template_renderer(default):
+ """Render template for species."""
+ def render_template(template, **kwargs):
+ return flask_render_template(
+ template,
+ **{
+ **kwargs,
+ "activelink": kwargs.get("activelink", default)
+ })
+ return render_template