summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorstilbruch <stilbruch@protonmail.com>2022-04-23 16:21:17 -0500
committerstilbruch <stilbruch@protonmail.com>2022-04-23 16:25:07 -0500
commita4ca3d81f5bf0d00f1326ee80878da4169f54ea6 (patch)
tree34e5ff51f8bae678578ce7189d0ad3d2f685cf12 /app
parentb45e96d88485f7c9a7b6281b781218e180a43e94 (diff)
downloadStrengthy-a4ca3d81f5bf0d00f1326ee80878da4169f54ea6.tar.xz
Strengthy-a4ca3d81f5bf0d00f1326ee80878da4169f54ea6.zip
Rename 'reps' to 'units' internally
Diffstat (limited to 'app')
-rw-r--r--app/forms/workout.py17
-rw-r--r--app/routes/workout.py21
-rw-r--r--app/static/js/create.js60
-rw-r--r--app/tables/workout.py10
4 files changed, 62 insertions, 46 deletions
diff --git a/app/forms/workout.py b/app/forms/workout.py
index 4a96b32..ecc72c8 100644
--- a/app/forms/workout.py
+++ b/app/forms/workout.py
@@ -2,12 +2,23 @@ from flask_wtf import FlaskForm, Form
from wtforms import FieldList, FormField, IntegerField, StringField
from wtforms.validators import DataRequired, Email
-# Subclass, not used directly
-class ExerciseForm(Form):
+# Subclasses
+class ExerciseCreateForm(Form):
name = StringField("name", [DataRequired()])
sets = IntegerField("sets", [DataRequired()])
+ units = IntegerField("units", [DataRequired()])
+
+class SetForm(Form):
+ lbs = IntegerField("lbs", [DataRequired()])
reps = IntegerField("reps", [DataRequired()])
+class ExerciseRecordForm(Form):
+ sets = FieldList(FormField(SetForm))
+
+# Actual forms
class WorkoutCreateForm(FlaskForm):
name = StringField("name", [DataRequired()])
- exercises = FieldList(FormField(ExerciseForm), min_entries=1)
+ exercises = FieldList(FormField(ExerciseCreateForm), min_entries=1)
+
+class WorkoutRecordForm(FlaskForm):
+ exercises = FieldList(FormField(ExerciseRecordForm))
diff --git a/app/routes/workout.py b/app/routes/workout.py
index 8615156..7144d40 100644
--- a/app/routes/workout.py
+++ b/app/routes/workout.py
@@ -1,12 +1,12 @@
from app import app, db
from flask import render_template, redirect, request, url_for, flash
from flask_login import current_user, login_required
-from forms import LoginForm, RegisterForm, WorkoutCreateForm
+from forms import WorkoutCreateForm, WorkoutRecordForm
from tables import User, Workout
@app.route("/workout/create", methods=['GET', 'POST'])
@login_required
-def createWorkout():
+def workout_create():
form = WorkoutCreateForm()
name = form.name.data
@@ -23,11 +23,11 @@ def createWorkout():
else:
flash("Workout with this name already exists", "danger")
- return render_template('workout/create.html', form=form, title="Create a Workout")
+ return render_template('workout/create.html', form=form)
@app.route("/workout/edit", methods=['GET', 'POST'])
@login_required
-def editWorkout():
+def workout_edit():
# Id is required
if 'id' not in request.args:
return redirect(url_for('home'))
@@ -57,9 +57,11 @@ def editWorkout():
return render_template('workout/create.html', form=form, title=f'Edit Workout "{workout.name}"')
-@app.route("/workout/record", methods=['GET'])
+@app.route("/workout/record", methods=['GET', 'POST'])
@login_required
-def recordWorkout():
+def workout_record():
+ form = WorkoutRecordForm()
+
# Id is required
if 'id' not in request.args:
return redirect(url_for('home'))
@@ -69,9 +71,12 @@ def recordWorkout():
if not workout:
return redirect(url_for('home'));
- return render_template('workout/record.html', workout=workout, form=None)
+ if form.validate_on_submit():
+ print(form)
+
+ return render_template('workout/record.html', workout=workout, form=form)
@app.route("/workout/select", methods=['GET'])
@login_required
-def selectWorkout():
+def workout_select():
return render_template('workout/select.html')
diff --git a/app/static/js/create.js b/app/static/js/create.js
index ade61da..7cdf328 100644
--- a/app/static/js/create.js
+++ b/app/static/js/create.js
@@ -3,50 +3,50 @@ var rowId = rowsDiv.children.length;
function handleAdd() {
- newRow = rowsDiv.children[0].cloneNode(true);
+ newRow = rowsDiv.children[0].cloneNode(true);
- exerciseNameInput = newRow.children[0].children[0].children[0].children[0];
- exerciseNameInput.value = '';
- exerciseNameInput.name = 'exercises-' + rowId + '-name';
+ exerciseNameInput = newRow.children[0].children[0].children[0].children[0];
+ exerciseNameInput.value = '';
+ exerciseNameInput.name = 'exercises-' + rowId + '-name';
- exerciseSetInput = newRow.children[0].children[1].children[0].children[0];
- exerciseSetInput.value = '';
- exerciseSetInput.name = 'exercises-' + rowId + '-sets';
+ exerciseSetInput = newRow.children[0].children[1].children[0].children[0];
+ exerciseSetInput.value = '';
+ exerciseSetInput.name = 'exercises-' + rowId + '-sets';
- exerciseUnitInput = newRow.children[0].children[2].children[1];
- exerciseUnitInput.value = '';
- exerciseUnitInput.placeholder = 'Reps';
- exerciseUnitInput.name = 'exercises-' + rowId + '-units';
+ exerciseUnitInput = newRow.children[0].children[2].children[1];
+ exerciseUnitInput.value = '';
+ exerciseUnitInput.placeholder = 'Reps';
+ exerciseUnitInput.name = 'exercises-' + rowId + '-units';
- exerciseUnitInput.parentNode.children[0].children[0].children[0].addEventListener("input", handleChange);
+ exerciseUnitInput.parentNode.children[0].children[0].children[0].addEventListener("input", handleChange);
- rowId++;
- rowsDiv.append(newRow);
+ rowId++;
+ rowsDiv.append(newRow);
}
function handleDel(elem) {
- if (rowId > 1) {
- elem.parentNode.parentNode.remove();
- rowId--;
- }
+ if (rowId > 1) {
+ elem.parentNode.parentNode.remove();
+ rowId--;
+ }
}
document.getElementById("add").onclick = handleAdd;
function handleChange(elem) {
- if (elem.target.value == 'time') {
- elem.target.parentNode.parentNode.parentNode.children[1].placeholder = "Time";
- elem.target.parentNode.parentNode.parentNode.children[1].selected = true;
- elem.target.parentNode.parentNode.children[1].children[0].classList.remove('fa-calculator');
- elem.target.parentNode.parentNode.children[1].children[0].classList.add('fa-clock-o');
- } else if (elem.target.value == 'reps') {
- elem.target.parentNode.parentNode.children[1].children[0].classList.add('fa-calculator');
- elem.target.parentNode.parentNode.children[1].children[0].classList.remove('fa-clock-o');
- elem.target.parentNode.parentNode.parentNode.children[1].selected = true;
- elem.target.parentNode.parentNode.parentNode.children[1].placeholder = "Reps";
- }
+ if (elem.target.value == 'time') {
+ elem.target.parentNode.parentNode.parentNode.children[1].placeholder = "Time";
+ elem.target.parentNode.parentNode.parentNode.children[1].selected = true;
+ elem.target.parentNode.parentNode.children[1].children[0].classList.remove('fa-calculator');
+ elem.target.parentNode.parentNode.children[1].children[0].classList.add('fa-clock-o');
+ } else if (elem.target.value == 'reps') {
+ elem.target.parentNode.parentNode.children[1].children[0].classList.add('fa-calculator');
+ elem.target.parentNode.parentNode.children[1].children[0].classList.remove('fa-clock-o');
+ elem.target.parentNode.parentNode.parentNode.children[1].selected = true;
+ elem.target.parentNode.parentNode.parentNode.children[1].placeholder = "Reps";
+ }
}
for (row of rowsDiv.children) {
- row.children[0].children[2].children[0].children[0].children[0].addEventListener('input', handleChange);
+ row.children[0].children[2].children[0].children[0].children[0].addEventListener('input', handleChange);
}
diff --git a/app/tables/workout.py b/app/tables/workout.py
index b86a3db..cff0762 100644
--- a/app/tables/workout.py
+++ b/app/tables/workout.py
@@ -6,17 +6,17 @@ class Exercise(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(100), nullable=False)
sets = db.Column(db.Integer)
- reps = db.Column(db.Integer)
+ units = db.Column(db.Integer)
# Workout Relationship
workout_id = db.Column(db.Integer, db.ForeignKey('workouts.id'))
- def __init__(self, name, sets, reps):
+ def __init__(self, name, sets, units):
self.name = name
self.sets = sets
- self.reps = reps
+ self.unit = units
def __repr__(self):
- return f'<Exercise {self.name} {self.sets}x{self.reps}>'
+ return f'<Exercise {self.name} {self.sets}x{self.units}>'
# Represents a singular workout
class Workout(db.Model):
@@ -34,7 +34,7 @@ class Workout(db.Model):
# Create exercises
for exercise in exercises:
- self.exercises.append(Exercise(exercise['name'], exercise['sets'], exercise['reps']))
+ self.exercises.append(Exercise(exercise['name'], exercise['sets'], exercise['units']))
def __repr__(self):
return f'<Workout {self.name}>'