Nearly done rework of the whole application to add groups

This commit is contained in:
2026-07-11 22:06:18 -04:00
parent 8db9f3bd9f
commit d8a071a965
6 changed files with 251 additions and 136 deletions

View File

@@ -13,6 +13,16 @@ UPDATE buttons SET is_active = 1
WHERE button_name = ?
'''
find_buttons_for_group = r'''
SELECT * FROM buttons
WHERE page_group = ?
'''
find_groups_for_parent = r'''
SELECT * FROM groups
WHERE parent_group = ?
'''
with open("config.json", "r") as config_file:
config_json = json.loads(config_file.read())
@@ -36,8 +46,17 @@ def set_active_by_name(name):
@app.route("/")
def root_route():
with open("index.html", "r") as html_file:
db = get_db()
group = request.args.get(key="group", default="Home")
template = Template(html_file.read())
return template.render(config_json), 200
return template.render({
"instance_name": config_json["instance_name"],
"current_group": group,
"buttons": db.execute(find_buttons_for_group, [group]).fetchall(),
"groups": db.execute(find_groups_for_parent, [group]).fetchall()
}), 200
@app.route("/stream", methods=["POST"])
def stream_route():
@@ -51,16 +70,6 @@ def stream_route():
}
return jsonify(error_response), 400
resource_list = [element for element in config_json["buttons"] if element["name"] == body["name"]]
if(len(resource_list) == 0):
error_response = {
'status': "ERROR",
"reason": "The name {name} does not exist in config['buttons'], check your config".format(name = body["name"])
}
return jsonify(error_response), 400
db = get_db()
@@ -68,7 +77,7 @@ def stream_route():
db.execute(set_active_by_name_sql, [body["name"]])
db.commit()
return jsonify(resource_list[0]), 200
return jsonify(body["name"]), 200
else:
error_response = {
'status': 'ERROR',