diff --git a/flash_cards.py b/flash_cards.py index 1a8715b7..3e316440 100644 --- a/flash_cards.py +++ b/flash_cards.py @@ -217,6 +217,41 @@ def memorize_known(card_type, card_id=None): short_answer=short_answer, tags=tags) +@app.route('/previous_card//') +def previous_card(card_type, card_id=None): + if not session.get('logged_in'): + return redirect(url_for('login')) + + # Get the previous card (lesser ID) for the given type + db = get_db() + + query = ''' + SELECT + id, type, front, back, known + FROM cards + WHERE + type = ? AND id < ? + ORDER BY id DESC + LIMIT 1 + ''' + + cur = db.execute(query, [card_type, card_id]) + previous_card = cur.fetchone() + + # If no previous card, redirect to the current card or show a message + if not previous_card: + flash("This is the first card.") + return redirect(url_for('memorize_known', card_type=card_type, card_id=card_id)) + + short_answer = (len(previous_card['back']) < 75) + tags = getAllTag() + + return render_template('memorize_known.html', + card=previous_card, + card_type=card_type, + short_answer=short_answer, tags=tags) + + def get_card(type): db = get_db() diff --git a/templates/memorize.html b/templates/memorize.html index be3cccb5..95857dbb 100644 --- a/templates/memorize.html +++ b/templates/memorize.html @@ -82,9 +82,15 @@

{{ card.front }}

    + + + Previous Card + +   +   - Next Card + Next Card diff --git a/templates/memorize_known.html b/templates/memorize_known.html index d09ea76a..f2068d18 100644 --- a/templates/memorize_known.html +++ b/templates/memorize_known.html @@ -60,6 +60,12 @@

{{ card.front }}

    + + + Previous Card + +   +   Next Card