added support for DB table "Sprache"
This commit is contained in:
parent
c47732d875
commit
06b770e56a
@ -19,11 +19,12 @@ def create_app():
|
|||||||
init_db(app)
|
init_db(app)
|
||||||
|
|
||||||
# register blueprints
|
# register blueprints
|
||||||
from the_works.views import home, text, werk, verlag
|
from the_works.views import home, text, werk, verlag, sprache
|
||||||
app.register_blueprint(text.bp)
|
app.register_blueprint(text.bp)
|
||||||
app.register_blueprint(home.bp)
|
app.register_blueprint(home.bp)
|
||||||
app.register_blueprint(werk.bp)
|
app.register_blueprint(werk.bp)
|
||||||
app.register_blueprint(verlag.bp)
|
app.register_blueprint(verlag.bp)
|
||||||
|
app.register_blueprint(sprache.bp)
|
||||||
|
|
||||||
### DEBUG
|
### DEBUG
|
||||||
app.config["SQLALCHEMY_ECHO"] = True
|
app.config["SQLALCHEMY_ECHO"] = True
|
||||||
|
|||||||
@ -13,5 +13,6 @@
|
|||||||
<li><a href="{{ url_for('text.all') }}">Texte</a></li>
|
<li><a href="{{ url_for('text.all') }}">Texte</a></li>
|
||||||
<li><a href="{{ url_for('werk.all') }}">Werke</a></li>
|
<li><a href="{{ url_for('werk.all') }}">Werke</a></li>
|
||||||
<li><a href="{{ url_for('verlag.all') }}">Verlage</a></li>
|
<li><a href="{{ url_for('verlag.all') }}">Verlage</a></li>
|
||||||
|
<li><a href="{{ url_for('sprache.all') }}">Sprachen</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|||||||
103
the_works/templates/views/sprache.html
Normal file
103
the_works/templates/views/sprache.html
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block title %}Sprachen{% endblock title %}
|
||||||
|
|
||||||
|
{% block script %}
|
||||||
|
<script>
|
||||||
|
const SCRIPT_ROOT = {{ request.script_root | tojson }};
|
||||||
|
|
||||||
|
function showCreateModal() {
|
||||||
|
// set modal heading
|
||||||
|
document.getElementById("dialog-heading").textContent = "Sprache hinzufügen";
|
||||||
|
// empty text input
|
||||||
|
document.getElementById("form_Sprache").value = "";
|
||||||
|
// set form action
|
||||||
|
document.getElementById("form_submit").formAction = "{{ url_for('sprache.create') }}";
|
||||||
|
// show modal
|
||||||
|
document.getElementById("sprachmodal").showModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
function showUpdateModal() {
|
||||||
|
// set modal heading
|
||||||
|
document.getElementById("dialog-heading").textContent = "Sprache bearbeiten";
|
||||||
|
// populate text input
|
||||||
|
document.getElementById("form_Sprache").value = this.dataset.sprache;
|
||||||
|
// set form action
|
||||||
|
document.getElementById("form_submit").formAction = `${SCRIPT_ROOT}/sprache/update/${this.dataset.id}`;
|
||||||
|
// show modal
|
||||||
|
document.getElementById("sprachmodal").showModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
window.onload = function () {
|
||||||
|
// initialise DataTable
|
||||||
|
let table = new DataTable('#sprachtable', {
|
||||||
|
paging: false,
|
||||||
|
order: []
|
||||||
|
});
|
||||||
|
deRole("#sprachtable");
|
||||||
|
|
||||||
|
// create and append "New"-button to
|
||||||
|
let button = document.createElement("button");
|
||||||
|
button.id = "create-button";
|
||||||
|
button.setAttribute("title", "Sprache hinzufügen");
|
||||||
|
button.innerHTML = "Neu …";
|
||||||
|
button.addEventListener("click", showCreateModal, false);
|
||||||
|
document.getElementById("sprachtable_wrapper").firstElementChild.firstElementChild.appendChild(button);
|
||||||
|
|
||||||
|
// add event listeners
|
||||||
|
document.getElementById ("create-button").addEventListener("click", showCreateModal, false);
|
||||||
|
for (const el of document.querySelectorAll('.action-update') ) {
|
||||||
|
el.addEventListener("click", showUpdateModal, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>{% endblock script %}
|
||||||
|
|
||||||
|
{% block heading %}Verlage{% endblock heading %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
{% include "_icons.svg" %}
|
||||||
|
|
||||||
|
<table id="sprachtable">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Sprachen</th>
|
||||||
|
<th colspan="2">Aktionen</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for sprache in sprachen %}
|
||||||
|
<tr id="sprache-{{ sprache['ID'] }}">
|
||||||
|
<td title="Sprache">{{ sprache["Sprache"] }}</td>
|
||||||
|
<td class="action action-update" data-id="{{ sprache['ID'] }}" data-sprache="{{sprache['Sprache'] }}"><a href="#" title="Sprache bearbeiten"><svg viewbox="0 0 24 24"><use href="#update" /></svg></a></td>
|
||||||
|
<td id="delete-{{ sprache['ID'] }}" class="action"><a onclick="return confirm('Eintrag wirklich löschen?');" href="{{ url_for('sprache.delete', id=sprache['ID']) }}" title="Sprache löschen"><svg viewbox="0 0 24 24"><use href="#delete" /></svg></a></td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<dialog aria-labelledby="dialog-heading" id="sprachmodal">
|
||||||
|
<article>
|
||||||
|
<form id="sprache_detail_form" method="post" >
|
||||||
|
<header>
|
||||||
|
<button aria-label="close" rel="prev" onclick="sprachmodal.close()"></button>
|
||||||
|
<h1 id="dialog-heading">#</h1>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<fieldset>
|
||||||
|
<article>
|
||||||
|
<label>
|
||||||
|
Sprache (erforderlich)
|
||||||
|
<input id="form_Sprache" name="form_Sprache" aria-Label="Sprache" placeholder="Sprache" required />
|
||||||
|
</label>
|
||||||
|
</article>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
<footer class="grid">
|
||||||
|
<button id="form_submit" type="submit" formmethod="post" formaction="{{ url_for('sprache.create') }}">OK</button>
|
||||||
|
<button class="secondary" aria-label="close" formmethod="dialog" formnovalidate>Abbrechen</button>
|
||||||
|
</footer>
|
||||||
|
</form>
|
||||||
|
</article>
|
||||||
|
</dialog>
|
||||||
|
{% endblock content %}
|
||||||
39
the_works/views/sprache.py
Normal file
39
the_works/views/sprache.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
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 Sprache
|
||||||
|
|
||||||
|
bp = Blueprint("sprache", __name__)
|
||||||
|
|
||||||
|
@bp.route("/sprache")
|
||||||
|
@bp.route("/sprache/all")
|
||||||
|
def all():
|
||||||
|
return render_template("views/sprache.html", sprachen=db.session.scalars(select(Sprache)))
|
||||||
|
|
||||||
|
@bp.route("/sprache/verlag/<int:id>")
|
||||||
|
def read(id):
|
||||||
|
return db.session.get(Sprache, id)
|
||||||
|
|
||||||
|
@bp.route("/sprache/create", methods=["POST"])
|
||||||
|
def create():
|
||||||
|
db.session.add(Sprache(Sprache = request.form["form_Sprache"]))
|
||||||
|
db.session.commit()
|
||||||
|
flash("Eintrag erfolgreich hinzugefügt")
|
||||||
|
return redirect(url_for("sprache.all"))
|
||||||
|
|
||||||
|
@bp.route("/sprache/update/<int:id>", methods=["POST"])
|
||||||
|
def update(id):
|
||||||
|
sprache = db.session.get(Sprache, id)
|
||||||
|
sprache.Sprache = request.form["form_Sprache"]
|
||||||
|
db.session.commit()
|
||||||
|
flash("Eintrag erfolgreich geändert")
|
||||||
|
return redirect(url_for("sprache.all"))
|
||||||
|
|
||||||
|
@bp.route("/sprache/delete/<int:id>")
|
||||||
|
def delete(id):
|
||||||
|
sprache = db.session.get(Sprache, id)
|
||||||
|
db.session.delete(sprache)
|
||||||
|
db.session.commit()
|
||||||
|
flash("Eintrag erfolgreich gelöscht")
|
||||||
|
return redirect(url_for("sprache.all"))
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user