From c16922be367a03812cc4ef87b94537eb71c5615f Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Sat, 23 Jul 2022 18:59:21 +1000 Subject: [PATCH] Migrate data and improve ui --- app.py | 33 ++------------ db.py | 2 + swagger/base.json | 16 +++++++ templates/person.html | 98 ++++++++++++++++++++++++++++++++++++++++ templates/workout.html | 11 ++++- templates/workouts.html | 87 ----------------------------------- workout.db | Bin 24576 -> 24576 bytes 7 files changed, 130 insertions(+), 117 deletions(-) create mode 100644 swagger/base.json create mode 100644 templates/person.html delete mode 100644 templates/workouts.html 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 110ac684888caf1cd6e47f477487cb13383777bc..794c68852abb4711a2f52a13fb0d50a13aab5e04 100644 GIT binary patch literal 24576 zcmeI4ZEPb)8OQf!*3OJ~W|CZTPR^HP^LFRF_~Kp1anh!xzQmVHlQ=%d>D^IE@Fflx zHJ4lxA3dZVA}OeqKnNtn`v+bGDhLTGA@KoKDgwcmA}CUYkf=(9ggB^xN>xGPLz(rg zWA9xKzEz+;BgOtd|9L$7%x`urjWWs7h53zg$y(puy;dw+38hg{RplYeQWWL3_z8%g zYHJY!RRi&^*6Dl6+sc`lXDL5WjL?$`kF&4SFPkkwLIVOo00;m9AOHk_01yBI?>Yke zt$|>;qeI=lRW4rHEM;z%c2_s{4&RNbd?sDUScUZ2`Ha<5?e4Lnlvtu2IHWTB*k>WG)pvCzqdHNartGbD7Ig-v`sng~i#dxYR->TNrRZKJXMWg5mad z_2a9Rx(eIZmr7;%8t~U7&00k=KBAtB+q;i%-zXo^Q=QfkUHQ`WQhB4ivAwl-*90$? zHa>W@e5dW3Wvv+h96ciE7W0|enXDvIt8c){XU=8vne0?%$?|L~de}c;EoQCh%zQ>H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