Example #1
0
def saved (request):
    answers =  get_answers(request.POST.items())
    #Make blank state, add the backlog of answers, get next state
    state = start_state(request.user)
    state.add_vars(answers,1)
    state.next_state()
    priorQuestions = getPriorQuestions(state.get_answers())
    #If logged in, save progress to profile
    if request.user.is_authenticated():
        profile = request.user.get_profile()
        profile.save_answers(answers)
    return ask_or_done(request, state, priorQuestions)
Example #2
0
def ask(request):
    context = RequestContext(request)
    if request.method == 'POST':
        # user answered some questions
        answers =  get_answers(request.POST.items())
        state = get_state(request.session)
        state.next_state(answers)
        priorQuestions = getPriorQuestions(state.get_answers())
        if request.user.is_authenticated():
            profile = request.user.get_profile()
            profile.save_answers(state.get_answers())
        return ask_or_done(request, state, priorQuestions)
    else:
        # User clicks Start on Index...
        state = start_state(request.user)
        priorQuestions = None
        #If logged in, grab prior progress and use it to resume.
        if request.user.is_authenticated():
            profile = request.user.get_profile()
            priorAnswers = profile.get_answers()
            state.add_vars(priorAnswers,1)
            priorQuestions = getPriorQuestions(profile.get_answers())
        state.next_state()
        return ask_or_done(request, state, priorQuestions)