diff --git a/workouts/app/database.sqlite b/workouts/app/database.sqlite index d14166f..1ca0b1c 100644 Binary files a/workouts/app/database.sqlite and b/workouts/app/database.sqlite differ diff --git a/workouts/app/models.py b/workouts/app/models.py index 936ed3c..3dcd522 100644 --- a/workouts/app/models.py +++ b/workouts/app/models.py @@ -32,9 +32,8 @@ class Exercise(Model): return instr def __repr__(self): - name = self.name - musclegroup = self.musclegroup - instr = self.instructions() - return name+": This is a(n) "+musclegroup+" exercise. Instructions: "+instr + rep = self.to_dict() + rep["instructions"] = self.instructions() + return rep diff --git a/workouts/app/views.py b/workouts/app/views.py index 02a9858..da4c0f2 100644 --- a/workouts/app/views.py +++ b/workouts/app/views.py @@ -4,7 +4,11 @@ from app.models import Exercise from random import choice, sample from app.exlist import init_starting_exs -init_starting_exs() +#Done +@route_get("populate_workouts", args ={}) +def populate_workouts(params): + init_starting_exs() + return "Workouts populated." #Done @route_get("all", args = {}) @@ -31,13 +35,28 @@ def workout_with_length(params): else: raise BadRequest("There are not enough exercises to pick that many.") +#Done @route_get("full_body", args={}) #Returns one random exercise from each muscle group def workout_full_body(params): - return "in progress" + all_ex = {'cardio':[],'legs':[],'arms':[],'back':[],'chest':[],"abs":[]} + for mg in all_ex.keys(): + rand_ex = choice(Exercise.objects.filter(musclegroup=mg)) + all_ex[mg].append(rand_ex.__repr__()) + return all_ex +#Done @route_post("edit_exercise", args={"name":str,"category to edit":str,"new value":int}) #Allows a change to an exercise weight, reps, sets, time, or distance (numbers) def edit_exercise(params): - return "in progress" + ex_name = params["name"] + category = params["category to edit"] + new_val = params["new value"] + ex = Exercise.objects.get(name=ex_name) + ex_dict = ex.to_dict() + ex_dict[category] = new_val + edited = Exercise.from_dict(ex_dict) + ex.delete() + edited.save() + return "Updates: "+str(edited.__repr__()) #Done @route_post("new_exercise",args={"name":str,"musclegroup":str,"weight":int,"reps":int,"sets":int,"timemins":int,"distance":int})