예제 #1
0
def profile(request, email):
    # Create your views here.
    # If this is a POST request then process the Form data

    # user=Student.objects.filter(student_email__exact=email)
    profile = Profile()
    # jr=Joiners()
    if request.method == 'POST':

        # Create a form instance and populate it with data from the request (binding):
        form = ProfileForm(request.POST)

        # Check if the form is valid:
        if form.is_valid():
            # process the data in form.cleaned_data as required (here we just write it to the model due_back field)
            profile.test_uid = form.cleaned_data['test_uid']
            # jr.test_uid=profile.test_uid
            profile.test_score = 0
            profile.ques_used = 0
            # profile.ques_id=1
            profile.student_emailid = email
            # jr.save()
            profile.save()
            zero = 0
            zero = str(zero)
            # redirect to a new URL:
            return HttpResponseRedirect('/test/%s/%s/%s' %
                                        (email, profile.test_uid, zero))

    # If this is a GET (or any other method) create the default form.
    else:
        form = ProfileForm()

    context = {'form': form, 'email': email, 'Profile': profile}

    return render(request, 'dashboard.html', context)
예제 #2
0
def exam(request, email, testno, qno):
    qno = int(qno)
    pr = list(
        Profile.objects.filter(test_uid__exact=testno,
                               student_emailid__exact=email,
                               ques_id__exact=qno))

    mcq = Mcq.objects.filter(test_no__exact=testno)
    total_ques = mcq.count()
    if request.method == 'POST':
        form = TestForm(request.POST)
        if form.is_valid():
            one = form.cleaned_data['ans1']
            two = form.cleaned_data['ans2']
            three = form.cleaned_data['ans3']
            four = form.cleaned_data['ans4']
            # jr=list(Joiners.objects.filter(test_uid__exact=testno,student_emailid__exact=email,ques_id__exact=qno))
            # if len(jr)==0:
            #     jrr=Joiners()
            #     jrr.ques_used=0
            #     jrr.student_emailid=email
            #     jrr.ques_id=qno
            #     jrr.test_uid=testno
            #     jrr.save()
            #     jr.append(jrr)

            if one == mcq[qno].ans1 and two == mcq[qno].ans2 and three == mcq[
                    qno].ans3 and four == mcq[qno].ans4 and pr[
                        0].ques_used == 0:
                # qno=str(qno)
                # qno=int(qno)
                pr[0].test_score = pr[0].test_score + mcq[qno].points
                pr[0].ques_used = 1
                # jr[0].save()
                # qno=str(qno)
                # request.session[qno]=True
                # request.session.modified=True
                pr[0].save()

            # pr[0].save()
            qno = int(qno)
            qno = qno + 1
            qno = str(qno)
            pro = Profile()
            pro.test_uid = testno
            pro.ques_used = 0
            pro.test_score = 0
            pro.ques_id = qno
            pro.student_emailid = email
            pro.save()
            return HttpResponseRedirect('/test/%s/%s/%s' %
                                        (email, testno, qno))
    else:
        form = TestForm()
    if qno < total_ques:
        context = {'form': form, 'Mcq': mcq[qno], 'Profile': pr[0]}
        return render(request, 'ques.html', context)
    else:
        pr = list(
            Profile.objects.filter(test_uid__exact=testno,
                                   student_emailid__exact=email))
        score = 0
        for i in pr:
            score += int(i.test_score)
        for i in range(len(pr)):
            pr[i].test_score = score
            pr[i].save()

        context = {
            'form': form,
            'Mcq': mcq[qno - 1],
            'Profile': pr[0],
            'score': score
        }
        return render(request, 'result.html', context)