diff --git a/flash_cards.py b/flash_cards.py index 84ab4ac9..166c6796 100644 --- a/flash_cards.py +++ b/flash_cards.py @@ -173,20 +173,22 @@ def delete(card_id): @app.route('/general') -def general(): +@app.route('/general/') +def general(card_id=None): if not session.get('logged_in'): return redirect(url_for('login')) - return memorize("general") + return memorize("general", card_id) @app.route('/code') -def code(): +@app.route('/code/') +def code(card_id=None): if not session.get('logged_in'): return redirect(url_for('login')) - return memorize("code") + return memorize("code", card_id) -def memorize(card_type): +def memorize(card_type, card_id): if card_type == "general": type = 1 elif card_type == "code": @@ -194,7 +196,10 @@ def memorize(card_type): else: return redirect(url_for('cards')) - card = get_card(type) + if card_id: + card = get_card_by_id(card_id) + else: + card = get_card(type) if not card: flash("You've learned all the " + card_type + " cards.") return redirect(url_for('cards')) @@ -223,6 +228,22 @@ def get_card(type): return cur.fetchone() +def get_card_by_id(card_id): + db = get_db() + + query = ''' + SELECT + id, type, front, back, known + FROM cards + WHERE + id = ? + LIMIT 1 + ''' + + cur = db.execute(query, [card_id]) + return cur.fetchone() + + @app.route('/mark_known//') def mark_known(card_id, card_type): if not session.get('logged_in'): diff --git a/static/general.js b/static/general.js index c3f47cf0..b72bad7c 100644 --- a/static/general.js +++ b/static/general.js @@ -2,8 +2,13 @@ $(document).ready(function(){ if ($('.memorizePanel').length != 0) { $('.flipCard').click(function(){ - $('.cardFront').hide(); - $('.cardBack').show(); + if ($('.cardFront').is(":visible") == true) { + $('.cardFront').hide(); + $('.cardBack').show(); + } else { + $('.cardFront').show(); + $('.cardBack').hide(); + } }); } diff --git a/templates/memorize.html b/templates/memorize.html index 52077fdd..8c6de67d 100644 --- a/templates/memorize.html +++ b/templates/memorize.html @@ -87,5 +87,17 @@

{{ card.front }}

+ {% endblock %} \ No newline at end of file