Skip to content

Commit

Permalink
adding complete lied segment
Browse files Browse the repository at this point in the history
  • Loading branch information
fifthaccess committed May 10, 2022
1 parent 956876b commit b7544ce
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 55 deletions.
112 changes: 112 additions & 0 deletions controllers/lied.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
from ast import Del
from operator import index
from pyexpat import model
import string
from click import edit
from flask import Flask, redirect, request, flash
from flask.templating import render_template
from flask import Blueprint
import sqlalchemy
import sqlalchemy.orm
from forms.lied import DeleteLiederForm, EditLiedForm, LiedForm
from model.models import Lied, db


lied_blueprint = Blueprint('lied_blueprint',__name__)


@lied_blueprint.route("/lieder")
def Lieder_view():
session : sqlalchemy.orm.scoping.scoped_session = db.session

lied = session.query(Lied).order_by(Lied.LiedId).all()

return render_template("lieder/viewlieder.html", lieder = lied, headline = "Lieder")

@lied_blueprint.route('/lieder/add', methods=["Get", "Post"])
def Lieder_add():
session : sqlalchemy.orm.scoping.scoped_session = db.session

add_lied_form = LiedForm()
lied = session.query(Lied).order_by(Lied.LiedId).all()

if request.method == 'POST':
print("f")
if add_lied_form.validate_on_submit():
new_Lied = Lied()

print("data is valid")
#new_manager.ManagerId = add_manager_form.ManagerID.data

new_Lied.Kuenstleranzahl = add_lied_form.Kuenstleranzahl.data
new_Lied.Liedname = add_lied_form.Liedname.data
new_Lied.Erscheinungsdatum = add_lied_form.Erscheinungsdatum.data
db.session.add(new_Lied)
db.session.commit()

return redirect("/lieder")

else:
return render_template("lieder/addlieder.html", headline = "Add Lieder", form = add_lied_form, lieder = lied)

else:
return render_template("lieder/addlieder.html", headline = "Add Lieder", form = add_lied_form, lieder = lied)

@lied_blueprint.route('/lieder/delete', methods=["Get", "Post"])
def lied_delete():

session : sqlalchemy.orm.scoping.scoped_session = db.session
lied = session.query(Lied).order_by(Lied.LiedId).all()

del_form = DeleteLiederForm()

if request.method == 'POST':
print("f")
if del_form.validate_on_submit():
delete_id_string = del_form.CheckedCheckboxes.data
delete_id_list = list(delete_id_string.split(","))

print(del_form.CheckedCheckboxes.data)
for i in delete_id_list:
print("deleting now data with id " + i)
itemToDelete = db.session.query(Lied).filter(Lied.LiedId == i)
itemToDelete.delete()
db.session.commit()
print("deleted data with id " + i)

lied = session.query(Lied).order_by(Lied.LiedId).all()
return render_template("lieder/viewlieder.html", lieder = lied, headline = "Lieder", form = del_form )
else:
print("invalide Form")
return render_template("lieder/deletelieder.html", lieder = lied, headline = "Delete Lieder", form = del_form )

else:
return render_template("lieder/deletelieder.html", lieder = lied, headline = "Delete Lieder", form = del_form )


@lied_blueprint.route('/lieder/edit', methods=["Get", "Post"])
def lied_edit():
edit_lied_id = request.args["itemid"]
edit_lied_form = EditLiedForm()

item_to_edit = db.session.query(Lied).filter(Lied.LiedId == edit_lied_id).first()

if request.method == 'POST':
print("Post")
if edit_lied_form.validate_on_submit():
print("is validate")


item_to_edit.LiedId = edit_lied_form.LiedId.data
item_to_edit.Kuenstleranzahl = edit_lied_form.Kuenstleranzahl.data
item_to_edit.Liedname = edit_lied_form.Liedname.data
item_to_edit.Erscheinungsdatum = edit_lied_form.Erscheinungsdatum.data
db.session.commit()
return redirect("/lieder")
else:

edit_lied_form.LiedId.data = item_to_edit.LiedId
edit_lied_form.Kuenstleranzahl.data = item_to_edit.Kuenstleranzahl
edit_lied_form.Liedname.data = item_to_edit.Liedname
edit_lied_form.Erscheinungsdatum.data = item_to_edit.Erscheinungsdatum
return render_template("lieder/editlieder.html", headline = "Edit Lieder", form = edit_lied_form)
28 changes: 28 additions & 0 deletions forms/lied.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from operator import imod
from flask_wtf import FlaskForm
from wtforms.fields.datetime import DateField
from wtforms.fields.simple import BooleanField, StringField, TextAreaField ,HiddenField
from wtforms.fields import DecimalField, FieldList , SelectField , DateField
from wtforms import validators
from model.models import Kuenstler
import sqlalchemy
import sqlalchemy.orm
from model.models import Manager
from model.models import db

class LiedForm(FlaskForm):
LiedId = HiddenField("LiedId")
Kuenstleranzahl = DecimalField("Kuenstleranzahl")
Liedname = StringField("Liedname")
Erscheinungsdatum = DateField("Erscheinungsdatum")


class DeleteLiederForm(FlaskForm):
CheckedCheckboxes = HiddenField("CheckedCheckboxes")


class EditLiedForm(FlaskForm):
LiedId = HiddenField("LiedId")
Kuenstleranzahl = DecimalField("Kuenstleranzahl")
Liedname = StringField("Liedname")
Erscheinungsdatum = DateField("Erscheinungsdatum")
1 change: 1 addition & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<li><a class="dropdown-item" href="/">Hauptseite</a></li>
<li><a class="dropdown-item" href="/managers">Managers</a></li>
<li><a class="dropdown-item" href="/kuenstler">Künstler</a></li>
<li><a class="dropdown-item" href="/lieder">Lieder</a></li>

<!--<li><a class="dropdown-item" href="/products/add">Hinzufügen</a></li>-->
</ul>
Expand Down
18 changes: 7 additions & 11 deletions templates/lieder/addlieder.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%extends 'manager/viewmanagers.html'%}
{%extends 'lieder/viewlieder.html'%}

{%block body2%}

Expand All @@ -11,24 +11,20 @@


<div class="mb-3">
<label for="Vorname" class="form-label">Vorname</label>
{{form.Vorname(class_="form-control")}}
<label for="Vorname" class="form-label">Kuenstleranzahl</label>
{{form.Kuenstleranzahl(class_="form-control")}}
</div>

<div class="mb-3">
<label for="Nachname" class="form-label">Nachname</label>
{{form.Nachname(class_="form-control")}}
<label for="Nachname" class="form-label">Liedname</label>
{{form.Liedname(class_="form-control")}}
</div>

<div class="mb-3">
<label for="Firma" class="form-label">Firma</label>
{{form.Firma(class_="form-control")}}
<label for="Firma" class="form-label">Erscheinungsdatum</label>
{{form.Erscheinungsdatum(class_="form-control")}}
</div>

<div class="mb-3">
<label for="Kuenstler_anzahl" class="form-label">Kuenstler_anzahl</label>
{{form.Kuenstler_anzahl(class_="form-control")}}
</div>

<button type="submit" class="btn btn-primary">Submit</button>
</form>
Expand Down
30 changes: 14 additions & 16 deletions templates/lieder/deletelieder.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,36 +44,34 @@
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<li><a class="dropdown-item" href="/">Hauptseite</a></li>
<li><a class="dropdown-item" href="/managers">View Managers</a></li>
<li><a class="dropdown-item" href="/managers/add">Add Managers</a></li>
<li><a class="dropdown-item" href="/managers/delete">Delete Managers</a></li>
<li><a class="dropdown-item" href="/lieder">View Lieder</a></li>
<li><a class="dropdown-item" href="/lieder/add">Add Lieder</a></li>
<li><a class="dropdown-item" href="/lieder/delete">Delete Lieder</a></li>

<!--<li><a class="dropdown-item" href="/products/add">Hinzufügen</a></li>-->
</ul>
<form method="POST" >
<form method="POST">
{{form.csrf_token}}

<table class="table">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Vorname</th>
<th scope="col">Nachname</th>
<th scope="col">Firma</th>
<th scope="col">Kuenstler_anzahl</th>
<th scope="col">LiedId</th>
<th scope="col">Liedname</th>
<th scope="col">Liedname</th>
<th scope="col">Erscheinungsdatum</th>
<th scope="col" style="color:red">Delete❌</th>
</tr>
</thead>
<tbody>

{% for manager in managers %}
{% for lied in lieder %}
<tr>
<td>{{manager.ManagerId}}</td>
<td>{{manager.Vorname}}</td>
<td>{{manager.Nachname}}</td>
<td>{{manager.Firma}}</td>
<td>{{manager.Kuenstler_anzahl}}</td>
<td><input type="checkbox" value="{{manager.ManagerId}}" onclick="Checkboxes()"></td>
<td>{{lied.LiedId}}</td>
<td>{{lied.Kuenstleranzahl}}</td>
<td>{{lied.Liedname}}</td>
<td>{{lied.Erscheinungsdatum}}</td>
<td><input type="checkbox" value="{{lied.LiedId}}" onclick="Checkboxes()"></td>


</tr>
Expand Down
20 changes: 8 additions & 12 deletions templates/lieder/editlieder.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,30 @@
{%block body%}


<button class="btn btn-warning" onclick= "window.location.href='/managers'">🔙Leave</button>
<button class="btn btn-warning" onclick= "window.location.href='/lieder'">🔙Leave</button>

<form method="POST">
{{form.csrf_token}}

<!-- {{ form.errors }} -->

{{form.ManagerID(class_="form-control")}}
{{form.LiedId(class_="form-control")}}

<div class="mb-3">
<label for="Vorname" class="form-label">Vorname</label>
{{form.Vorname(class_="form-control")}}
<label for="Vorname" class="form-label">Kuenstleranzahl</label>
{{form.Kuenstleranzahl(class_="form-control")}}
</div>

<div class="mb-3">
<label for="Nachname" class="form-label">Nachname</label>
{{form.Nachname(class_="form-control")}}
<label for="Nachname" class="form-label">Liedname</label>
{{form.Liedname(class_="form-control")}}
</div>

<div class="mb-3">
<label for="Firma" class="form-label">Firma</label>
{{form.Firma(class_="form-control")}}
<label for="Firma" class="form-label">Erscheinungsdatum</label>
{{form.Erscheinungsdatum(class_="form-control")}}
</div>

<div class="mb-3">
<label for="Kuenstler_anzahl" class="form-label">Kuenstler_anzahl</label>
{{form.Kuenstler_anzahl(class_="form-control")}}
</div>

<button type="submit" class="btn btn-primary">Save Changes</button>
</form>
Expand Down
30 changes: 14 additions & 16 deletions templates/lieder/viewlieder.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,31 @@

<ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<li><a class="dropdown-item" href="/">Hauptseite</a></li>
<li><a class="dropdown-item" href="/managers">View Managers</a></li>
<li><a class="dropdown-item" href="/managers/add">Add Managers</a></li>
<li><a class="dropdown-item" href="/managers/delete">Delete Managers</a></li>
<li><a class="dropdown-item" href="/lieder">View Lieder</a></li>
<li><a class="dropdown-item" href="/lieder/add">Add Lieder</a></li>
<li><a class="dropdown-item" href="/lieder/delete">Delete Lieder</a></li>
<!--<li><a class="dropdown-item" href="/products/add">Hinzufügen</a></li>-->
</ul>

<table class="table">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Vorname</th>
<th scope="col">Nachname</th>
<th scope="col">Firma</th>
<th scope="col">Kuenstler_anzahl</th>
<th scope="col">edit</th>
<th scope="col">LiedId</th>
<th scope="col">Kuenstleranzahl</th>
<th scope="col">Liedname</th>
<th scope="col">Erscheinungsdatum</th>

</tr>
</thead>
<tbody>

{% for manager in managers %}
{% for lied in lieder %}
<tr>
<td>{{manager.ManagerId}}</td>
<td>{{manager.Vorname}}</td>
<td>{{manager.Nachname}}</td>
<td>{{manager.Firma}}</td>
<td>{{manager.Kuenstler_anzahl}}</td>
<td><button class="btn btn-info " onclick= "window.location.href='/managers/edit?itemid={{manager.ManagerId}}'">✏️</button></td>
<td>{{lied.LiedId}}</td>
<td>{{lied.Kuenstleranzahl}}</td>
<td>{{lied.Liedname}}</td>
<td>{{lied.Erscheinungsdatum}}</td>
<td><button class="btn btn-info " onclick= "window.location.href='/lieder/edit?itemid={{lied.LiedId}}'">✏️</button></td>

</tr>
{% endfor %}
Expand Down

0 comments on commit b7544ce

Please sign in to comment.