From 9a7836b00d4dcc7e3e52a9f4cecb0961cd49bf1c Mon Sep 17 00:00:00 2001 From: Mark Liffiton Date: Sun, 1 Sep 2024 23:16:44 -0500 Subject: [PATCH] Stop shadowing builtin 'id'. --- src/codehelp/tutor.py | 8 ++++---- src/gened/admin.py | 22 +++++++++++----------- src/gened/demo.py | 8 ++++---- src/gened/experiments.py | 10 +++++----- src/gened/templates/admin_demo_link.html | 2 +- src/gened/templates/admin_experiments.html | 2 +- src/gened/templates/admin_main.html | 2 +- src/gened/templates/consumer_form.html | 2 +- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/codehelp/tutor.py b/src/codehelp/tutor.py index 5aaeebe..d7ac882 100644 --- a/src/codehelp/tutor.py +++ b/src/codehelp/tutor.py @@ -291,8 +291,8 @@ def new_message(llm: LLMConfig) -> Response: @register_admin_link("Tutor Chats") @bp_admin.route("/tutor/") -@bp_admin.route("/tutor/") -def tutor_admin(id : int|None = None) -> str: +@bp_admin.route("/tutor/") +def tutor_admin(chat_id : int|None = None) -> str: db = get_db() chats = db.execute(""" SELECT @@ -315,8 +315,8 @@ def tutor_admin(id : int|None = None) -> str: chats.id DESC """).fetchall() - if id is not None: - chat_row = db.execute("SELECT users.display_name, topic, chat_json FROM chats JOIN users ON chats.user_id=users.id WHERE chats.id=?", [id]).fetchone() + if chat_id is not None: + chat_row = db.execute("SELECT users.display_name, topic, chat_json FROM chats JOIN users ON chats.user_id=users.id WHERE chats.id=?", [chat_id]).fetchone() chat = json.loads(chat_row['chat_json']) else: chat_row = None diff --git a/src/gened/admin.py b/src/gened/admin.py index f9ac833..d72bbd2 100644 --- a/src/gened/admin.py +++ b/src/gened/admin.py @@ -347,29 +347,29 @@ def consumer_new() -> str: return render_template("consumer_form.html", models=get_models()) -@bp.route("/consumer/delete/", methods=['POST']) -def consumer_delete(id: int) -> Response: +@bp.route("/consumer/delete/", methods=['POST']) +def consumer_delete(consumer_id: int) -> Response: db = get_db() # Check for dependencies - classes_count = db.execute("SELECT COUNT(*) FROM classes_lti WHERE lti_consumer_id=?", [id]).fetchone()[0] + classes_count = db.execute("SELECT COUNT(*) FROM classes_lti WHERE lti_consumer_id=?", [consumer_id]).fetchone()[0] if classes_count > 0: flash("Cannot delete consumer: there are related classes.", "warning") - return redirect(url_for(".consumer_form", id=id)) + return redirect(url_for(".consumer_form", consumer_id=consumer_id)) # No dependencies, proceed with deletion # Fetch the consumer's name - consumer_name_row = db.execute("SELECT lti_consumer FROM consumers WHERE id=?", [id]).fetchone() + consumer_name_row = db.execute("SELECT lti_consumer FROM consumers WHERE id=?", [consumer_id]).fetchone() if not consumer_name_row: flash("Invalid id.", "danger") - return redirect(url_for(".consumer_form", id=id)) + return redirect(url_for(".consumer_form", consumer_id=consumer_id)) consumer_name = consumer_name_row['lti_consumer'] # Delete the row - db.execute("DELETE FROM consumers WHERE id=?", [id]) + db.execute("DELETE FROM consumers WHERE id=?", [consumer_id]) db.commit() reload_consumers() @@ -378,10 +378,10 @@ def consumer_delete(id: int) -> Response: return redirect(url_for(".main")) -@bp.route("/consumer/") -def consumer_form(id: int | None = None) -> str: +@bp.route("/consumer/") +def consumer_form(consumer_id: int | None = None) -> str: db = get_db() - consumer_row = db.execute("SELECT * FROM consumers WHERE id=?", [id]).fetchone() + consumer_row = db.execute("SELECT * FROM consumers WHERE id=?", [consumer_id]).fetchone() return render_template("consumer_form.html", consumer=consumer_row, models=get_models()) @@ -423,4 +423,4 @@ def consumer_update() -> Response: # anything might have changed: reload all consumers reload_consumers() - return redirect(url_for(".consumer_form", id=consumer_id)) + return redirect(url_for(".consumer_form", consumer_id=consumer_id)) diff --git a/src/gened/demo.py b/src/gened/demo.py index a5078f4..a2cbaeb 100644 --- a/src/gened/demo.py +++ b/src/gened/demo.py @@ -91,10 +91,10 @@ def demo_link_new() -> str: return render_template("demo_link_form.html") -@bp_admin.route("/demo_link/") -def demo_link_form(id: int) -> str: +@bp_admin.route("/demo_link/") +def demo_link_form(demo_id: int) -> str: db = get_db() - demo_link_row = db.execute("SELECT * FROM demo_links WHERE id=?", [id]).fetchone() + demo_link_row = db.execute("SELECT * FROM demo_links WHERE id=?", [demo_id]).fetchone() demo_link_url = f"/demo/{demo_link_row['name']}" return render_template("demo_link_form.html", demo_link=demo_link_row, demo_link_url=demo_link_url) @@ -120,4 +120,4 @@ def demo_link_update() -> Response: db.commit() flash("Demo link updated.") - return redirect(url_for(".demo_link_form", id=demo_link_id)) + return redirect(url_for(".demo_link_form", demo_id=demo_link_id)) diff --git a/src/gened/experiments.py b/src/gened/experiments.py index 49dd2fd..9abf343 100644 --- a/src/gened/experiments.py +++ b/src/gened/experiments.py @@ -64,13 +64,13 @@ def experiments_view() -> str: def experiment_new() -> str: return render_template("experiment_form.html") -@bp_admin.route("/experiment/") -def experiment_form(id: int) -> str: +@bp_admin.route("/experiment/") +def experiment_form(exp_id: int) -> str: db = get_db() - experiment = db.execute("SELECT * FROM experiments WHERE id=?", [id]).fetchone() + experiment = db.execute("SELECT * FROM experiments WHERE id=?", [exp_id]).fetchone() classes = db.execute("SELECT id, name FROM classes ORDER BY name").fetchall() classes = [dict(row) for row in classes] # so we can tojson it in the template - assigned_classes = db.execute("SELECT class_id AS id, classes.name FROM experiment_class JOIN classes ON experiment_class.class_id=classes.id WHERE experiment_id=? ORDER BY name", [id]).fetchall() + assigned_classes = db.execute("SELECT class_id AS id, classes.name FROM experiment_class JOIN classes ON experiment_class.class_id=classes.id WHERE experiment_id=? ORDER BY name", [exp_id]).fetchall() assigned_classes = [dict(row) for row in assigned_classes] return render_template("experiment_form.html", experiment=experiment, classes=classes, assigned_classes=assigned_classes) @@ -101,7 +101,7 @@ def experiment_update() -> Response: [exp_id, class_id]) db.commit() - return redirect(url_for(".experiment_form", id=exp_id)) + return redirect(url_for(".experiment_form", exp_id=exp_id)) @bp_admin.route("/experiment/delete/", methods=['POST']) def experiment_delete(exp_id: int) -> Response: diff --git a/src/gened/templates/admin_demo_link.html b/src/gened/templates/admin_demo_link.html index f405eaf..62b16dd 100644 --- a/src/gened/templates/admin_demo_link.html +++ b/src/gened/templates/admin_demo_link.html @@ -10,6 +10,6 @@ {% block admin_body %}

Demo Links Create New

- {{ datatable('demo_links', [('id', 'id'), ('name', 'name'), ('expiration', 'expiration'), ('tokens', 'tokens', 'r'), ('enabled', 'enabled', 'r'), ('uses', 'uses', 'r')], demo_links, extra_links=[{'text': "edit", 'handler': "admin.demo_link_form", 'param': "id"}]) }} + {{ datatable('demo_links', [('id', 'id'), ('name', 'name'), ('expiration', 'expiration'), ('tokens', 'tokens', 'r'), ('enabled', 'enabled', 'r'), ('uses', 'uses', 'r')], demo_links, extra_links=[{'text': "edit", 'handler': "admin.demo_link_form", 'param': "demo_id"}]) }}
{% endblock %} diff --git a/src/gened/templates/admin_experiments.html b/src/gened/templates/admin_experiments.html index 9eb177a..f9ae5fb 100644 --- a/src/gened/templates/admin_experiments.html +++ b/src/gened/templates/admin_experiments.html @@ -14,7 +14,7 @@

Experiments {% endblock %} diff --git a/src/gened/templates/admin_main.html b/src/gened/templates/admin_main.html index 9d7b985..01d4fdb 100644 --- a/src/gened/templates/admin_main.html +++ b/src/gened/templates/admin_main.html @@ -51,7 +51,7 @@

Consumers Classes

{{ datatable( diff --git a/src/gened/templates/consumer_form.html b/src/gened/templates/consumer_form.html index 8b4dd21..ce4585a 100644 --- a/src/gened/templates/consumer_form.html +++ b/src/gened/templates/consumer_form.html @@ -111,7 +111,7 @@

New Consumer

{% if consumer %} -