Skip to content

Commit

Permalink
19.04.2022
Browse files Browse the repository at this point in the history
  • Loading branch information
fifthaccess committed Apr 19, 2022
1 parent deb8e5f commit ef7ebda
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 31 deletions.
22 changes: 18 additions & 4 deletions controllers/manager.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from ast import Del
from operator import index
from pyexpat import model
from flask import Flask, redirect, request, flash
Expand All @@ -6,8 +7,8 @@
import sqlalchemy
import sqlalchemy.orm
from model.models import db
from forms.Manager import ManagerForm
from model.models import Manager
from forms.Manager import ManagerForm , DeleteManagerFrom
from model.models import Manager

manager_blueprint = Blueprint('manager_blueprint',__name__)

Expand All @@ -27,7 +28,7 @@ def manager_add():
add_manager_form = ManagerForm()
managers = session.query(Manager).order_by(Manager.ManagerId).all()
if request.method == 'POST':

print("f")
if add_manager_form.validate_on_submit():
new_manager = Manager()

Expand All @@ -45,9 +46,22 @@ def manager_add():

else:
return render_template("manager/addmanager.html", headline = "Add Managers", form = add_manager_form, managers = managers)

else:
return render_template("manager/addmanager.html", headline = "Add Managers", form = add_manager_form, managers = managers)

@manager_blueprint.route('/managers/delete', methods=["Get", "Post"])
def manager_delete ():
def manager_delete():
session : sqlalchemy.orm.scoping.scoped_session = db.session
managers = session.query(Manager).order_by(Manager.ManagerId).all()
del_form = DeleteManagerFrom()
if request.method == 'POST':
print("f")
if del_form.validate_on_submit():
print(del_form.CheckedCheckboxes.data)
else:
print("invalide Form")
return render_template("manager/deleteManager.html", managers = managers, headline = "Delete Managers", form = del_form )

else:
return render_template("manager/deleteManager.html", managers = managers, headline = "Delete Managers", form = del_form )
9 changes: 6 additions & 3 deletions forms/Manager.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from operator import imod
from flask_wtf import FlaskForm
from wtforms.fields.datetime import DateField
from wtforms.fields.datetime import DateField
from wtforms.fields.simple import BooleanField, StringField, TextAreaField ,HiddenField
from wtforms.fields import DecimalField
from wtforms.fields import DecimalField, FieldList
from wtforms import validators
from model.models import Kuenstler

Expand All @@ -11,4 +11,7 @@ class ManagerForm(FlaskForm):
Vorname = StringField("Vorname")
Nachname = StringField("Nachname")
Firma = StringField("Firma")
Kuenstler_anzahl = DecimalField("Kuenstler_anzahl")
Kuenstler_anzahl = DecimalField("Kuenstler_anzahl")

class DeleteManagerFrom(FlaskForm):
CheckedCheckboxes = HiddenField("Checked")
89 changes: 65 additions & 24 deletions templates/manager/deleteManager.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,41 @@

{%block body%}

<!--{% with messages = get_flashed_messages() %}
{% if messages %}
<div class="alert alert-warning alert-dismissible fade show" role="alert">
{% for message in messages %}
{{ message }}
{% endfor %}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
{% endif %}
{% endwith %}-->
<script type="text/javascript">
function Checkboxes()
{
var i;
let Checked_Checkedbox = [];
let c = document.querySelectorAll("input[type=checkbox]");

/* jede Checkbox abchecken und wenn ausgewaehlt auflisten : */
for (i=0;i<c.length;i++)
if (c[i].checked == true){
Checked_Checkedbox.push(c[i].value)
}
let test = Checked_Checkedbox.join(",")
document.getElementById("Checked").value = test
console.log(test);


}

function Try()
{
console.log(document.getElementById("ManagersToDelete").value);
}
</script>

<a class="nav-link dropdown-toggle" href="/products" id="navbarDropdownMenuLink" role="button"
data-bs-toggle="dropdown" aria-expanded="false">
Optionen
Expand All @@ -11,36 +46,42 @@
<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="/products/add">Hinzufügen</a></li>-->
</ul>
<form method="POST" >
<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" style="color:red">Delete❌</th>
</tr>
</thead>
<tbody>

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

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


<div class="mb-3">
<label for="Vorname" class="form-label">Vorname</label>
{{form.Vorname(class_="form-control")}}
</div>
{% for manager in managers %}
<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>

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

</tr>
{% endfor %}

<div class="mb-3">
<label for="Firma" class="form-label">Firma</label>
{{form.Firma(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>
</tbody>
</table>

<input type ="hidden" name = "Checked" id ="Checked" value ="">

<button type="submit" class="btn btn-primary">Submit</button>
<button type="submit" class="btn btn-primary" onclick="Try()">Delete</button>
</form>

{%endblock%}

0 comments on commit ef7ebda

Please sign in to comment.