Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

previous card functionality #109

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions flash_cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,41 @@ def memorize_known(card_type, card_id=None):
short_answer=short_answer, tags=tags)


@app.route('/previous_card/<card_type>/<card_id>')
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()

Expand Down
8 changes: 7 additions & 1 deletion templates/memorize.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,15 @@ <h3 class="text-center">{{ card.front }}</h3>
</a>
&nbsp;
&nbsp;
<a href="{{ url_for('previous_card', card_type=card_type, card_id=card.id) }}" class="btn btn-primary btn-lg">
<i class="fa fa-arrow-left"></i>
Previous Card
</a>
&nbsp;
&nbsp;
<a href="{{ url_for('memorize', card_type=card_type) }}" class="btn btn-primary btn-lg">
Next Card
<i class="fa fa-arrow-right"></i>
Next Card
</a>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions templates/memorize_known.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ <h3 class="text-center">{{ card.front }}</h3>
</a>
&nbsp;
&nbsp;
<a href="{{ url_for('previous_card', card_type=card_type, card_id=card.id) }}" class="btn btn-primary btn-lg">
<i class="fa fa-arrow-left"></i>
Previous Card
</a>
&nbsp;
&nbsp;
<a href="{{ url_for('memorize_known', card_type=card_type) }}" class="btn btn-primary btn-lg">
Next Card
<i class="fa fa-arrow-right"></i>
Expand Down