Add ability to dynamically add/remove users & exercises
This commit is contained in:
30
app.py
30
app.py
@@ -91,10 +91,38 @@ def delete_topset(person_id, workout_id, topset_id):
|
|||||||
return redirect(url_for('get_workout', person_id=person_id, workout_id=workout_id))
|
return redirect(url_for('get_workout', person_id=person_id, workout_id=workout_id))
|
||||||
|
|
||||||
|
|
||||||
|
@ app.route("/person", methods=['POST'])
|
||||||
|
def create_person():
|
||||||
|
name = request.form.get("name")
|
||||||
|
db.create_person(name)
|
||||||
|
return redirect(url_for('settings'))
|
||||||
|
|
||||||
|
|
||||||
|
@ app.route("/person/<int:person_id>/delete", methods=['GET', 'POST'])
|
||||||
|
def delete_person(person_id):
|
||||||
|
db.delete_person(person_id)
|
||||||
|
return redirect(url_for('settings'))
|
||||||
|
|
||||||
|
|
||||||
|
@ app.route("/exercise", methods=['POST'])
|
||||||
|
def create_exercise():
|
||||||
|
name = request.form.get("name")
|
||||||
|
db.create_exercise(name)
|
||||||
|
return redirect(url_for('settings'))
|
||||||
|
|
||||||
|
|
||||||
|
@ app.route("/exercise/<int:exercise_id>/delete", methods=['GET', 'POST'])
|
||||||
|
def delete_exercise(exercise_id):
|
||||||
|
db.delete_exercise(exercise_id)
|
||||||
|
return redirect(url_for('settings'))
|
||||||
|
|
||||||
|
|
||||||
@ app.route("/settings")
|
@ app.route("/settings")
|
||||||
@ swag_from('swagger/dashboard.yml')
|
@ swag_from('swagger/dashboard.yml')
|
||||||
def settings():
|
def settings():
|
||||||
return render_template('settings.html')
|
people = db.get_people()
|
||||||
|
exercises = db.get_exercises()
|
||||||
|
return render_template('settings.html', people=people, exercises=exercises)
|
||||||
|
|
||||||
|
|
||||||
@ app.context_processor
|
@ app.context_processor
|
||||||
|
|||||||
25
db.py
25
db.py
@@ -43,11 +43,36 @@ class DataBase():
|
|||||||
'SELECT ExerciseId AS "ExerciseId", Name AS "Name" FROM Exercise')
|
'SELECT ExerciseId AS "ExerciseId", Name AS "Name" FROM Exercise')
|
||||||
return [{"ExerciseId": e['ExerciseId'], "Name": e['Name']} for e in exercises]
|
return [{"ExerciseId": e['ExerciseId'], "Name": e['Name']} for e in exercises]
|
||||||
|
|
||||||
|
def create_exercise(self, name):
|
||||||
|
self.execute('INSERT INTO Exercise (Name) VALUES (%s)',
|
||||||
|
[name], commit=True)
|
||||||
|
|
||||||
|
def delete_exercise(self, exercise_id):
|
||||||
|
self.execute('DELETE FROM Exercise WHERE ExerciseId=%s', [
|
||||||
|
exercise_id], commit=True)
|
||||||
|
|
||||||
|
def get_people(self):
|
||||||
|
people = self.execute(
|
||||||
|
'SELECT PersonId AS "PersonId", Name AS "Name" FROM Person')
|
||||||
|
return people
|
||||||
|
|
||||||
def get_person(self, person_id):
|
def get_person(self, person_id):
|
||||||
person = self.execute(
|
person = self.execute(
|
||||||
'SELECT PersonId AS "PersonId" FROM Person WHERE PersonId=%s LIMIT 1', [person_id], one=True)
|
'SELECT PersonId AS "PersonId" FROM Person WHERE PersonId=%s LIMIT 1', [person_id], one=True)
|
||||||
return person
|
return person
|
||||||
|
|
||||||
|
def create_person(self, name):
|
||||||
|
self.execute('INSERT INTO Person (Name) VALUES (%s)',
|
||||||
|
[name], commit=True)
|
||||||
|
|
||||||
|
def delete_person(self, person_id):
|
||||||
|
self.execute('DELETE FROM TopSet WHERE WorkoutId IN (SELECT WorkoutId FROM Workout WHERE PersonId=%s)', [
|
||||||
|
person_id], commit=True)
|
||||||
|
self.execute('DELETE FROM Workout WHERE PersonId=%s',
|
||||||
|
[person_id], commit=True)
|
||||||
|
self.execute('DELETE FROM Person WHERE PersonId=%s',
|
||||||
|
[person_id], commit=True)
|
||||||
|
|
||||||
def get_workout(self, person_id, workout_id):
|
def get_workout(self, person_id, workout_id):
|
||||||
workout = self.execute('SELECT W.WorkoutId AS "WorkoutId" FROM Person P, Workout W WHERE P.PersonId=W.PersonId AND P.PersonId=%s AND W.WorkoutId=%s LIMIT 1', [
|
workout = self.execute('SELECT W.WorkoutId AS "WorkoutId" FROM Person P, Workout W WHERE P.PersonId=W.PersonId AND P.PersonId=%s AND W.WorkoutId=%s LIMIT 1', [
|
||||||
person_id, workout_id], one=True)
|
person_id, workout_id], one=True)
|
||||||
|
|||||||
@@ -31,34 +31,22 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody class="bg-white">
|
<tbody class="bg-white">
|
||||||
|
{% for p in people %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
|
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
|
||||||
1
|
{{ loop.index }}
|
||||||
</td>
|
</td>
|
||||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||||
Gabe
|
{{ p['Name'] }}
|
||||||
</td>
|
</td>
|
||||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||||
<a href="/person/2/workout/10"
|
<a href="{{ url_for('delete_person', person_id=p['PersonId']) }}"
|
||||||
class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg inline-flex items-center p-2">
|
|
||||||
Remove
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
|
|
||||||
2
|
|
||||||
</td>
|
|
||||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
|
||||||
Michael
|
|
||||||
</td>
|
|
||||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
|
||||||
<a href="/person/2/workout/10"
|
|
||||||
class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg inline-flex items-center p-2">
|
class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg inline-flex items-center p-2">
|
||||||
Remove
|
Remove
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
@@ -66,7 +54,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form class="w-full mt-3" action="/user" method="post">
|
<form class="w-full mt-3" action="{{ url_for('create_person') }}" method="post">
|
||||||
<div class="flex flex-wrap -mx-3 mb-2">
|
<div class="flex flex-wrap -mx-3 mb-2">
|
||||||
<div class="grow px-3">
|
<div class="grow px-3">
|
||||||
<label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="grid-city">
|
<label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="grid-city">
|
||||||
@@ -123,48 +111,22 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody class="bg-white">
|
<tbody class="bg-white">
|
||||||
|
{% for e in exercises %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
|
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
|
||||||
1
|
{{ loop.index }}
|
||||||
</td>
|
</td>
|
||||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||||
Squat
|
{{ e['Name'] }}
|
||||||
</td>
|
</td>
|
||||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||||
<a href="/person/2/workout/10"
|
<a href="{{ url_for('delete_exercise', exercise_id=e['ExerciseId']) }}"
|
||||||
class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg inline-flex items-center p-2">
|
|
||||||
Remove
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
|
|
||||||
1
|
|
||||||
</td>
|
|
||||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
|
||||||
Deadlift
|
|
||||||
</td>
|
|
||||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
|
||||||
<a href="/person/2/workout/10"
|
|
||||||
class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg inline-flex items-center p-2">
|
|
||||||
Remove
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
|
|
||||||
1
|
|
||||||
</td>
|
|
||||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
|
||||||
Bench
|
|
||||||
</td>
|
|
||||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
|
||||||
<a href="/person/2/workout/10"
|
|
||||||
class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg inline-flex items-center p-2">
|
class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg inline-flex items-center p-2">
|
||||||
Remove
|
Remove
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
@@ -172,7 +134,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form class="w-full mt-3" action="/user" method="post">
|
<form class="w-full mt-3" action="{{ url_for('create_exercise') }}" method="post">
|
||||||
<div class="flex flex-wrap -mx-3 mb-2">
|
<div class="flex flex-wrap -mx-3 mb-2">
|
||||||
<div class="grow px-3">
|
<div class="grow px-3">
|
||||||
<label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="grid-city">
|
<label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="grid-city">
|
||||||
|
|||||||
Reference in New Issue
Block a user