Add method memorize use tag id
This commit is contained in:
@@ -59,7 +59,7 @@ def initdb():
|
|||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
if session.get('logged_in'):
|
if session.get('logged_in'):
|
||||||
return redirect(url_for('general'))
|
return redirect(url_for('mem', card_type="1"))
|
||||||
else:
|
else:
|
||||||
return redirect(url_for('login'))
|
return redirect(url_for('login'))
|
||||||
|
|
||||||
@@ -184,7 +184,7 @@ def delete(card_id):
|
|||||||
def general(card_id=None):
|
def general(card_id=None):
|
||||||
if not session.get('logged_in'):
|
if not session.get('logged_in'):
|
||||||
return redirect(url_for('login'))
|
return redirect(url_for('login'))
|
||||||
return memorize("general", card_id)
|
return mem("1", card_id)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/code')
|
@app.route('/code')
|
||||||
@@ -194,6 +194,35 @@ def code(card_id=None):
|
|||||||
return redirect(url_for('login'))
|
return redirect(url_for('login'))
|
||||||
return memorize("code", card_id)
|
return memorize("code", card_id)
|
||||||
|
|
||||||
|
@app.route('/test')
|
||||||
|
@app.route('/test/<card_id>')
|
||||||
|
def test(card_id=None):
|
||||||
|
if not session.get('logged_in'):
|
||||||
|
return redirect(url_for('login'))
|
||||||
|
return memorize("test", card_id)
|
||||||
|
|
||||||
|
@app.route('/mem')
|
||||||
|
@app.route('/mem/<card_id>')
|
||||||
|
@app.route('/mem/<card_type>')
|
||||||
|
def mem(card_type, card_id=None):
|
||||||
|
tag = getTag(card_type)
|
||||||
|
if tag is None:
|
||||||
|
return redirect(url_for('cards'))
|
||||||
|
|
||||||
|
if card_id:
|
||||||
|
card = get_card_by_id(card_id)
|
||||||
|
else:
|
||||||
|
card = get_card(card_type)
|
||||||
|
if not card:
|
||||||
|
flash("You've learned all the " + card_type + " cards.")
|
||||||
|
return redirect(url_for('cards'))
|
||||||
|
short_answer = (len(card['back']) < 75)
|
||||||
|
tags = getAllTag()
|
||||||
|
card_type = int(card_type)
|
||||||
|
return render_template('memorize.html',
|
||||||
|
card=card,
|
||||||
|
card_type=card_type,
|
||||||
|
short_answer=short_answer, tags=tags)
|
||||||
|
|
||||||
def memorize(card_type, card_id):
|
def memorize(card_type, card_id):
|
||||||
if card_type == "general":
|
if card_type == "general":
|
||||||
@@ -211,10 +240,11 @@ def memorize(card_type, card_id):
|
|||||||
flash("You've learned all the " + card_type + " cards.")
|
flash("You've learned all the " + card_type + " cards.")
|
||||||
return redirect(url_for('cards'))
|
return redirect(url_for('cards'))
|
||||||
short_answer = (len(card['back']) < 75)
|
short_answer = (len(card['back']) < 75)
|
||||||
|
tags = getAllTag()
|
||||||
return render_template('memorize.html',
|
return render_template('memorize.html',
|
||||||
card=card,
|
card=card,
|
||||||
card_type=card_type,
|
card_type=card_type,
|
||||||
short_answer=short_answer)
|
short_answer=short_answer, tags=tags)
|
||||||
|
|
||||||
|
|
||||||
def get_card(type):
|
def get_card(type):
|
||||||
@@ -291,7 +321,7 @@ def getAllTag():
|
|||||||
query = '''
|
query = '''
|
||||||
SELECT id, tagName
|
SELECT id, tagName
|
||||||
FROM tags
|
FROM tags
|
||||||
ORDER BY id DESC
|
ORDER BY id ASC
|
||||||
'''
|
'''
|
||||||
cur = db.execute(query)
|
cur = db.execute(query)
|
||||||
tags = cur.fetchall()
|
tags = cur.fetchall()
|
||||||
@@ -322,14 +352,15 @@ def add_tag():
|
|||||||
def edit_tag(tag_id):
|
def edit_tag(tag_id):
|
||||||
if not session.get('logged_in'):
|
if not session.get('logged_in'):
|
||||||
return redirect(url_for('login'))
|
return redirect(url_for('login'))
|
||||||
db = get_db()
|
# db = get_db()
|
||||||
query = '''
|
# query = '''
|
||||||
SELECT id, tagName
|
# SELECT id, tagName
|
||||||
FROM tags
|
# FROM tags
|
||||||
WHERE id = ?
|
# WHERE id = ?
|
||||||
'''
|
# '''
|
||||||
cur = db.execute(query, [tag_id])
|
# cur = db.execute(query, [tag_id])
|
||||||
tag = cur.fetchone()
|
# tag = cur.fetchone()
|
||||||
|
tag = getTag(tag_id)
|
||||||
return render_template('editTag.html', tag=tag)
|
return render_template('editTag.html', tag=tag)
|
||||||
|
|
||||||
|
|
||||||
@@ -378,5 +409,18 @@ def show():
|
|||||||
tags = getAllTag()
|
tags = getAllTag()
|
||||||
return render_template('show.html', cards=cards, tags=tags, filter_name="all")
|
return render_template('show.html', cards=cards, tags=tags, filter_name="all")
|
||||||
|
|
||||||
|
def getTag(tag_id):
|
||||||
|
if not session.get('logged_in'):
|
||||||
|
return redirect(url_for('login'))
|
||||||
|
db = get_db()
|
||||||
|
query = '''
|
||||||
|
SELECT id, tagName
|
||||||
|
FROM tags
|
||||||
|
WHERE id = ?
|
||||||
|
'''
|
||||||
|
cur = db.execute(query, [tag_id])
|
||||||
|
tag = cur.fetchone()
|
||||||
|
return tag
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host='0.0.0.0')
|
app.run(host='0.0.0.0')
|
||||||
|
|||||||
Reference in New Issue
Block a user