added support for DB tables "Textform" and "Werksform"
This commit is contained in:
parent
151d96e1db
commit
4bba6fdfd1
@ -14,22 +14,24 @@ def create_app():
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///" + os.path.abspath(app.root_path + "/..") + "/" + os.getenv("SQLALCHEMY_DATABASE_SQLITE_FILENAME")
|
||||
else:
|
||||
exit("no SQLite database URI given; exiting")
|
||||
|
||||
|
||||
# initialize database
|
||||
init_db(app)
|
||||
|
||||
# register blueprints
|
||||
from the_works.views import home, text, werk, verlag, sprache
|
||||
from the_works.views import home, text, werk, verlag, sprache, textform, werksform
|
||||
app.register_blueprint(text.bp)
|
||||
app.register_blueprint(home.bp)
|
||||
app.register_blueprint(werk.bp)
|
||||
app.register_blueprint(verlag.bp)
|
||||
app.register_blueprint(sprache.bp)
|
||||
app.register_blueprint(textform.bp)
|
||||
app.register_blueprint(werksform.bp)
|
||||
|
||||
### DEBUG
|
||||
app.config["SQLALCHEMY_ECHO"] = True
|
||||
print(f"Current Environment: " + app.config['ENVIRONMENT'])
|
||||
# load debug toolbar
|
||||
toolbar = DebugToolbarExtension(app)
|
||||
app.config["SQLALCHEMY_ECHO"] = True
|
||||
app.config['SQLALCHEMY_RECORD_QUERIES'] = os.getenv("SQLALCHEMY_RECORD_QUERIES")
|
||||
print(f"Current Environment: " + app.config['ENVIRONMENT'])
|
||||
|
||||
return app
|
||||
|
||||
@ -14,5 +14,7 @@
|
||||
<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('sprache.all') }}">Sprachen</a></li>
|
||||
<li><a href="{{ url_for('textform.all') }}">Textformen</a></li>
|
||||
<li><a href="{{ url_for('werksform.all') }}">Werksformen</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
103
the_works/templates/views/textform.html
Normal file
103
the_works/templates/views/textform.html
Normal file
@ -0,0 +1,103 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block title %}Textformen{% endblock title %}
|
||||
|
||||
{% block script %}
|
||||
<script>
|
||||
const SCRIPT_ROOT = {{ request.script_root | tojson }};
|
||||
|
||||
function showCreateModal() {
|
||||
// set modal heading
|
||||
document.getElementById("dialog-heading").textContent = "Textform hinzufügen";
|
||||
// empty text input
|
||||
document.getElementById("form_Textform").value = "";
|
||||
// set form action
|
||||
document.getElementById("form_submit").formAction = "{{ url_for('textform.create') }}";
|
||||
// show modal
|
||||
document.getElementById("textformmodal").showModal();
|
||||
}
|
||||
|
||||
function showUpdateModal() {
|
||||
// set modal heading
|
||||
document.getElementById("dialog-heading").textContent = "Textform bearbeiten";
|
||||
// populate text input
|
||||
document.getElementById("form_Textform").value = this.dataset.textform;
|
||||
// set form action
|
||||
document.getElementById("form_submit").formAction = `${SCRIPT_ROOT}/textform/update/${this.dataset.id}`;
|
||||
// show modal
|
||||
document.getElementById("textformmodal").showModal();
|
||||
}
|
||||
|
||||
window.onload = function () {
|
||||
// initialise DataTable
|
||||
let table = new DataTable('#textformtable', {
|
||||
paging: false,
|
||||
order: []
|
||||
});
|
||||
deRole("#textformtable");
|
||||
|
||||
// create and append "New"-button to
|
||||
let button = document.createElement("button");
|
||||
button.id = "create-button";
|
||||
button.setAttribute("title", "Textform hinzufügen");
|
||||
button.innerHTML = "Neu …";
|
||||
button.addEventListener("click", showCreateModal, false);
|
||||
document.getElementById("textformtable_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 %}Textformen{% endblock heading %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% include "_icons.svg" %}
|
||||
|
||||
<table id="textformtable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Textformen</th>
|
||||
<th colspan="2">Aktionen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for textform in textformen %}
|
||||
<tr id="textform-{{ textform['ID'] }}">
|
||||
<td title="Textform">{{ textform["Textform"] }}</td>
|
||||
<td class="action action-update" data-id="{{ textform['ID'] }}" data-textform="{{textform['Textform'] }}"><a href="#" title="Textform bearbeiten"><svg viewbox="0 0 24 24"><use href="#update" /></svg></a></td>
|
||||
<td id="delete-{{ textform['ID'] }}" class="action"><a onclick="return confirm('Eintrag wirklich löschen?');" href="{{ url_for('textform.delete', id=textform['ID']) }}" title="Textform löschen"><svg viewbox="0 0 24 24"><use href="#delete" /></svg></a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<dialog aria-labelledby="dialog-heading" id="textformmodal">
|
||||
<article>
|
||||
<form id="textform_detail_form" method="post" >
|
||||
<header>
|
||||
<button aria-label="close" rel="prev" onclick="textformmodal.close()"></button>
|
||||
<h1 id="dialog-heading">#</h1>
|
||||
</header>
|
||||
|
||||
<fieldset>
|
||||
<article>
|
||||
<label>
|
||||
Textform (erforderlich)
|
||||
<input id="form_Textform" name="form_Textform" aria-Label="Textform" placeholder="Textform" required autofocus />
|
||||
</label>
|
||||
</article>
|
||||
</fieldset>
|
||||
|
||||
<footer class="grid">
|
||||
<button id="form_submit" type="submit" formmethod="post" formaction="{{ url_for('textform.create') }}">OK</button>
|
||||
<button class="secondary" aria-label="close" formmethod="dialog" formnovalidate>Abbrechen</button>
|
||||
</footer>
|
||||
</form>
|
||||
</article>
|
||||
</dialog>
|
||||
{% endblock content %}
|
||||
103
the_works/templates/views/werksform.html
Normal file
103
the_works/templates/views/werksform.html
Normal file
@ -0,0 +1,103 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block title %}Werksformen{% endblock title %}
|
||||
|
||||
{% block script %}
|
||||
<script>
|
||||
const SCRIPT_ROOT = {{ request.script_root | tojson }};
|
||||
|
||||
function showCreateModal() {
|
||||
// set modal heading
|
||||
document.getElementById("dialog-heading").textContent = "Werksform hinzufügen";
|
||||
// empty text input
|
||||
document.getElementById("form_Werksform").value = "";
|
||||
// set form action
|
||||
document.getElementById("form_submit").formAction = "{{ url_for('werksform.create') }}";
|
||||
// show modal
|
||||
document.getElementById("werksformmodal").showModal();
|
||||
}
|
||||
|
||||
function showUpdateModal() {
|
||||
// set modal heading
|
||||
document.getElementById("dialog-heading").textContent = "Werksform bearbeiten";
|
||||
// populate text input
|
||||
document.getElementById("form_Werksform").value = this.dataset.werksform;
|
||||
// set form action
|
||||
document.getElementById("form_submit").formAction = `${SCRIPT_ROOT}/werksform/update/${this.dataset.id}`;
|
||||
// show modal
|
||||
document.getElementById("werksformmodal").showModal();
|
||||
}
|
||||
|
||||
window.onload = function () {
|
||||
// initialise DataTable
|
||||
let table = new DataTable('#werksformtable', {
|
||||
paging: false,
|
||||
order: []
|
||||
});
|
||||
deRole("#werksformtable");
|
||||
|
||||
// create and append "New"-button to
|
||||
let button = document.createElement("button");
|
||||
button.id = "create-button";
|
||||
button.setAttribute("title", "Werksform hinzufügen");
|
||||
button.innerHTML = "Neu …";
|
||||
button.addEventListener("click", showCreateModal, false);
|
||||
document.getElementById("werksformtable_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 %}Werksformen{% endblock heading %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% include "_icons.svg" %}
|
||||
|
||||
<table id="werksformtable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Werksformen</th>
|
||||
<th colspan="2">Aktionen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for werksform in werksformen %}
|
||||
<tr id="werksform-{{ werksform['ID'] }}">
|
||||
<td title="Werksform">{{ werksform["Werksform"] }}</td>
|
||||
<td class="action action-update" data-id="{{ werksform['ID'] }}" data-werksform="{{werksform['Werksform'] }}"><a href="#" title="Werksform bearbeiten"><svg viewbox="0 0 24 24"><use href="#update" /></svg></a></td>
|
||||
<td id="delete-{{ werksform['ID'] }}" class="action"><a onclick="return confirm('Eintrag wirklich löschen?');" href="{{ url_for('werksform.delete', id=werksform['ID']) }}" title="Werksform löschen"><svg viewbox="0 0 24 24"><use href="#delete" /></svg></a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<dialog aria-labelledby="dialog-heading" id="werksformmodal">
|
||||
<article>
|
||||
<form id="werksform_detail_form" method="post" >
|
||||
<header>
|
||||
<button aria-label="close" rel="prev" onclick="werksformmodal.close()"></button>
|
||||
<h1 id="dialog-heading">#</h1>
|
||||
</header>
|
||||
|
||||
<fieldset>
|
||||
<article>
|
||||
<label>
|
||||
Werksform (erforderlich)
|
||||
<input id="form_Werksform" name="form_Werksform" aria-Label="Werksform" placeholder="Werksform" required autofocus/>
|
||||
</label>
|
||||
</article>
|
||||
</fieldset>
|
||||
|
||||
<footer class="grid">
|
||||
<button id="form_submit" type="submit" formmethod="post" formaction="#">OK</button>
|
||||
<button class="secondary" aria-label="close" formmethod="dialog" formnovalidate>Abbrechen</button>
|
||||
</footer>
|
||||
</form>
|
||||
</article>
|
||||
</dialog>
|
||||
{% endblock content %}
|
||||
39
the_works/views/textform.py
Normal file
39
the_works/views/textform.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 Textform
|
||||
|
||||
bp = Blueprint("textform", __name__)
|
||||
|
||||
@bp.route("/textform")
|
||||
@bp.route("/textform/all")
|
||||
def all():
|
||||
return render_template("views/textform.html", textformen=db.session.scalars(select(Textform)))
|
||||
|
||||
@bp.route("/textform/verlag/<int:id>")
|
||||
def read(id):
|
||||
return db.session.get(Textform, id)
|
||||
|
||||
@bp.route("/textform/create", methods=["POST"])
|
||||
def create():
|
||||
db.session.add(Textform(Textform = request.form["form_Textform"]))
|
||||
db.session.commit()
|
||||
flash("Eintrag erfolgreich hinzugefügt")
|
||||
return redirect(url_for("textform.all"), code=303)
|
||||
|
||||
@bp.route("/textform/update/<int:id>", methods=["POST"])
|
||||
def update(id):
|
||||
textform = db.session.get(Textform, id)
|
||||
textform.Textform = request.form["form_Textform"]
|
||||
db.session.commit()
|
||||
flash("Eintrag erfolgreich geändert")
|
||||
return redirect(url_for("textform.all"), code=303)
|
||||
|
||||
@bp.route("/textform/delete/<int:id>")
|
||||
def delete(id):
|
||||
textform = db.session.get(Textform, id)
|
||||
db.session.delete(textform)
|
||||
db.session.commit()
|
||||
flash("Eintrag erfolgreich gelöscht")
|
||||
return redirect(url_for("textform.all"))
|
||||
|
||||
39
the_works/views/werksform.py
Normal file
39
the_works/views/werksform.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 Werksform
|
||||
|
||||
bp = Blueprint("werksform", __name__)
|
||||
|
||||
@bp.route("/werksform")
|
||||
@bp.route("/werksform/all")
|
||||
def all():
|
||||
return render_template("views/werksform.html", werksformen=db.session.scalars(select(Werksform)))
|
||||
|
||||
@bp.route("/werksform/verlag/<int:id>")
|
||||
def read(id):
|
||||
return db.session.get(Werksform, id)
|
||||
|
||||
@bp.route("/werksform/create", methods=["POST"])
|
||||
def create():
|
||||
db.session.add(Werksform(Werksform = request.form["form_Werksform"]))
|
||||
db.session.commit()
|
||||
flash("Eintrag erfolgreich hinzugefügt")
|
||||
return redirect(url_for("werksform.all"), code=303)
|
||||
|
||||
@bp.route("/werksform/update/<int:id>", methods=["POST"])
|
||||
def update(id):
|
||||
werksform = db.session.get(Werksform, id)
|
||||
werksform.Werksform = request.form["form_Werksform"]
|
||||
db.session.commit()
|
||||
flash("Eintrag erfolgreich geändert")
|
||||
return redirect(url_for("werksform.all"), code=303)
|
||||
|
||||
@bp.route("/werksform/delete/<int:id>")
|
||||
def delete(id):
|
||||
werksform = db.session.get(Werksform, id)
|
||||
db.session.delete(werksform)
|
||||
db.session.commit()
|
||||
flash("Eintrag erfolgreich gelöscht")
|
||||
return redirect(url_for("werksform.all"))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user