diff --git a/app.py b/app.py index fefdc9f..b350ce1 100644 --- a/app.py +++ b/app.py @@ -1,34 +1,12 @@ -from flask import Flask, abort, render_template, g, redirect, request, url_for +from flask import Flask, render_template, redirect, request, url_for from flasgger import Swagger, swag_from -from functools import wraps -import sqlite3 from db import DataBase from decorators import validate_person, validate_topset, validate_workout -template = { - "swagger": "2.0", - "info": { - "title": "WorkoutTracker API", - "description": "API for tracking topsets of workouts", - "contact": { - "responsibleOrganization": "ME", - "responsibleDeveloper": "Me", - "email": "me@me.com", - "url": "www.me.com", - }, - "version": "0.0.1" - }, - "schemes": [ - "http", - "https" - ], - "operationId": "getmyData" -} - app = Flask(__name__) app.config.from_pyfile('config.py') -swagger = Swagger(app, template=template) +swagger = Swagger(app, template_file='swagger/base.json') db = DataBase(app) @@ -44,7 +22,7 @@ def dashboard(): @ validate_person def get_person(person_id): person = db.get_person_final(person_id) - return render_template('workouts.html', person=person) + return render_template('person.html', person=person) @ app.route("/person//workout", methods=['POST']) @@ -117,10 +95,7 @@ def my_utility_processor(): return '' def get_list_of_people_and_workout_count(): - person_id = -1 - if 'person_id' in request.view_args: - person_id = request.view_args['person_id'] - + person_id = request.view_args.get('person_id') return db.get_people_and_workout_count(person_id) def get_first_element_from_list_with_matching_attribute(list, attribute, value): diff --git a/db.py b/db.py index c720517..9f4e7c8 100644 --- a/db.py +++ b/db.py @@ -41,6 +41,8 @@ class DataBase(): return topset def delete_workout(self, workout_id): + self.execute('DELETE FROM TopSet WHERE WorkoutId=?', + [workout_id], commit=True) self.execute('DELETE FROM Workout WHERE WorkoutId=?', [workout_id], commit=True) diff --git a/swagger/base.json b/swagger/base.json new file mode 100644 index 0000000..2ff9b20 --- /dev/null +++ b/swagger/base.json @@ -0,0 +1,16 @@ +{ + "swagger": "2.0", + "info": { + "title": "WorkoutTracker API", + "description": "API for tracking topsets of workouts", + "contact": { + "responsibleOrganization": "ME", + "responsibleDeveloper": "Me", + "email": "me@me.com", + "url": "www.me.com" + }, + "version": "0.0.1" + }, + "schemes": ["http", "https"], + "operationId": "getmyData" +} diff --git a/templates/person.html b/templates/person.html new file mode 100644 index 0000000..cf698ce --- /dev/null +++ b/templates/person.html @@ -0,0 +1,98 @@ +{% extends 'base.html' %} + +{% block content %} +
+
+ +
+
+

{{ person['PersonName'] }}

+ List of workouts +
+
+
+ +
+
+
+ +
+
+
+
+ + {% if person['Workouts']|length > 0 %} + + + + + {% for e in person['Exercises'] %} + + {% endfor %} + + + + + + {% for w in person['Workouts'] %} + + + + {% for e in person['Exercises'] %} + + {% endfor %} + + + + {% endfor %} + + +
+ Date + + {{ e['ExerciseName'] }} + +
+ {{ w['StartDate'] }} + + {% set topset_exercise = + get_first_element_from_list_with_matching_attribute(w['TopSets'], 'ExerciseId', + e['ExerciseId']) %} + {% if topset_exercise %} + {{ topset_exercise['Repetitions'] }} x {{ topset_exercise['Weight'] }}kg + {% endif %} + + + Edit + + +
+ +
+
+ {% endif %} + + {% if person['Workouts']|length == 0 %} + + {% endif %} + +
+
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/templates/workout.html b/templates/workout.html index f68f48e..29b3b4b 100644 --- a/templates/workout.html +++ b/templates/workout.html @@ -12,7 +12,7 @@
@@ -26,6 +26,8 @@
+ + {% if workout['TopSets']|length > 0 %} @@ -62,6 +64,13 @@ {% endfor %}
+ {% endif %} + + {% if workout['TopSets']|length == 0 %} + + {% endif %}
diff --git a/templates/workouts.html b/templates/workouts.html deleted file mode 100644 index 031ceeb..0000000 --- a/templates/workouts.html +++ /dev/null @@ -1,87 +0,0 @@ -{% extends 'base.html' %} - -{% block content %} - -
- -
-
-

{{ person['PersonName'] }}

- List of workouts -
-
- -
-
-
-
- - - - - {% for e in person['Exercises'] %} - - {% endfor %} - - - - - - {% for w in person['Workouts'] %} - - - - {% for e in person['Exercises'] %} - - {% endfor %} - - - - {% endfor %} - - -
- Date - - {{ e['ExerciseName'] }} - -
- {{ w['StartDate'] }} - - {% set topset_exercise = - get_first_element_from_list_with_matching_attribute(w['TopSets'], 'ExerciseId', - e['ExerciseId']) %} - {% if topset_exercise %} - {{ topset_exercise['Repetitions'] }} x {{ topset_exercise['Weight'] }}kg - {% endif %} - - - Edit - - -
- -
-
- -
- -
- -
-
-
-
-
- -{% endblock %} \ No newline at end of file diff --git a/workout.db b/workout.db index 110ac68..794c688 100644 Binary files a/workout.db and b/workout.db differ