Permalink
Browse files

got saving workouts to work, onto displaying and deleting them

  • Loading branch information...
jamiltron committed May 14, 2011
1 parent 53bcc63 commit 04bb82ecadab0db93e2f8095f90773337b3ab042
Showing with 33 additions and 9 deletions.
  1. +2 −4 docs/TODO
  2. BIN fitgen.db
  3. +15 −5 fitgen.py
  4. +7 −0 schema.sql
  5. +9 −0 templates/show_exercises.html
View
@@ -1,12 +1,10 @@
TODO
-+ Format results (maybe add more information than just name)
+ Learn SQLAlchemy
+ Allow the declining of an exercise from a generated list
+ Implement an "admin" screen to modify exercise lists more gracefully
-+ Add more exercises
+ Allow users to change passwords
-+ Add captchas or something like it to registration
-+ Allow users to save specific workouts
+ Look into Facebook integration
+ /Maybe/ allow users to add new equipment and exercises
++ Make sure users cannot save too many workouts
++ Allow users to delete workouts
View
BIN fitgen.db
Binary file not shown.
View
@@ -93,8 +93,6 @@ def build_query(muscles=[], types=[], equip=[], force=None, limit=1):
query += " AND "
query += equip[i] + " != 1"
query += ') ORDER BY RANDOM() LIMIT ' + str(limit) + ";"
-
- # print the query for shoddy debugging purposes and then
print query
return query
@@ -135,7 +133,6 @@ def cpanel():
insert_query[:len(insert_query)-1]
insert_query += " WHERE login_name='"
insert_query += str(session['username']) + "';"
- print "INSERT QUERY: " + insert_query
try:
g.db.execute(insert_query)
g.db.commit()
@@ -206,9 +203,22 @@ def login():
def termsofservice():
return render_template('termsofservice.html')
+@app.route('/save_workout', methods=['POST'])
+def save_workout():
+ """Records the currently-generated workout to the workouts database
+ with the corresponding user's name attached to it"""
+ if not session.get('logged_in'):
+ abort(401)
+ to_save = request.form['entries'].replace('[', '').replace(']', '')
+ g.db.execute('insert into workouts (user_saved, exercises) values (?, ?)',
+ [session.get('username'), to_save])
+ g.db.commit()
+ flash("Workout saved successfully")
+ return redirect(url_for('index'))
+
@app.route('/logout')
def logout():
- """pops the user's information off of the session stack and returns
+ """Pops the user's information off of the session stack and returns
a flash message stating this has been done"""
session.pop('logged_in', None)
session.pop('username', None)
@@ -348,7 +358,7 @@ def forgot():
@app.route('/workout', methods=['POST'])
def random_workout():
- """the logic behind the random workout"""
+ """The logic behind the random workout"""
if request.method == 'POST':
global equip_list, muscle_dict, type_list
equip_exclude = []
View
@@ -28,6 +28,13 @@ create table users (
secret_answer string not null
);
+drop table if exists workouts;
+create table workouts (
+ id integer primary key autoincrement,
+ user_saved string not null,
+ exercises string not null
+);
+
drop table if exists exercises;
create table exercises (
id integer primary key autoincrement,
@@ -7,6 +7,15 @@
<li><em>Unbelievable. No exercises here so far.</em>
{% endfor %}
</ul>
+ {% if session.logged_in %}
+ <form action="{{ url_for('save_workout') }}" method=post class=add-entry>
+ <dl>
+ <dd><input type=hidden name=entries value="{{ entries }}">
+ <dd><input type=submit value="Save this Workout">
+ </dl>
+ </form>
+ {% endif %}
+ <br>
<br>
<a href="{{ url_for('index') }}"><b>Return home</b></a>
{% endblock %}

0 comments on commit 04bb82e

Please sign in to comment.