Ejemplo n.º 1
0
def result():
    utils.checklogin(session)
    form_data = request.form
    utils.check_csrf_token(form_data, session)
    
    #There is three arrays. One with all words, one with right answers and last with wrong answers
    all_words = {}
    rights = {}
    wrongs = {}
    deck_id = request.form["deck_id"]
    user_id = session['user_id']
    
    #Takes all keys and values from test.html and if it starts with translation_, we take a id one, after split. 
    #And then we take all words and translations from database where card_id is splitted card_id.
    for key,value in form_data.items():
    	if key.startswith("translation_"):
    	    card_id = int(key.split("translation_")[1])
    	    result_list = database.getword(db, card_id)
    	    word = result_list[1]
    	    right_translation = result_list[0]
    	    all_words[word] = right_translation
    	    
    	    #Now we check if your guess is right or not.
    	    if right_translation.lower().strip() == value.lower().strip():
    	        rights[word] = right_translation
    	    else:
    	        wrongs[word] = value    
    
    #Here we put all right answers and wrong answers into database
    right_answers = len(rights)
    wrong_answers = len(wrongs)
    database.insert_test_results(db, user_id, deck_id, right_answers, wrong_answers)
    return render_template("result.html", rights = rights, wrongs = wrongs, deck_id = deck_id, all_words = all_words)
Ejemplo n.º 2
0
def delete_word():
    utils.checklogin(session)
    utils.check_csrf_token(request.form, session)
    deck_id = int(request.form["deck_id"])
    user_id = database.getuserbasedondeck(db, deck_id)
    utils.userloggedin(user_id, session)
    words = database.getselectedwords(db, deck_id)
    return render_template("delete_selected_word.html", words = words, deck_id = deck_id)
Ejemplo n.º 3
0
def delete_one_deck():
    utils.checklogin(session)
    utils.check_csrf_token(request.form, session)
    deck_id = int(request.form["deck_id"])
    user_id = database.getuserbasedondeck(db, deck_id)
    utils.userloggedin(user_id, session)
    database.deletedeck(db, deck_id)
    return redirect("/")
Ejemplo n.º 4
0
def student_result():
    utils.checklogin(session)
    utils.check_csrf_token(request.form, session)
    student_id = int(request.form["student_id"])
    
    student_results = database.getstudentresults(db, student_id)
    student = database.getstudentname(db, student_id)
    
    return render_template("/student_results.html", student_results = student_results, student = student)
Ejemplo n.º 5
0
def delete_selected_word():
    utils.checklogin(session)
    utils.check_csrf_token(request.form, session)
    deck_id = request.form["deck_id"]
    
    user_id = database.getuserbasedondeck(db, deck_id)
    utils.userloggedin(user_id, session)
    word_id = int(request.form["word_id"])
    database.deleteword(db, word_id)
    
    return redirect("/")
Ejemplo n.º 6
0
def add_new_deck(): 
    utils.checklogin(session)
    utils.check_csrf_token(request.form, session)  
    name = request.form["deck"]
    difficulty = request.form["difficulty"]
    user_id = session['user_id']
    if database.checkdeck(db, name) == False:
    	return render_template("new_deck.html", error = True, errorcode = 3)
    	
    database.insertdeck(db, difficulty, name, user_id)
    	
    return redirect("/")
Ejemplo n.º 7
0
def add_new_estimate():
    utils.checklogin(session)
    utils.check_csrf_token(request.form, session)
    deck_id = request.form["deck_id"]
    user_id = session['user_id']
    comment = request.form["estimate"]
    grade = int(request.form["grade"])
    
    #Check if comment is empty
    if comment == '':
    	comment = 'Ei arvointia'
    	   
    database.insertestimate(db, user_id, deck_id, grade, comment)
    
    return redirect("/")
Ejemplo n.º 8
0
def add_new_word():
    utils.checklogin(session)    
    utils.check_csrf_token(request.form, session)
    word = request.form["word"]
    translation = request.form["translation"]
    deck_id = int(request.form["deck_id"])
    
    if database.checkword(db, word, deck_id) == False:
    	return redirect(f"new_word?deck_id={deck_id}&errorcode=2")
    	
    user_id = database.getdeckowner(db, deck_id)
    utils.userloggedin(user_id, session)
    
    database.insertword(db, deck_id, word, translation)
    
    return redirect(f"/new_word?deck_id={deck_id}")