Skip to content

Commit

Permalink
got saving workouts to work, onto displaying and deleting them
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiltron committed May 14, 2011
1 parent 53bcc63 commit 04bb82e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
6 changes: 2 additions & 4 deletions docs/TODO
@@ -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

Binary file modified fitgen.db
Binary file not shown.
20 changes: 15 additions & 5 deletions fitgen.py
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 = []
Expand Down
7 changes: 7 additions & 0 deletions schema.sql
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions templates/show_exercises.html
Expand Up @@ -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.