Branchen dazugegeben
This commit is contained in:
parent
8499c9f60d
commit
b4ea78ec3b
214
app.py
214
app.py
@ -38,6 +38,18 @@ from db import (
|
|||||||
delete_question,
|
delete_question,
|
||||||
activate_user,
|
activate_user,
|
||||||
delete_user,
|
delete_user,
|
||||||
|
get_all_branchen,
|
||||||
|
get_branche_by_id,
|
||||||
|
get_thema_ids_for_branche,
|
||||||
|
create_branche,
|
||||||
|
update_branche,
|
||||||
|
delete_branche,
|
||||||
|
get_all_branchen,
|
||||||
|
get_branche_ids_for_thema,
|
||||||
|
get_all_branchen,
|
||||||
|
get_themen_for_branche,
|
||||||
|
get_next_thema_id_for_branche,
|
||||||
|
get_thema_for_branche,
|
||||||
)
|
)
|
||||||
from permissions import admin_required, login_required
|
from permissions import admin_required, login_required
|
||||||
from tools import create_assessment_chart, generate_activation_token, send_mail, verify_activation_token
|
from tools import create_assessment_chart, generate_activation_token, send_mail, verify_activation_token
|
||||||
@ -165,11 +177,26 @@ def logout():
|
|||||||
return redirect(url_for("login"))
|
return redirect(url_for("login"))
|
||||||
|
|
||||||
|
|
||||||
@app.route("/dashboard")
|
@app.route("/dashboard", methods=["GET", "POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def dashboard():
|
def dashboard():
|
||||||
themen = get_all_themen()
|
branchen = get_all_branchen()
|
||||||
return render_template("dashboard.html", themen=themen)
|
|
||||||
|
if request.method == "POST":
|
||||||
|
branche_id = request.form.get("branche_id")
|
||||||
|
|
||||||
|
if not branche_id:
|
||||||
|
flash("Bitte wählen Sie eine Branche aus.", "warning")
|
||||||
|
return render_template("dashboard.html", branchen=branchen)
|
||||||
|
|
||||||
|
themen = get_themen_for_branche(branche_id)
|
||||||
|
if not themen:
|
||||||
|
flash("Für diese Branche sind aktuell keine Themen hinterlegt.", "warning")
|
||||||
|
return render_template("dashboard.html", branchen=branchen)
|
||||||
|
|
||||||
|
return redirect(url_for("topic", thema_id=themen[0]["id"], branche_id=branche_id))
|
||||||
|
|
||||||
|
return render_template("dashboard.html", branchen=branchen)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/profil", methods=["GET", "POST"])
|
@app.route("/profil", methods=["GET", "POST"])
|
||||||
@ -193,9 +220,21 @@ def profile():
|
|||||||
@app.route("/thema/<int:thema_id>", methods=["GET", "POST"])
|
@app.route("/thema/<int:thema_id>", methods=["GET", "POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def topic(thema_id):
|
def topic(thema_id):
|
||||||
thema = get_thema_by_id(thema_id)
|
branche_id = request.values.get("branche_id")
|
||||||
|
|
||||||
|
if not branche_id:
|
||||||
|
flash("Bitte starten Sie das Assessment über die Startseite.", "warning")
|
||||||
|
return redirect(url_for("dashboard"))
|
||||||
|
|
||||||
|
try:
|
||||||
|
branche_id = int(branche_id)
|
||||||
|
except ValueError:
|
||||||
|
flash("Ungültige Branche.", "danger")
|
||||||
|
return redirect(url_for("dashboard"))
|
||||||
|
|
||||||
|
thema = get_thema_for_branche(thema_id, branche_id)
|
||||||
if not thema:
|
if not thema:
|
||||||
flash("Thema nicht gefunden.", "danger")
|
flash("Thema nicht gefunden oder nicht für diese Branche freigegeben.", "danger")
|
||||||
return redirect(url_for("dashboard"))
|
return redirect(url_for("dashboard"))
|
||||||
|
|
||||||
fragen = get_thema_questions(thema_id)
|
fragen = get_thema_questions(thema_id)
|
||||||
@ -217,6 +256,7 @@ def topic(thema_id):
|
|||||||
fragen=fragen,
|
fragen=fragen,
|
||||||
ansprechpartner=ansprechpartner,
|
ansprechpartner=ansprechpartner,
|
||||||
assessment_id=assessment_id,
|
assessment_id=assessment_id,
|
||||||
|
branche_id=branche_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
save_assessment_answer(
|
save_assessment_answer(
|
||||||
@ -226,11 +266,24 @@ def topic(thema_id):
|
|||||||
antwort=(value == "ja"),
|
antwort=(value == "ja"),
|
||||||
)
|
)
|
||||||
|
|
||||||
next_thema_id = get_next_thema_id(thema_id)
|
next_thema_id = get_next_thema_id_for_branche(thema_id, branche_id)
|
||||||
if next_thema_id:
|
if next_thema_id:
|
||||||
return redirect(url_for("topic", thema_id=next_thema_id, assessment_id=assessment_id))
|
return redirect(
|
||||||
|
url_for(
|
||||||
|
"topic",
|
||||||
|
thema_id=next_thema_id,
|
||||||
|
assessment_id=assessment_id,
|
||||||
|
branche_id=branche_id,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return redirect(url_for("assessment_result", assessment_id=assessment_id))
|
return redirect(
|
||||||
|
url_for(
|
||||||
|
"assessment_result",
|
||||||
|
assessment_id=assessment_id,
|
||||||
|
branche_id=branche_id,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
assessment_id = request.args.get("assessment_id", "")
|
assessment_id = request.args.get("assessment_id", "")
|
||||||
return render_template(
|
return render_template(
|
||||||
@ -239,24 +292,42 @@ def topic(thema_id):
|
|||||||
fragen=fragen,
|
fragen=fragen,
|
||||||
ansprechpartner=ansprechpartner,
|
ansprechpartner=ansprechpartner,
|
||||||
assessment_id=assessment_id,
|
assessment_id=assessment_id,
|
||||||
|
branche_id=branche_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/assessment/<int:assessment_id>/result")
|
@app.route("/assessment/<int:assessment_id>/result")
|
||||||
@login_required
|
@login_required
|
||||||
def assessment_result(assessment_id):
|
def assessment_result(assessment_id):
|
||||||
rows = get_assessment_result_rows(assessment_id)
|
branche_id = request.args.get("branche_id")
|
||||||
|
|
||||||
|
if not branche_id:
|
||||||
|
flash("Branche fehlt für die Auswertung.", "warning")
|
||||||
|
return redirect(url_for("dashboard"))
|
||||||
|
|
||||||
|
try:
|
||||||
|
branche_id = int(branche_id)
|
||||||
|
except ValueError:
|
||||||
|
flash("Ungültige Branche.", "danger")
|
||||||
|
return redirect(url_for("dashboard"))
|
||||||
|
|
||||||
|
rows = get_assessment_result_rows(assessment_id, branche_id)
|
||||||
|
|
||||||
|
if not rows:
|
||||||
|
flash("Für diese Branche konnten keine Auswertungsdaten geladen werden.", "warning")
|
||||||
|
return redirect(url_for("dashboard"))
|
||||||
|
|
||||||
labels = [row["kurztitel"] for row in rows]
|
labels = [row["kurztitel"] for row in rows]
|
||||||
values = [int(row["ja_anzahl"]) for row in rows]
|
values = [int(row["ja_anzahl"]) for row in rows]
|
||||||
|
|
||||||
filename = f"assessment_{assessment_id}.png"
|
filename = f"assessment_{assessment_id}_branche_{branche_id}.png"
|
||||||
output_path = chart_dir / filename
|
output_path = chart_dir / filename
|
||||||
create_assessment_chart(labels, values, output_path)
|
create_assessment_chart(labels, values, output_path)
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"result.html",
|
"result.html",
|
||||||
assessment_id=assessment_id,
|
assessment_id=assessment_id,
|
||||||
|
branche_id=branche_id,
|
||||||
chart_file=filename,
|
chart_file=filename,
|
||||||
rows=rows,
|
rows=rows,
|
||||||
)
|
)
|
||||||
@ -292,6 +363,7 @@ def admin_themen():
|
|||||||
@admin_required
|
@admin_required
|
||||||
def admin_thema_new():
|
def admin_thema_new():
|
||||||
ansprechpartner = get_all_ansprechpartner()
|
ansprechpartner = get_all_ansprechpartner()
|
||||||
|
branchen = get_all_branchen()
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
kurztitel = request.form.get("kurztitel", "").strip()
|
kurztitel = request.form.get("kurztitel", "").strip()
|
||||||
@ -299,6 +371,7 @@ def admin_thema_new():
|
|||||||
infotext = request.form.get("infotext", "").strip()
|
infotext = request.form.get("infotext", "").strip()
|
||||||
zusatztext = request.form.get("zusatztext", "").strip()
|
zusatztext = request.form.get("zusatztext", "").strip()
|
||||||
ansprechpartner_ids = [int(x) for x in request.form.getlist("ansprechpartner_ids")]
|
ansprechpartner_ids = [int(x) for x in request.form.getlist("ansprechpartner_ids")]
|
||||||
|
branche_ids = [int(x) for x in request.form.getlist("branche_ids")]
|
||||||
|
|
||||||
if not kurztitel or not titel:
|
if not kurztitel or not titel:
|
||||||
flash("Kurztitel und Titel sind Pflichtfelder.", "error")
|
flash("Kurztitel und Titel sind Pflichtfelder.", "error")
|
||||||
@ -307,10 +380,19 @@ def admin_thema_new():
|
|||||||
mode="new",
|
mode="new",
|
||||||
thema=request.form,
|
thema=request.form,
|
||||||
ansprechpartner=ansprechpartner,
|
ansprechpartner=ansprechpartner,
|
||||||
|
branchen=branchen,
|
||||||
selected_ansprechpartner_ids=ansprechpartner_ids,
|
selected_ansprechpartner_ids=ansprechpartner_ids,
|
||||||
|
selected_branche_ids=branche_ids,
|
||||||
)
|
)
|
||||||
|
|
||||||
create_thema(kurztitel, titel, infotext, zusatztext, ansprechpartner_ids)
|
create_thema(
|
||||||
|
kurztitel,
|
||||||
|
titel,
|
||||||
|
infotext,
|
||||||
|
zusatztext,
|
||||||
|
ansprechpartner_ids,
|
||||||
|
branche_ids,
|
||||||
|
)
|
||||||
flash("Thema wurde erstellt.", "success")
|
flash("Thema wurde erstellt.", "success")
|
||||||
return redirect(url_for("admin_themen"))
|
return redirect(url_for("admin_themen"))
|
||||||
|
|
||||||
@ -319,10 +401,11 @@ def admin_thema_new():
|
|||||||
mode="new",
|
mode="new",
|
||||||
thema={},
|
thema={},
|
||||||
ansprechpartner=ansprechpartner,
|
ansprechpartner=ansprechpartner,
|
||||||
|
branchen=branchen,
|
||||||
selected_ansprechpartner_ids=[],
|
selected_ansprechpartner_ids=[],
|
||||||
|
selected_branche_ids=[],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/admin/themen/<int:thema_id>/edit", methods=["GET", "POST"])
|
@app.route("/admin/themen/<int:thema_id>/edit", methods=["GET", "POST"])
|
||||||
@admin_required
|
@admin_required
|
||||||
def admin_thema_edit(thema_id):
|
def admin_thema_edit(thema_id):
|
||||||
@ -332,6 +415,7 @@ def admin_thema_edit(thema_id):
|
|||||||
return redirect(url_for("admin_themen"))
|
return redirect(url_for("admin_themen"))
|
||||||
|
|
||||||
ansprechpartner = get_all_ansprechpartner()
|
ansprechpartner = get_all_ansprechpartner()
|
||||||
|
branchen = get_all_branchen()
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
kurztitel = request.form.get("kurztitel", "").strip()
|
kurztitel = request.form.get("kurztitel", "").strip()
|
||||||
@ -339,6 +423,7 @@ def admin_thema_edit(thema_id):
|
|||||||
infotext = request.form.get("infotext", "").strip()
|
infotext = request.form.get("infotext", "").strip()
|
||||||
zusatztext = request.form.get("zusatztext", "").strip()
|
zusatztext = request.form.get("zusatztext", "").strip()
|
||||||
ansprechpartner_ids = [int(x) for x in request.form.getlist("ansprechpartner_ids")]
|
ansprechpartner_ids = [int(x) for x in request.form.getlist("ansprechpartner_ids")]
|
||||||
|
branche_ids = [int(x) for x in request.form.getlist("branche_ids")]
|
||||||
|
|
||||||
if not kurztitel or not titel:
|
if not kurztitel or not titel:
|
||||||
flash("Kurztitel und Titel sind Pflichtfelder.", "error")
|
flash("Kurztitel und Titel sind Pflichtfelder.", "error")
|
||||||
@ -354,24 +439,36 @@ def admin_thema_edit(thema_id):
|
|||||||
mode="edit",
|
mode="edit",
|
||||||
thema=thema_form,
|
thema=thema_form,
|
||||||
ansprechpartner=ansprechpartner,
|
ansprechpartner=ansprechpartner,
|
||||||
|
branchen=branchen,
|
||||||
selected_ansprechpartner_ids=ansprechpartner_ids,
|
selected_ansprechpartner_ids=ansprechpartner_ids,
|
||||||
|
selected_branche_ids=branche_ids,
|
||||||
)
|
)
|
||||||
|
|
||||||
update_thema(thema_id, kurztitel, titel, infotext, zusatztext, ansprechpartner_ids)
|
update_thema(
|
||||||
|
thema_id,
|
||||||
|
kurztitel,
|
||||||
|
titel,
|
||||||
|
infotext,
|
||||||
|
zusatztext,
|
||||||
|
ansprechpartner_ids,
|
||||||
|
branche_ids,
|
||||||
|
)
|
||||||
flash("Thema wurde gespeichert.", "success")
|
flash("Thema wurde gespeichert.", "success")
|
||||||
return redirect(url_for("admin_themen"))
|
return redirect(url_for("admin_themen"))
|
||||||
|
|
||||||
selected_ansprechpartner_ids = get_ansprechpartner_ids_for_thema(thema_id)
|
selected_ansprechpartner_ids = get_ansprechpartner_ids_for_thema(thema_id)
|
||||||
|
selected_branche_ids = get_branche_ids_for_thema(thema_id)
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"admin/thema_form.html",
|
"admin/thema_form.html",
|
||||||
mode="edit",
|
mode="edit",
|
||||||
thema=thema,
|
thema=thema,
|
||||||
ansprechpartner=ansprechpartner,
|
ansprechpartner=ansprechpartner,
|
||||||
|
branchen=branchen,
|
||||||
selected_ansprechpartner_ids=selected_ansprechpartner_ids,
|
selected_ansprechpartner_ids=selected_ansprechpartner_ids,
|
||||||
|
selected_branche_ids=selected_branche_ids,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/admin/themen/<int:thema_id>/delete", methods=["POST"])
|
@app.route("/admin/themen/<int:thema_id>/delete", methods=["POST"])
|
||||||
@admin_required
|
@admin_required
|
||||||
def admin_thema_delete(thema_id):
|
def admin_thema_delete(thema_id):
|
||||||
@ -569,5 +666,94 @@ def admin_user_delete(user_id):
|
|||||||
def impressum():
|
def impressum():
|
||||||
return render_template("impressum.html")
|
return render_template("impressum.html")
|
||||||
|
|
||||||
|
@app.route("/admin/branchen")
|
||||||
|
@admin_required
|
||||||
|
def admin_branchen():
|
||||||
|
branchen = get_all_branchen()
|
||||||
|
return render_template("admin/branchen_list.html", branchen=branchen)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/admin/branchen/new", methods=["GET", "POST"])
|
||||||
|
@admin_required
|
||||||
|
def admin_branche_new():
|
||||||
|
themen = get_all_themen()
|
||||||
|
|
||||||
|
if request.method == "POST":
|
||||||
|
branchenname = request.form.get("branchenname", "").strip()
|
||||||
|
thema_ids = [int(x) for x in request.form.getlist("thema_ids")]
|
||||||
|
|
||||||
|
if not branchenname:
|
||||||
|
flash("Branchenname ist ein Pflichtfeld.", "error")
|
||||||
|
return render_template(
|
||||||
|
"admin/branche_form.html",
|
||||||
|
mode="new",
|
||||||
|
branche=request.form,
|
||||||
|
themen=themen,
|
||||||
|
selected_thema_ids=thema_ids,
|
||||||
|
)
|
||||||
|
|
||||||
|
create_branche(branchenname, thema_ids)
|
||||||
|
flash("Branche wurde erstellt.", "success")
|
||||||
|
return redirect(url_for("admin_branchen"))
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
"admin/branche_form.html",
|
||||||
|
mode="new",
|
||||||
|
branche={},
|
||||||
|
themen=themen,
|
||||||
|
selected_thema_ids=[],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/admin/branchen/<int:branche_id>/edit", methods=["GET", "POST"])
|
||||||
|
@admin_required
|
||||||
|
def admin_branche_edit(branche_id):
|
||||||
|
branche = get_branche_by_id(branche_id)
|
||||||
|
if not branche:
|
||||||
|
flash("Branche nicht gefunden.", "error")
|
||||||
|
return redirect(url_for("admin_branchen"))
|
||||||
|
|
||||||
|
themen = get_all_themen()
|
||||||
|
|
||||||
|
if request.method == "POST":
|
||||||
|
branchenname = request.form.get("branchenname", "").strip()
|
||||||
|
thema_ids = [int(x) for x in request.form.getlist("thema_ids")]
|
||||||
|
|
||||||
|
if not branchenname:
|
||||||
|
flash("Branchenname ist ein Pflichtfeld.", "error")
|
||||||
|
branche_form = {
|
||||||
|
"id": branche_id,
|
||||||
|
"branchenname": branchenname,
|
||||||
|
}
|
||||||
|
return render_template(
|
||||||
|
"admin/branche_form.html",
|
||||||
|
mode="edit",
|
||||||
|
branche=branche_form,
|
||||||
|
themen=themen,
|
||||||
|
selected_thema_ids=thema_ids,
|
||||||
|
)
|
||||||
|
|
||||||
|
update_branche(branche_id, branchenname, thema_ids)
|
||||||
|
flash("Branche wurde gespeichert.", "success")
|
||||||
|
return redirect(url_for("admin_branchen"))
|
||||||
|
|
||||||
|
selected_thema_ids = get_thema_ids_for_branche(branche_id)
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
"admin/branche_form.html",
|
||||||
|
mode="edit",
|
||||||
|
branche=branche,
|
||||||
|
themen=themen,
|
||||||
|
selected_thema_ids=selected_thema_ids,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/admin/branchen/<int:branche_id>/delete", methods=["POST"])
|
||||||
|
@admin_required
|
||||||
|
def admin_branche_delete(branche_id):
|
||||||
|
delete_branche(branche_id)
|
||||||
|
flash("Branche wurde gelöscht.", "success")
|
||||||
|
return redirect(url_for("admin_branchen"))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(host="0.0.0.0", port=5000, debug=True)
|
app.run(host="0.0.0.0", port=5000, debug=True)
|
||||||
229
db.py
229
db.py
@ -242,7 +242,10 @@ def get_ansprechpartner_ids_for_thema(thema_id):
|
|||||||
return [row["ansprechpartner_id"] for row in rows]
|
return [row["ansprechpartner_id"] for row in rows]
|
||||||
|
|
||||||
|
|
||||||
def create_thema(kurztitel, titel, infotext, zusatztext, ansprechpartner_ids):
|
def create_thema(kurztitel, titel, infotext, zusatztext, ansprechpartner_ids, branche_ids=None):
|
||||||
|
if branche_ids is None:
|
||||||
|
branche_ids = []
|
||||||
|
|
||||||
row = execute_returning(
|
row = execute_returning(
|
||||||
"""
|
"""
|
||||||
INSERT INTO thema (kurztitel, titel, infotext, zusatztext)
|
INSERT INTO thema (kurztitel, titel, infotext, zusatztext)
|
||||||
@ -262,10 +265,22 @@ def create_thema(kurztitel, titel, infotext, zusatztext, ansprechpartner_ids):
|
|||||||
(thema_id, ap_id),
|
(thema_id, ap_id),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
for branche_id in branche_ids:
|
||||||
|
execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO branchenthemen (branche_id, thema_id)
|
||||||
|
VALUES (%s, %s)
|
||||||
|
""",
|
||||||
|
(branche_id, thema_id),
|
||||||
|
)
|
||||||
|
|
||||||
return thema_id
|
return thema_id
|
||||||
|
|
||||||
|
|
||||||
def update_thema(thema_id, kurztitel, titel, infotext, zusatztext, ansprechpartner_ids):
|
def update_thema(thema_id, kurztitel, titel, infotext, zusatztext, ansprechpartner_ids, branche_ids=None):
|
||||||
|
if branche_ids is None:
|
||||||
|
branche_ids = []
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
"""
|
"""
|
||||||
UPDATE thema
|
UPDATE thema
|
||||||
@ -295,6 +310,22 @@ def update_thema(thema_id, kurztitel, titel, infotext, zusatztext, ansprechpartn
|
|||||||
(thema_id, ap_id),
|
(thema_id, ap_id),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
execute(
|
||||||
|
"""
|
||||||
|
DELETE FROM branchenthemen
|
||||||
|
WHERE thema_id = %s
|
||||||
|
""",
|
||||||
|
(thema_id,),
|
||||||
|
)
|
||||||
|
|
||||||
|
for branche_id in branche_ids:
|
||||||
|
execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO branchenthemen (branche_id, thema_id)
|
||||||
|
VALUES (%s, %s)
|
||||||
|
""",
|
||||||
|
(branche_id, thema_id),
|
||||||
|
)
|
||||||
|
|
||||||
def delete_thema(thema_id):
|
def delete_thema(thema_id):
|
||||||
execute("DELETE FROM themaansprechpartner WHERE thema_id = %s", (thema_id,))
|
execute("DELETE FROM themaansprechpartner WHERE thema_id = %s", (thema_id,))
|
||||||
@ -357,18 +388,24 @@ def save_assessment_answer(assessment_id, thema_id, frage_id, antwort):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_assessment_result_rows(assessment_id):
|
def get_assessment_result_rows(assessment_id, branche_id):
|
||||||
return fetch_all(
|
return fetch_all(
|
||||||
"""
|
"""
|
||||||
SELECT t.kurztitel, COUNT(*) FILTER (WHERE aa.antwort = TRUE) AS ja_anzahl
|
SELECT
|
||||||
|
t.id,
|
||||||
|
t.kurztitel,
|
||||||
|
COUNT(*) FILTER (WHERE aa.antwort = TRUE) AS ja_anzahl
|
||||||
FROM thema t
|
FROM thema t
|
||||||
|
JOIN branchenthemen bt
|
||||||
|
ON bt.thema_id = t.id
|
||||||
LEFT JOIN assessmentanswer aa
|
LEFT JOIN assessmentanswer aa
|
||||||
ON aa.thema_id = t.id
|
ON aa.thema_id = t.id
|
||||||
AND aa.assessmentid = %s
|
AND aa.assessmentid = %s
|
||||||
|
WHERE bt.branche_id = %s
|
||||||
GROUP BY t.id, t.kurztitel
|
GROUP BY t.id, t.kurztitel
|
||||||
ORDER BY t.id
|
ORDER BY t.id
|
||||||
""",
|
""",
|
||||||
(assessment_id,),
|
(assessment_id, branche_id),
|
||||||
)
|
)
|
||||||
############
|
############
|
||||||
# Ansprechpartner
|
# Ansprechpartner
|
||||||
@ -493,3 +530,185 @@ def delete_user(user_id, current_user_id=None):
|
|||||||
""",
|
""",
|
||||||
(user_id,),
|
(user_id,),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
###############
|
||||||
|
# Branchen
|
||||||
|
###############
|
||||||
|
|
||||||
|
def get_all_branchen():
|
||||||
|
return fetch_all(
|
||||||
|
"""
|
||||||
|
SELECT id, branchenname
|
||||||
|
FROM branche
|
||||||
|
ORDER BY branchenname ASC
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_branche_by_id(branche_id):
|
||||||
|
return fetch_one(
|
||||||
|
"""
|
||||||
|
SELECT id, branchenname
|
||||||
|
FROM branche
|
||||||
|
WHERE id = %s
|
||||||
|
""",
|
||||||
|
(branche_id,),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_thema_ids_for_branche(branche_id):
|
||||||
|
rows = fetch_all(
|
||||||
|
"""
|
||||||
|
SELECT thema_id
|
||||||
|
FROM branchenthemen
|
||||||
|
WHERE branche_id = %s
|
||||||
|
""",
|
||||||
|
(branche_id,),
|
||||||
|
)
|
||||||
|
return [row["thema_id"] for row in rows]
|
||||||
|
|
||||||
|
|
||||||
|
def create_branche(branchenname, thema_ids):
|
||||||
|
row = execute_returning(
|
||||||
|
"""
|
||||||
|
INSERT INTO branche (branchenname)
|
||||||
|
VALUES (%s)
|
||||||
|
RETURNING id
|
||||||
|
""",
|
||||||
|
(branchenname,),
|
||||||
|
)
|
||||||
|
branche_id = row["id"]
|
||||||
|
|
||||||
|
for thema_id in thema_ids:
|
||||||
|
execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO branchenthemen (branche_id, thema_id)
|
||||||
|
VALUES (%s, %s)
|
||||||
|
""",
|
||||||
|
(branche_id, thema_id),
|
||||||
|
)
|
||||||
|
|
||||||
|
return branche_id
|
||||||
|
|
||||||
|
|
||||||
|
def update_branche(branche_id, branchenname, thema_ids):
|
||||||
|
execute(
|
||||||
|
"""
|
||||||
|
UPDATE branche
|
||||||
|
SET branchenname = %s
|
||||||
|
WHERE id = %s
|
||||||
|
""",
|
||||||
|
(branchenname, branche_id),
|
||||||
|
)
|
||||||
|
|
||||||
|
execute(
|
||||||
|
"""
|
||||||
|
DELETE FROM branchenthemen
|
||||||
|
WHERE branche_id = %s
|
||||||
|
""",
|
||||||
|
(branche_id,),
|
||||||
|
)
|
||||||
|
|
||||||
|
for thema_id in thema_ids:
|
||||||
|
execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO branchenthemen (branche_id, thema_id)
|
||||||
|
VALUES (%s, %s)
|
||||||
|
""",
|
||||||
|
(branche_id, thema_id),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def delete_branche(branche_id):
|
||||||
|
execute(
|
||||||
|
"""
|
||||||
|
DELETE FROM branchenthemen
|
||||||
|
WHERE branche_id = %s
|
||||||
|
""",
|
||||||
|
(branche_id,),
|
||||||
|
)
|
||||||
|
execute(
|
||||||
|
"""
|
||||||
|
DELETE FROM branche
|
||||||
|
WHERE id = %s
|
||||||
|
""",
|
||||||
|
(branche_id,),
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_branche_ids_for_thema(thema_id):
|
||||||
|
rows = fetch_all(
|
||||||
|
"""
|
||||||
|
SELECT branche_id
|
||||||
|
FROM branchenthemen
|
||||||
|
WHERE thema_id = %s
|
||||||
|
""",
|
||||||
|
(thema_id,),
|
||||||
|
)
|
||||||
|
return [row["branche_id"] for row in rows]
|
||||||
|
|
||||||
|
|
||||||
|
def update_thema_branchen(thema_id, branche_ids):
|
||||||
|
execute(
|
||||||
|
"""
|
||||||
|
DELETE FROM branchenthemen
|
||||||
|
WHERE thema_id = %s
|
||||||
|
""",
|
||||||
|
(thema_id,),
|
||||||
|
)
|
||||||
|
|
||||||
|
for branche_id in branche_ids:
|
||||||
|
execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO branchenthemen (branche_id, thema_id)
|
||||||
|
VALUES (%s, %s)
|
||||||
|
""",
|
||||||
|
(branche_id, thema_id),
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_all_branchen():
|
||||||
|
return fetch_all(
|
||||||
|
"""
|
||||||
|
SELECT id, branchenname
|
||||||
|
FROM branche
|
||||||
|
ORDER BY branchenname ASC
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_themen_for_branche(branche_id):
|
||||||
|
return fetch_all(
|
||||||
|
"""
|
||||||
|
SELECT t.id, t.kurztitel, t.titel, t.infotext, t.zusatztext
|
||||||
|
FROM thema t
|
||||||
|
JOIN branchenthemen bt ON bt.thema_id = t.id
|
||||||
|
WHERE bt.branche_id = %s
|
||||||
|
ORDER BY t.id
|
||||||
|
""",
|
||||||
|
(branche_id,),
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_next_thema_id_for_branche(current_thema_id, branche_id):
|
||||||
|
row = fetch_one(
|
||||||
|
"""
|
||||||
|
SELECT t.id
|
||||||
|
FROM thema t
|
||||||
|
JOIN branchenthemen bt ON bt.thema_id = t.id
|
||||||
|
WHERE bt.branche_id = %s
|
||||||
|
AND t.id > %s
|
||||||
|
ORDER BY t.id
|
||||||
|
LIMIT 1
|
||||||
|
""",
|
||||||
|
(branche_id, current_thema_id),
|
||||||
|
)
|
||||||
|
return row["id"] if row else None
|
||||||
|
|
||||||
|
def get_thema_for_branche(thema_id, branche_id):
|
||||||
|
return fetch_one(
|
||||||
|
"""
|
||||||
|
SELECT t.id, t.kurztitel, t.titel, t.infotext, t.zusatztext
|
||||||
|
FROM thema t
|
||||||
|
JOIN branchenthemen bt ON bt.thema_id = t.id
|
||||||
|
WHERE t.id = %s
|
||||||
|
AND bt.branche_id = %s
|
||||||
|
""",
|
||||||
|
(thema_id, branche_id),
|
||||||
|
)
|
||||||
@ -13,11 +13,11 @@ services:
|
|||||||
DB_USER: UnternehmenUser
|
DB_USER: UnternehmenUser
|
||||||
DB_PASSWORD: UnternehmenPWD
|
DB_PASSWORD: UnternehmenPWD
|
||||||
DB_PORT: 5432
|
DB_PORT: 5432
|
||||||
SMTP_SERVER: smtp.example.com
|
SMTP_SERVER: mail.kolb.cc
|
||||||
SMTP_PORT: 587
|
SMTP_PORT: 25
|
||||||
SMTP_USERNAME: smtp-user
|
SMTP_USERNAME: smtp-user
|
||||||
SMTP_PASSWORD: smtp-password
|
SMTP_PASSWORD: smtp-password
|
||||||
MAIL_SENDER: noreply@dasunternehmen.com
|
MAIL_SENDER: admin@kolb.cc
|
||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
|
|
||||||
|
|||||||
@ -322,3 +322,12 @@ textarea {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* contacts verbergen bei self assessment */
|
/* contacts verbergen bei self assessment */
|
||||||
|
select {
|
||||||
|
width: 100%;
|
||||||
|
margin: 8px 0 18px;
|
||||||
|
padding: 14px 16px;
|
||||||
|
border-radius: 16px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
background: #fff;
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
42
templates/admin/branche_form.html
Normal file
42
templates/admin/branche_form.html
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="content-card">
|
||||||
|
<h1>
|
||||||
|
{% if mode == "edit" %}
|
||||||
|
Branche bearbeiten
|
||||||
|
{% else %}
|
||||||
|
Neue Branche erstellen
|
||||||
|
{% endif %}
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
<form method="post" class="admin-form">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="branchenname">Branchenname</label>
|
||||||
|
<input type="text" id="branchenname" name="branchenname" value="{{ branche.branchenname or '' }}" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Zugeordnete Themen</label>
|
||||||
|
<div class="checkbox-list">
|
||||||
|
{% for thema in themen %}
|
||||||
|
<label class="checkbox-item">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
name="thema_ids"
|
||||||
|
value="{{ thema.id }}"
|
||||||
|
{% if thema.id in selected_thema_ids %}checked{% endif %}
|
||||||
|
>
|
||||||
|
<span>{{ thema.kurztitel }} - {{ thema.titel }}</span>
|
||||||
|
</label>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-actions">
|
||||||
|
<button type="submit" class="btn">Speichern</button>
|
||||||
|
<a class="btn btn-secondary" href="{{ url_for('admin_branchen') }}">Abbrechen</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
44
templates/admin/branchen_list.html
Normal file
44
templates/admin/branchen_list.html
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="content-card">
|
||||||
|
<div class="page-header">
|
||||||
|
<h1>Branchen</h1>
|
||||||
|
<a class="btn" href="{{ url_for('admin_branche_new') }}">Neue Branche erstellen</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% if branchen %}
|
||||||
|
<table class="admin-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Branchenname</th>
|
||||||
|
<th>Aktionen</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for branche in branchen %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ branche.id }}</td>
|
||||||
|
<td>{{ branche.branchenname }}</td>
|
||||||
|
<td class="actions">
|
||||||
|
<a class="btn btn-small" href="{{ url_for('admin_branche_edit', branche_id=branche.id) }}">
|
||||||
|
Bearbeiten
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<form method="post"
|
||||||
|
action="{{ url_for('admin_branche_delete', branche_id=branche.id) }}"
|
||||||
|
style="display:inline;"
|
||||||
|
onsubmit="return confirm('Branche wirklich löschen?');">
|
||||||
|
<button type="submit" class="btn btn-small btn-danger">Löschen</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% else %}
|
||||||
|
<p>Keine Branchen vorhanden.</p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@ -27,6 +27,10 @@
|
|||||||
<p>Ansprechpartner anzeigen und verwalten.</p>
|
<p>Ansprechpartner anzeigen und verwalten.</p>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
<a class="topic-box" href="{{ url_for('admin_branchen') }}">
|
||||||
|
<h2>Branchen</h2>
|
||||||
|
<p>Branchen anlegen, bearbeiten und Themen zuordnen.</p>
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@ -48,6 +48,23 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Zugeordnete Branchen</label>
|
||||||
|
<div class="checkbox-list">
|
||||||
|
{% for branche in branchen %}
|
||||||
|
<label class="checkbox-item">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
name="branche_ids"
|
||||||
|
value="{{ branche.id }}"
|
||||||
|
{% if branche.id in selected_branche_ids %}checked{% endif %}
|
||||||
|
>
|
||||||
|
<span>{{ branche.branchenname }}</span>
|
||||||
|
</label>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<button type="submit" class="btn">Speichern</button>
|
<button type="submit" class="btn">Speichern</button>
|
||||||
<a class="btn btn-secondary" href="{{ url_for('admin_themen') }}">Abbrechen</a>
|
<a class="btn btn-secondary" href="{{ url_for('admin_themen') }}">Abbrechen</a>
|
||||||
|
|||||||
@ -8,14 +8,20 @@
|
|||||||
Wir helfen Ihnen mit einer kurzen Selbsteinschätzung sich einen Überblick über ihre Unternehmenssituation zu verschaffen.
|
Wir helfen Ihnen mit einer kurzen Selbsteinschätzung sich einen Überblick über ihre Unternehmenssituation zu verschaffen.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
{% if themen and themen|length > 0 %}
|
<form method="post" class="admin-form" style="max-width: 520px; margin-top: 24px;">
|
||||||
<div class="form-actions" style="margin-top: 24px;">
|
<div class="form-group">
|
||||||
<a class="btn" href="{{ url_for('topic', thema_id=themen[0].id) }}">
|
<label for="branche_id">Branche</label>
|
||||||
Self Assessment starten
|
<select id="branche_id" name="branche_id" required>
|
||||||
</a>
|
<option value="">Bitte auswählen</option>
|
||||||
|
{% for branche in branchen %}
|
||||||
|
<option value="{{ branche.id }}">{{ branche.branchenname }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
|
||||||
<p class="muted">Aktuell sind keine Themen verfügbar.</p>
|
<div class="form-actions">
|
||||||
{% endif %}
|
<button type="submit" class="btn">Self Assessment starten</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@ -10,6 +10,7 @@
|
|||||||
<section class="card">
|
<section class="card">
|
||||||
<form method="post" id="topic-form">
|
<form method="post" id="topic-form">
|
||||||
<input type="hidden" name="assessment_id" value="{{ assessment_id }}">
|
<input type="hidden" name="assessment_id" value="{{ assessment_id }}">
|
||||||
|
<input type="hidden" name="branche_id" value="{{ branche_id }}">
|
||||||
|
|
||||||
{% for frage in fragen %}
|
{% for frage in fragen %}
|
||||||
<div class="question-box">
|
<div class="question-box">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user