endpoint "all" now shows an overview of all table rows while "read" shows a single row in detail; harmonized parameter spelling

This commit is contained in:
eclipse 2025-04-23 10:12:04 +02:00
parent 93e07a57f9
commit f083b1bc81
8 changed files with 77 additions and 69 deletions

View File

@ -1,10 +1,15 @@
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" style="display: none;">
<!-- "plus" from https://heroicons.com/solid -->
<defs>
<!-- "plus" from https://heroicons.com/solid -->
<symbol id="create">
<path fill-rule="evenodd" d="M12 3.75a.75.75 0 0 1 .75.75v6.75h6.75a.75.75 0 0 1 0 1.5h-6.75v6.75a.75.75 0 0 1-1.5 0v-6.75H4.5a.75.75 0 0 1 0-1.5h6.75V4.5a.75.75 0 0 1 .75-.75Z" clip-rule="evenodd" />
</symbol>
<!-- "plus" from https://heroicons.com/solid -->
<symbol id="read">
<path fill-rule="evenodd" d="M10.5 3.75a6.75 6.75 0 1 0 0 13.5 6.75 6.75 0 0 0 0-13.5ZM2.25 10.5a8.25 8.25 0 1 1 14.59 5.28l4.69 4.69a.75.75 0 1 1-1.06 1.06l-4.69-4.69A8.25 8.25 0 0 1 2.25 10.5Z" clip-rule="evenodd" />
</symbol>
<!-- "pencil-square" from https://heroicons.com/solid -->
<symbol id="update">
<path d="M21.731 2.269a2.625 2.625 0 0 0-3.712 0l-1.157 1.157 3.712 3.712 1.157-1.157a2.625 2.625 0 0 0 0-3.712ZM19.513 8.199l-3.712-3.712-8.4 8.4a5.25 5.25 0 0 0-1.32 2.214l-.8 2.685a.75.75 0 0 0 .933.933l2.685-.8a5.25 5.25 0 0 0 2.214-1.32l8.4-8.4Z" />

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@ -1,7 +1,7 @@
<nav>
<ul>
<li><a href="{{ url_for('home.home') }}">Home</a></li>
<li><a href="{{ url_for('text.read') }}">Texte</a></li>
<li><a href="{{ url_for('werk.read') }}">Werke</a></li>
<li><a href="{{ url_for('text.all') }}">Texte</a></li>
<li><a href="{{ url_for('werk.all') }}">Werke</a></li>
</ul>
</nav>

View File

@ -1,23 +1,23 @@
<script>
function showUpdateModal(titel, untertitel, reihe, textform, sprache, formaction) {
document.getElementById("dialog-heading").textContent = "Text bearbeiten";
document.getElementById("text_titel").value = titel;
document.getElementById("text_untertitel").value = untertitel;
document.getElementById('text_reihe').selectedIndex = reihe;
document.getElementById("text_textform").selectedIndex = textform;
document.getElementById("text_sprache").selectedIndex = sprache;
document.getElementById("text_submit").formAction = formaction;
document.getElementById("form_Titel").value = titel;
document.getElementById("form_Untertitel").value = untertitel;
document.getElementById('form_Reihe').selectedIndex = reihe;
document.getElementById("form_Textform").selectedIndex = textform;
document.getElementById("form_Sprache").selectedIndex = sprache;
document.getElementById("form_submit").formAction = formaction;
document.getElementById("textmodal").showModal();
}
function showCreateModal() {
document.getElementById("dialog-heading").textContent = "Text hinzufügen";
document.getElementById("text_titel").value = "";
document.getElementById("text_untertitel").value = "";
document.getElementById('text_reihe').selectedIndex = "";
document.getElementById("text_textform").selectedIndex = "";
document.getElementById("text_sprache").selectedIndex = "";
document.getElementById("text_submit").formAction = "{{ url_for('text.create') }}";
document.getElementById("form_Titel").value = "";
document.getElementById("form_Untertitel").value = "";
document.getElementById('form_Reihe').selectedIndex = "";
document.getElementById("form_Textform").selectedIndex = "";
document.getElementById("form_Sprache").selectedIndex = "";
document.getElementById("form_submit").formAction = "{{ url_for('text.create') }}";
document.getElementById("textmodal").showModal();
}
</script>

View File

@ -5,5 +5,5 @@
{% block heading %}Home{% endblock heading %}
{% block content %}
<p><a href="{{ url_for('text.read') }}">Alle Texte</a></p>
<p><a href="{{ url_for('text.all') }}">Alle Texte</a></p>
{% endblock content %}

View File

@ -32,12 +32,12 @@
<tbody>
{% for text in texte %}
<tr id="text-{{ text['id'] }}">
<td title="Titel">{{ text["titel"] }}</td>
<td title="Untertitel">{{ text["untertitel"] }}</td>
<td title="Reihe">{{ text["reihe"] }}</td>
<td title="Textform">{{ text["textform"] }}</td>
<td title="Sprache">{{ text["sprache"] }}</td>
<td><a onclick="showUpdateModal('{{ text["titel"] }}', '{{ text["untertitel"] }}', '{{ text["r_id"] }}', '{{ text["tf_id"] }}', '{{ text["s_id"] }}', '{{ url_for("text.update", id=text["id"]) }}');" title="Text bearbeiten"><svg viewbox="0 0 24 24"><use href="#update" /></svg></a></td>
<td title="Titel">{{ text["Titel"] }}</td>
<td title="Untertitel">{{ text["Untertitel"] }}</td>
<td title="Reihe">{{ text["Reihe"] }}</td>
<td title="Textform">{{ text["Textform"] }}</td>
<td title="Sprache">{{ text["Sprache"] }}</td>
<td><a onclick="showUpdateModal('{{ text["Titel"] }}', '{{ text["Untertitel"] }}', '{{ text["r_id"] }}', '{{ text["tf_id"] }}', '{{ text["s_id"] }}', '{{ url_for("text.update", id=text["id"]) }}');" title="Text bearbeiten"><svg viewbox="0 0 24 24"><use href="#update" /></svg></a></td>
<td><a onclick="return confirm('Eintrag wirklich löschen?');" href="{{ url_for('text.delete', id=text["id"]) }}" title="Text löschen"><svg viewbox="0 0 24 24"><use href="#delete" /></svg></a></td>
</tr>
{% endfor %}
@ -54,15 +54,15 @@
<form>
<label>
Titel (erforderlich)
<input id="text_titel" name="text_titel" placeholder="Titel" required />
<input id="form_Titel" name="form_Titel" placeholder="Titel" required />
</label>
<label>
Untertitel
<input id="text_untertitel" name="text_untertitel" placeholder="Untertitel" />
<input id="form_Untertitel" name="form_Untertitel" placeholder="Untertitel" />
</label>
<label>
Reihe
<select id="text_reihe" name="text_reihe" aria-label="Der Text gehört zur Reihe …">
<select id="form_Reihe" name="form_Reihe" aria-label="Der Text gehört zur Reihe …">
<option selected value="">keine Reihe</option>
{% for r in reihen %}<option value="{{ r.ID }}">{{ r.Titel }}</option>
{% endfor %}
@ -70,7 +70,7 @@
</label>
<label>
Textform (erforderlich)
<select id="text_textform" name="text_textform" aria-label="Textform" required>
<select id="form_Textform" name="form_Textform" aria-label="Textform" required>
<option selected disabled value="">Textform auswählen …</option>
{% for tf in textformen %}<option value="{{ tf.ID }}">{{ tf.Textform }}</option>
{% endfor %}
@ -78,13 +78,13 @@
</label>
<label>
Sprache (erforderlich)
<select id="text_sprache" name="text_sprache" aria-label="Sprache des Textes" required>
<select id="form_Sprache" name="form_Sprache" aria-label="Sprache des Textes" required>
<option selected disabled value="">Sprache auswählen …</option>
{% for s in sprachen %}<option value="{{ s.ID }}">{{ s.Sprache }}</option>
{% endfor %}
</select>
</label>
<button id="text_submit" type="submit" formmethod="post" formaction="{{ url_for('text.create') }}">OK</button>
<button id="form_submit" type="submit" formmethod="post" formaction="{{ url_for('text.create') }}">OK</button>
<button aria-label="close" formmethod="dialog" formnovalidate>Abbrechen</button>
</form>
</article>

View File

@ -32,13 +32,13 @@
<tbody>
{% for werk in werke %}
<tr id="werk-{{ werk['id'] }}">
<td title="Titel">{{ werk["titel"] }}</td>
<td title="Untertitel">{{ werk["untertitel"] }}</td>
<td title="Reihe">{{ werk["reihe"] }}</td>
<td title="Verlag">{{ werk["verlag"] }}</td>
<td title="Werksform">{{ werk["werksform"] }}</td>
<td><a onclick="showUpdateModal('{{ werk["titel"] }}', '{{ werk["untertitel"] }}', '{{ werk["r_id"] }}', '{{ werk["v_id"] }}', '{{ werk["wf_id"] }}', '{{ url_for("werk.update", id=werk["id"]) }}');" title="Werk bearbeiten"><svg viewbox="0 0 24 24"><use href="#update" /></svg></a></td>
<td><a onclick="return confirm('Eintrag wirklich löschen?');" href="{{ url_for('werk.delete', id=werk["id"]) }}" title="Werk löschen"><svg viewbox="0 0 24 24"><use href="#delete" /></svg></a></td>
<td title="Titel">{{ werk["Titel"] }}</td>
<td title="Untertitel">{{ werk["Untertitel"] }}</td>
<td title="Reihe">{{ werk["Reihe"] }}</td>
<td title="Verlag">{{ werk["Verlag"] }}</td>
<td title="Werksform">{{ werk["Werksform"] }}</td>
<td><a href="{{ url_for('werk.read', id=werk['id']) }}" title="Werk ansehen/bearbeiten"><svg viewbox="0 0 24 24"><use href="#read" /></svg></a></td>
<td><a href="{{ url_for('werk.delete', id=werk['id']) }}" title="Werk löschen"><svg viewbox="0 0 24 24"><use href="#delete" /></svg></a></td>
</tr>
{% endfor %}
</tbody>

View File

@ -5,9 +5,9 @@ from the_works.models import Text, Reihe, Sprache, Textform
bp = Blueprint("text", __name__)
@bp.route("/text/all")
@bp.route("/text")
def read():
@bp.route("/text/all")
def all():
# build ORM equivalent of SELECT statement
stmt = (
select(Text, Reihe, Textform, Sprache)
@ -20,13 +20,13 @@ def read():
for row in db.session.execute(stmt):
texte.append({
"id": row.Text.ID,
"titel": row.Text.Titel,
"untertitel": row.Text.Untertitel or "",
"reihe": row.Reihe.Titel if row.Reihe else "",
"Titel": row.Text.Titel,
"Untertitel": row.Text.Untertitel or "",
"Reihe": row.Reihe.Titel if row.Reihe else "",
"r_id": str(row.Reihe.ID) if row.Reihe else "",
"textform": row.Textform.Textform if row.Textform else "",
"Textform": row.Textform.Textform if row.Textform else "",
"tf_id": str(row.Textform.ID) if row.Textform else "",
"sprache": row.Sprache.Sprache,
"Sprache": row.Sprache.Sprache,
"s_id": str(row.Sprache.ID) if row.Sprache else ""
})
return render_template("views/text.html", texte=texte, reihen=db.session.scalars(select(Reihe)), textformen=db.session.scalars(select(Textform)), sprachen=db.session.scalars(select(Sprache)))
@ -34,30 +34,30 @@ def read():
@bp.route("/text/create", methods=["POST"])
def create():
db.session.add(Text(
Titel = request.form["text_titel"],
Untertitel = request.form["text_untertitel"] or None,
Reihe = request.form["text_reihe"] or None,
Textform = request.form["text_textform"],
Sprache = request.form["text_sprache"]
Titel = request.form["form_Titel"],
Untertitel = request.form["form_Untertitel"] or None,
Reihe = request.form["form_Reihe"] or None,
Textform = request.form["form_Textform"],
Sprache = request.form["form_Sprache"]
))
db.session.commit()
flash("Eintrag erfolgreich hinzugefügt")
return redirect(url_for("text.read"))
return redirect(url_for("text.all"))
@bp.route("/text/update/<int:id>", methods=["POST"])
def update(id):
# get record
text = db.session.get(Text, id)
# update values
text.Titel = request.form["text_titel"]
text.Untertitel = request.form["text_untertitel"] or None
text.Reihe = request.form["text_reihe"] or None
text.Textform = request.form["text_textform"]
text.Sprache = request.form["text_sprache"]
text.Titel = request.form["form_Titel"]
text.Untertitel = request.form["form_Untertitel"] or None
text.Reihe = request.form["form_Reihe"] or None
text.Textform = request.form["form_Textform"]
text.Sprache = request.form["form_Sprache"]
# commit changes
db.session.commit()
flash("Eintrag erfolgreich geändert")
return redirect(url_for("text.read"))
return redirect(url_for("text.all"))
@bp.route("/text/delete/<int:id>")
@ -66,5 +66,5 @@ def delete(id):
db.session.delete(text)
db.session.commit()
flash("Eintrag erfolgreich gelöscht")
return redirect(url_for("text.read"))
return redirect(url_for("text.all"))

View File

@ -5,9 +5,9 @@ from the_works.models import Werk, Reihe, Verlag, Werksform
bp = Blueprint("werk", __name__)
@bp.route("/werk/all")
@bp.route("/werk")
def read():
@bp.route("/werk/all")
def all():
# build ORM equivalent of SELECT statement
stmt = (
select(Werk, Reihe, Verlag, Werksform)
@ -20,16 +20,19 @@ def read():
for row in db.session.execute(stmt):
werke.append({
"id": row.Werk.ID,
"titel": row.Werk.Titel,
"untertitel": row.Werk.Untertitel or "",
"reihe": row.Reihe.Titel if row.Reihe else "",
"r_id": str(row.Reihe.ID) if row.Reihe else "",
"verlag": row.Verlag.Verlag if row.Verlag else "",
"v_id": str(row.Verlag.ID) if row.Verlag else "",
"werksform": row.Werksform.Werksform if row.Werksform else "",
"wf_id": str(row.Werksform.ID) if row.Werksform else ""
"Titel": row.Werk.Titel,
"Untertitel": row.Werk.Untertitel or "",
"Reihe": row.Reihe.Titel if row.Reihe else "",
"Verlag": row.Verlag.Verlag if row.Verlag else "",
"Werksform": row.Werksform.Werksform if row.Werksform else "",
})
return render_template("views/werk.html", werke=werke, reihen=db.session.scalars(select(Reihe)), verlage=db.session.scalars(select(Verlag)), werksformen=db.session.scalars(select(Werksform)))
return render_template("views/werk.html", werke=werke)
@bp.route("/werk/read/<int:id>")
def read():
werk = db.session.get(Werk, id)
return render_template("views/werk_read.html", werk=werk)
@bp.route("/werk/create", methods=["POST"])
def create():
@ -43,7 +46,7 @@ def create():
db.session.commit()
flash("Eintrag erfolgreich hinzugefügt")
"""
return redirect(url_for("werk.read"))
return redirect(url_for("werk.all"))
@bp.route("/werk/update/<int:id>", methods=["POST"])
def update(id):
@ -59,7 +62,7 @@ def update(id):
db.session.commit()
flash("Eintrag erfolgreich geändert")
"""
return redirect(url_for("werk.read"))
return redirect(url_for("werk.all"))
@bp.route("/werk/delete/<int:id>")
@ -69,4 +72,4 @@ def delete(id):
db.session.commit()
flash("Eintrag erfolgreich gelöscht")
"""
return redirect(url_for("werk.read"))
return redirect(url_for("werk.all"))