Skip to content

Commit

Permalink
Stop shadowing builtin 'id'.
Browse files Browse the repository at this point in the history
  • Loading branch information
liffiton committed Sep 2, 2024
1 parent 26ae424 commit 9a7836b
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 28 deletions.
8 changes: 4 additions & 4 deletions src/codehelp/tutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ def new_message(llm: LLMConfig) -> Response:

@register_admin_link("Tutor Chats")
@bp_admin.route("/tutor/")
@bp_admin.route("/tutor/<int:id>")
def tutor_admin(id : int|None = None) -> str:
@bp_admin.route("/tutor/<int:chat_id>")
def tutor_admin(chat_id : int|None = None) -> str:
db = get_db()
chats = db.execute("""
SELECT
Expand All @@ -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
Expand Down
22 changes: 11 additions & 11 deletions src/gened/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,29 +347,29 @@ def consumer_new() -> str:
return render_template("consumer_form.html", models=get_models())


@bp.route("/consumer/delete/<int:id>", methods=['POST'])
def consumer_delete(id: int) -> Response:
@bp.route("/consumer/delete/<int:consumer_id>", 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()

Expand All @@ -378,10 +378,10 @@ def consumer_delete(id: int) -> Response:
return redirect(url_for(".main"))


@bp.route("/consumer/<int:id>")
def consumer_form(id: int | None = None) -> str:
@bp.route("/consumer/<int:consumer_id>")
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())


Expand Down Expand Up @@ -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))
8 changes: 4 additions & 4 deletions src/gened/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ def demo_link_new() -> str:
return render_template("demo_link_form.html")


@bp_admin.route("/demo_link/<int:id>")
def demo_link_form(id: int) -> str:
@bp_admin.route("/demo_link/<int:demo_id>")
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)

Expand All @@ -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))
10 changes: 5 additions & 5 deletions src/gened/experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ def experiments_view() -> str:
def experiment_new() -> str:
return render_template("experiment_form.html")

@bp_admin.route("/experiment/<int:id>")
def experiment_form(id: int) -> str:
@bp_admin.route("/experiment/<int:exp_id>")
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)

Expand Down Expand Up @@ -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/<int:exp_id>", methods=['POST'])
def experiment_delete(exp_id: int) -> Response:
Expand Down
2 changes: 1 addition & 1 deletion src/gened/templates/admin_demo_link.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
{% block admin_body %}
<h1 class="is-size-3">Demo Links <a class="button is-light is-link is-small mt-2" href="{{url_for('admin.demo_link_new')}}">Create New</a></h1>
<div style="max-width: 50em;">
{{ 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"}]) }}
</div>
{% endblock %}
2 changes: 1 addition & 1 deletion src/gened/templates/admin_experiments.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h1 class="is-size-3">Experiments <a class="button is-light is-link is-small mt-
'experiments',
[('id', 'id'), ('name', 'name'), ('description', 'description'), ('classes', 'count', 'r')],
experiments,
extra_links=[{'text': "edit", 'handler': "admin.experiment_form", 'param': "id"}],
extra_links=[{'text': "edit", 'handler': "admin.experiment_form", 'param': "exp_id"}],
) }}
</div>
{% endblock %}
2 changes: 1 addition & 1 deletion src/gened/templates/admin_main.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ <h1 class="is-size-3">Consumers <a class="button is-light is-link is-small mt-2"
consumers,
link_col=0,
link_template=filters.template_string('consumer') | safe,
extra_links=[{'icon': "pencil", 'text': "Edit consumer", 'handler': "admin.consumer_form", 'param': "id"}],
extra_links=[{'icon': "pencil", 'text': "Edit consumer", 'handler': "admin.consumer_form", 'param': "consumer_id"}],
) }}
<h1 class="is-size-3">Classes</h1>
{{ datatable(
Expand Down
2 changes: 1 addition & 1 deletion src/gened/templates/consumer_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ <h1 class="title">New Consumer</h1>
<div class="control">
<button class="button is-link" type="submit">Submit</button>
{% if consumer %}
<button class="button is-danger" type="submit" formaction="{{ url_for('admin.consumer_delete', id=consumer.id) }}">
<button class="button is-danger" type="submit" formaction="{{ url_for('admin.consumer_delete', consumer_id=consumer.id) }}">
<span class="delete mr-2"></span>
Delete {{ consumer.lti_consumer }}
</button>
Expand Down

0 comments on commit 9a7836b

Please sign in to comment.