new texts can now be added to the DB

This commit is contained in:
eclipse 2025-04-18 20:51:53 +02:00
parent 83fe0e949a
commit d23e90f1b9
2 changed files with 36 additions and 4 deletions

View File

@ -18,6 +18,7 @@
<th>Reihe</th> <th>Reihe</th>
<th>Textform</th> <th>Textform</th>
<th>Originalsprache</th> <th>Originalsprache</th>
<th colspan="2">Aktionen</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -28,10 +29,13 @@
<td>{{row["Reihe"]}}</td> <td>{{row["Reihe"]}}</td>
<td>{{row["Textform"]}}</td> <td>{{row["Textform"]}}</td>
<td>{{row["Originalsprache"]}}</td> <td>{{row["Originalsprache"]}}</td>
<td><a href="{{ url_for('views.text_update', id=row['ID']) }}">edit</a></td>
<td><a href="{{ url_for('views.text_delete', id=row['ID']) }}">delete</a></td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
</article>
<dialog aria-labelledby="dialog-heading" id="textmodal"> <dialog aria-labelledby="dialog-heading" id="textmodal">
<article> <article>
@ -72,11 +76,10 @@
{% endfor %} {% endfor %}
</select> </select>
</label> </label>
<button type="submit" formmethod="post" formaction="">OK</button> <button type="submit" formmethod="post" formaction="{{ url_for('views.text_create') }}">OK</button>
<button aria-label="close" formmethod="dialog" formnovalidate>Abbrechen</button> <button aria-label="close" formmethod="dialog" formnovalidate>Abbrechen</button>
</form> </form>
</article> </article>
</dialog> </dialog>
</article>
{% endblock content %} {% endblock content %}

View File

@ -1,4 +1,4 @@
from flask import Blueprint, render_template from flask import Blueprint, render_template, request, redirect, flash, url_for
from the_works.database import get_db from the_works.database import get_db
bp = Blueprint("views", __name__) bp = Blueprint("views", __name__)
@ -8,10 +8,11 @@ def home():
return render_template("views/home.html") return render_template("views/home.html")
@bp.route("/texte") @bp.route("/texte")
def texte_list(): def texte_show():
db = get_db() db = get_db()
rows = db.execute( rows = db.execute(
"""SELECT """SELECT
t.ID as ID,
t.Titel AS Titel, t.Titel AS Titel,
t.Untertitel AS Untertitel, t.Untertitel AS Untertitel,
r.Reihentitel AS Reihe, r.Reihentitel AS Reihe,
@ -27,3 +28,31 @@ def texte_list():
sprachen = db.execute("SELECT ID, Sprache from Sprachen").fetchall() sprachen = db.execute("SELECT ID, Sprache from Sprachen").fetchall()
return render_template("views/texte.html", rows=rows, reihen=reihen, textformen=textformen, sprachen=sprachen) return render_template("views/texte.html", rows=rows, reihen=reihen, textformen=textformen, sprachen=sprachen)
@bp.route("/texte/create", methods=["POST"])
def text_create():
db = get_db()
try:
db.execute(
"INSERT INTO texte (Titel, Untertitel, Reihe, Textform, Originalsprache) VALUES (?, ?, ?, ?, ?)",
(
request.form["text_titel"],
request.form["text_untertitel"] or None,
request.form["text_reihe"] or None,
request.form["text_textform"],
request.form["text_sprache"]
)
)
db.commit()
flash("Neuen Text in Datenbank eingetragen")
except:
flash("Fehler beim Eintragen in die Datenbank", "error")
return redirect(url_for("views.texte_show"))
@bp.route("/texte/update/<int:id>")
def text_update():
pass
@bp.route("/texte/delete/<int:id>")
def text_delete():
pass