def challenge(request, question_no): question = get_object_or_404(Question, question_no=question_no) team = get_object_or_404(Team, team_name=request.user) # Save current time if `coding_start_time` is NULL in db if team.coding_start_time is None: team.coding_start_time = timezone.now() team.save() if team.is_coding_time_over: return HttpResponseRedirect(reverse('coding:index')) case_list = _get_case_list(question) status_dict = _get_question_statuses(team) if request.method == 'POST': file_form = UploadFileForm(request.POST, request.FILES) if file_form.is_valid(): # Save file obj, is_created = UploadFileModel.objects.update_or_create( team=team, question_no=question_no, defaults={'file': request.FILES['file'], }) # Save Output texts for case in case_list: output_field = case['output']['field_name'] output_text = request.POST.get(output_field) obj, is_created = TeamCodingAnswer.objects.update_or_create( question_no=question.question_no, inputcase_no=case['input']['case_no'], team=team, defaults={'output_text': output_text, }) next_question_no = int(question_no) + 1 if Question.objects.filter(question_no=next_question_no).exists(): return HttpResponseRedirect( reverse('coding:challenge', args=(next_question_no, ))) else: return HttpResponseRedirect(reverse('coding:index')) else: file_form = UploadFileForm() # Populate output text with previous answers for case in case_list: try: answer = team.teamcodinganswer_set.get( question_no=question_no, inputcase_no=case['input']['case_no']) case['output']['previous_answer'] = answer.output_text except TeamCodingAnswer.DoesNotExist: case['output']['previous_answer'] = '' return render(request, 'coding/challenge.html', { 'question': question, 'case_list': case_list, 'status_dict': status_dict, 'file_form': file_form, 'remaining_time': team.remaining_coding_time, })
def upload_teams(request): if request.method == 'POST': form = UploadFileForm(request.POST, request.FILES) if form.is_valid(): print "!!!!!!!!!!!!", request.FILES, request.FILES['groups'] handle_uploaded_file(request.FILES['groups']) else: form = UploadFileForm() return render_to_response('upload_teams.html', {'form': form}, context_instance=RequestContext(request))
def challenge(request, question_no): question = get_object_or_404(Question, question_no=question_no) team = get_object_or_404(Team, team_name=request.user) # Save current time if `coding_start_time` is NULL in db if team.coding_start_time is None: team.coding_start_time = timezone.now() team.save() if _is_time_over(team): return HttpResponseRedirect(reverse('coding:index')) case_list = _get_case_list(question) status_dict = _get_question_statuses(team) if request.method == 'POST': file_form = UploadFileForm(request.POST, request.FILES) if file_form.is_valid(): # Save file obj, is_created = UploadFileModel.objects.update_or_create( team=team, question_no=question_no, defaults={'file': request.FILES['file'],} ) # Save Output texts for case in case_list: output_field = case['output']['field_name'] output_text = request.POST.get(output_field) obj, is_created = TeamCodingAnswer.objects.update_or_create( question_no=question.question_no, inputcase_no=case['input']['case_no'], team=team, defaults={'output_text': output_text,} ) next_question_no = int(question_no) + 1 if Question.objects.filter(question_no=next_question_no).exists(): return HttpResponseRedirect(reverse('coding:challenge', args=(next_question_no,))) else: return HttpResponseRedirect(reverse('coding:index')) else: file_form = UploadFileForm() # Populate output text with previous answers for case in case_list: try: answer = team.teamcodinganswer_set.get( question_no=question_no, inputcase_no=case['input']['case_no'] ) case['output']['previous_answer'] = answer.output_text except TeamCodingAnswer.DoesNotExist: case['output']['previous_answer'] = '' return render(request, 'coding/challenge.html', { 'question': question, 'case_list': case_list, 'status_dict': status_dict, 'file_form': file_form, 'remaining_time': _get_remaining_time(team),} )