示例#1
0
def get_answers(request):
    done_before = request.POST.get('done_before', False)
    user = temp_user(done_before)
    got_answers = {}
    for source in SOURCES: got_answers[human_names[source]] = []
    for key, value in request.POST.items():
        if key.startswith('q_'):
            qid = int(key[2:])
            question = UserTestQuestion.objects.get(id=qid)
            answer = UserTestAnswer(question=question, user=user,
                                    value=int(value))
            got_answers[human_names[question.source]].append(answer)
            answer.save()
    insert_foot = UserTestAnswer.objects.filter(value=-2).order_by('?')[:10]
    return render_to_response('usertest/results.html', locals())
示例#2
0
文件: views.py 项目: kcarnold/commons
    random.shuffle(questions)
    for q in questions:
        q.asked += 1
        q.save()
    return render_to_response('usertest/ask.html', locals())

from sys import maxint
def temp_user(done_before=False):
    prefix = 'usertest10_use_'
    if done_before: prefix = 'usertest10_skip_'
    username = prefix + str(random.randint(0, 10000000))
    password = '******'
    return User.objects.create_user(username, '', password)

def get_answers(request):
    done_before = request.POST.get('done_before', False)
    user = temp_user(done_before)
    got_answers = {}
    for source in SOURCES: got_answers[human_names[source]] = []
    for key, value in request.POST.items():
        if key.startswith('q_'):
            qid = int(key[2:])
            question = UserTestQuestion.objects.get(id=qid)
            answer = UserTestAnswer(question=question, user=user,
                                    value=int(value))
            got_answers[human_names[question.source]].append(answer)
            answer.save()
    insert_foot = UserTestAnswer.objects.filter(value=-2).order_by('?')[:10]
    return render_to_response('usertest/results.html', locals())