Example #1
0
def tc_run_final_view(request, tc_id):
    tc = get_object_or_404(TaskCollection, pk=tc_id)

    response = HttpResponse()

    if "tc_task_id" not in request.session:
        response.write("<p>You haven't even started the quiz yet.</p>")
        return response

    if "tc_id" in request.session:
        if int(tc_id) != request.session["tc_id"]:
            response.write(
                "<p>You can't switch task collections on your own.</p>")
            return response

    tc_task_id = request.session["tc_task_id"]
    if tc_task_id < tc.number_of_tasks() - 1:
        response.write("<p>You're not done with the quiz yet.</p>")
        return response

    log = ""
    if "log" in request.session:
        log = request.session["log"]
    log += "Show final page."

    request.session.clear()

    current_date = datetime.now()
    date_iso8601 = current_date.isoformat(" ")
    hash_string = compute_hash(log, date_iso8601)

    quiz_result = QuizResult()
    quiz_result.date = current_date
    quiz_result.hash = hash_string
    quiz_result.log = log
    quiz_result.save()

    context_dict = dict(tc=tc)
    context_dict["hash"] = hash_string
    context = Context(context_dict)

    return render(request, 'tasks/tc_run_final.html', context)
Example #2
0
def tc_run_final_view(request, tc_id):
    tc = get_object_or_404(TaskCollection, pk=tc_id)

    response = HttpResponse()

    if "tc_task_id" not in request.session:
        response.write("<p>You haven't even started the quiz yet.</p>")
        return response

    if "tc_id" in request.session:
        if int(tc_id) != request.session["tc_id"]:
            response.write("<p>You can't switch task collections on your own.</p>")
            return response

    tc_task_id = request.session["tc_task_id"]
    if tc_task_id < tc.number_of_tasks() - 1:
        response.write("<p>You're not done with the quiz yet.</p>")
        return response

    log = ""
    if "log" in request.session:
        log = request.session["log"]
    log += "Show final page."

    request.session.clear()

    current_date = datetime.now()
    date_iso8601 = current_date.isoformat(" ")
    hash_string = compute_hash(log, date_iso8601)

    quiz_result = QuizResult()
    quiz_result.date = current_date
    quiz_result.hash = hash_string
    quiz_result.log = log
    quiz_result.save()

    context_dict = dict(tc=tc)
    context_dict["hash"] = hash_string
    context = Context(context_dict)

    return render(request, 'tasks/tc_run_final.html', context)