diff --git a/the_works/__init__.py b/the_works/__init__.py index 5ab5cba..6d1dd6f 100644 --- a/the_works/__init__.py +++ b/the_works/__init__.py @@ -26,8 +26,9 @@ def create_app(): init_db(app) # register blueprints - from the_works import views - app.register_blueprint(views.bp) + from the_works.views import home, text + app.register_blueprint(text.bp) + app.register_blueprint(home.bp) # load debug toolbar toolbar = DebugToolbarExtension(app) diff --git a/the_works/templates/_icons.svg b/the_works/templates/_icons.svg index 7b320c9..b6474d0 100644 --- a/the_works/templates/_icons.svg +++ b/the_works/templates/_icons.svg @@ -1,5 +1,10 @@ + + + + + diff --git a/the_works/templates/_nav.html b/the_works/templates/_nav.html index 9b930a3..2b9a336 100644 --- a/the_works/templates/_nav.html +++ b/the_works/templates/_nav.html @@ -1,6 +1,6 @@ diff --git a/the_works/templates/views/home.html b/the_works/templates/views/home.html index 55b6eae..a6a5831 100644 --- a/the_works/templates/views/home.html +++ b/the_works/templates/views/home.html @@ -5,5 +5,5 @@ {% block heading %}Home{% endblock heading %} {% block content %} -

Alle Texte

+

Alle Texte

{% endblock content %} \ No newline at end of file diff --git a/the_works/templates/views/texte.html b/the_works/templates/views/text.html similarity index 75% rename from the_works/templates/views/texte.html rename to the_works/templates/views/text.html index 3e349b0..3ea2eba 100644 --- a/the_works/templates/views/texte.html +++ b/the_works/templates/views/text.html @@ -9,7 +9,10 @@ {% include "_icons.svg" %}
- +
@@ -31,8 +34,8 @@ - - + + {% endfor %} @@ -78,7 +81,7 @@ {% endfor %} - + @@ -95,6 +98,17 @@ document.getElementById("text_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("textmodal").showModal(); + } {% endblock content %} \ No newline at end of file diff --git a/the_works/views/__init__.py b/the_works/views/__init__.py new file mode 100644 index 0000000..fc80254 --- /dev/null +++ b/the_works/views/__init__.py @@ -0,0 +1 @@ +pass \ No newline at end of file diff --git a/the_works/views/home.py b/the_works/views/home.py new file mode 100644 index 0000000..e402795 --- /dev/null +++ b/the_works/views/home.py @@ -0,0 +1,8 @@ +from flask import Blueprint, render_template + +bp = Blueprint("home", __name__) + +@bp.route("/") +def home(): + return render_template("views/home.html") + diff --git a/the_works/views.py b/the_works/views/text.py similarity index 69% rename from the_works/views.py rename to the_works/views/text.py index e531e0f..c877d41 100644 --- a/the_works/views.py +++ b/the_works/views/text.py @@ -1,16 +1,13 @@ from flask import Blueprint, render_template, request, redirect, flash, url_for +from sqlalchemy import select, insert, update, delete from the_works.database import db from the_works.models import Texte, Reihen, Sprachen, Textformen -from sqlalchemy import select, update, insert, delete -bp = Blueprint("views", __name__) +bp = Blueprint("text", __name__) -@bp.route("/") -def home(): - return render_template("views/home.html") - -@bp.route("/texte") -def texte_show(): +@bp.route("/text") +@bp.route("/text/all") +def read(): # build ORM equivalent of SELECT statement stmt = ( select(Texte, Reihen, Textformen, Sprachen) @@ -32,32 +29,32 @@ def texte_show(): "sprache": row.Sprachen.Sprache, "s_id": str(row.Sprachen.ID) if row.Sprachen else "" }) - return render_template("views/texte.html", texte=texte, reihen=db.session.scalars(select(Reihen)), textformen=db.session.scalars(select(Textformen)), sprachen=db.session.scalars(select(Sprachen))) + return render_template("views/text.html", texte=texte, reihen=db.session.scalars(select(Reihen)), textformen=db.session.scalars(select(Textformen)), sprachen=db.session.scalars(select(Sprachen))) -@bp.route("/texte/create", methods=["POST"]) -def text_create(): +@bp.route("/text/create", methods=["POST"]) +def create(): stmt = insert(Texte).values(form_to_dict(request.form)) db.session.execute(stmt) db.session.commit() flash("Eintrag erfolgreich hinzugefügt") - return redirect(url_for("views.texte_show")) + return redirect(url_for("views.text.read")) -@bp.route("/texte/update/", methods=["POST"]) -def text_update(id): +@bp.route("/text/update/", methods=["POST"]) +def update(id): stmt = update(Texte).where(Texte.ID == id).values(form_to_dict(request.form)) db.session.execute(stmt) db.session.commit() flash("Eintrag erfolgreich geändert") - return redirect(url_for("views.texte_show")) + return redirect(url_for("views.text.read")) -@bp.route("/texte/delete/") -def text_delete(id): +@bp.route("/text/delete/") +def delete(id): stmt = delete(Texte).where(Texte.ID == id) db.session.execute(stmt) db.session.commit() flash("Eintrag erfolgreich gelöscht") - return redirect(url_for("views.texte_show")) + return redirect(url_for("views.text.read")) def form_to_dict(form):
{{ text["reihe"] }} {{ text["textform"] }} {{ text["sprache"] }}