Exemple #1
0
def submit():
    """Creates a new record, assigning it the id from the session, and grades the test using
    questionator/lib/answers.json. After grading the test, it will set the score in the session to the users score."""
    record = Submission()
    if session.has_key('id'):
        record.uid = session['id']
    else:
        return redirect(url_for('start'))

    #check to make sure they haven't submitted the test multiple times
    if (Submission.hasDuplicate(record.uid)):
        flash('You have already submitted your test')

    #save the last answers if any
    user_test = session['test']
    for k, v in request.form.iteritems():
        user_test[k] = v
    session['test'] = user_test
    
    #grade the test
    record = gradeTest(record, user_test)

    #save the record a keyerror should never happen
    try:
        record.save()
    except KeyError:
        #log on record save failure
        app.logger.error('Record %d failed to save.', record.uid)

    session['score'] = record.score

    return redirect(url_for('results'))
Exemple #2
0
def start():
    """Generate a random id from the systime and assign set id in the session
    won't allow you to generate a new id on refresh.
    """
    #test session has been started
    if session.has_key('id'):
        return render_template('index.html', id=session['id'], error="Unique ID has already been generated,")

    randId = generateID()
    #continue to generate a new id if records are returned
    while (Submission.hasDuplicate(randId)):
        randId = generateID()
    
    #start the session
    session['id'] = randId
    return render_template('index.html', id=randId)