Exemplo n.º 1
0
def start_test(request):
  #check for log in
  if not request.user.is_authenticated():
    return HttpResponseRedirect('/accounts/login/?next=%s' % request.path)
  user = request.user    
  #Get post info
  if request.method == 'GET':
    item_bank_id = request.GET['item_bank_id']
    cat_test_id = request.GET['cat_test_id']
    #Retrieve item bank
    item_bank = ItemBank.objects.get(pk=item_bank_id)
    cat_test = CatTest.objects.get(pk=cat_test_id)
    uib = UserItemBank.objects.get(user=user,item_bank=item_bank)	
    #New user_cat_test
    user_cat_test = UserCatTest()
    user_cat_test.user = user
    user_cat_test.item_bank = item_bank
    user_cat_test.cat_test = cat_test
    user_cat_test.ability = uib.ability
    user_cat_test.stand_dev = uib.ability_stand_dev	
    user_cat_test.save()
    
  #Create cat_test for user with info from item bank
  return render_to_response('start_test.html', {"item_bank": item_bank,"cat_test":cat_test})