Commits

Arun Karunagath  committed ac6e6fe

Selcting previously answered options on page traversal

  • Participants
  • Parent commits 9d91067

Comments (0)

Files changed (3)

File src/ExTestTool/settings.py

 )
 
 # Grappelli related
-GRAPPELLI_ADMIN_TITLE = 'Mom & Me Associate Tablet: Admin'
-GRAPPELLI_ADMIN_HEADLINE = 'Mom & Me Associate Tablet: Admin'
+GRAPPELLI_ADMIN_TITLE = 'ExText: Expicient e-Test: Admin'
+GRAPPELLI_ADMIN_HEADLINE = 'ExText: Expicient e-Test: Admin'

File src/onlinetest/templates/exam.html

     <br />
     <div class="row">
             <div class="span3">
-                Time remaing:<p id="counter"></p>
-                <!-- {{ request.session.should_end_at|timeuntil }} more 
-                <div class="well"></div>                -->
+                <p id="counter"></p>
+                <!-- {{ request.session.should_end_at|timeuntil }} more -->
+                <br />
+                <div class="well"> {{ answerd }} out of 30 question attempted.</div>                
                 <br />
                 <a class="btn btn-warning btn-large" href="{% url onlinetest.views.submit %}">End Test</a>
             </div>
                     <div style='display:none'><input type='hidden' name='question_item' value='{{ cur }}' /></div>
                     <div class="controls">
                         <label class="radio">
-                            <input type="radio" name="answer" value="{{ options.0.pk }}" /> 
+                            <input type="radio" name="answer" value="{{ options.0.pk }}" {% if sel_opt %}{% if sel_opt == options.0.pk %} checked {% endif %}{% endif %} /> 
                             {{ options.0.answer|safe|escape }}
                         </label>
                         <label class="radio">
-                            <input type="radio" name="answer" value="{{ options.1.pk }}" />
+                            <input type="radio" name="answer" value="{{ options.1.pk }}" {% if sel_opt %}{% if sel_opt == options.1.pk %} checked {% endif %}{% endif %} />
                             {{ options.1.answer|safe|escape }}
                         </label>
                         <label class="radio">
-                            <input type="radio" name="answer" value="{{ options.2.pk }}" />
+                            <input type="radio" name="answer" value="{{ options.2.pk }}" {% if sel_opt %}{% if sel_opt == options.2.pk %} checked {% endif %}{% endif %} />
                             {{ options.2.answer|safe|escape }}
                         </label>
                         <label class="radio">
-                            <input type="radio" name="answer" value="{{ options.3.pk }}" />
+                            <input type="radio" name="answer" value="{{ options.3.pk }}" {% if sel_opt %}{% if sel_opt == options.3.pk %} checked {% endif %}{% endif %} />
                             {{ options.3.answer|safe|escape }}
                         </label>
                     </div>

File src/onlinetest/views.py

 from onlinetest.models import QuestionItem
 from onlinetest.models import QuestionPaper
 from onlinetest.models import Student
-
 from questionbank.models import CategorizedQuestion
 from questionbank.models import MultiQuestion
 from questionbank.models import Option
 from questionbank.models import SubQuestion
+from reports.models import Report
 
 """
 IN_PH = re.compile(
         return HttpResponse("Huh, Playing with me?")
 
     now = datetime.datetime.now()
-    #if not (now < request.session['should_end_at'] and now > request.session['started_at']):
-    #    return HttpResponse("TODO: Submit Form")
+    if not (now < request.session['should_end_at'] and now > request.session['started_at']):
+       return HttpResponseRedirect('/submit/') # Exam time is over, let's submit it.
 
     # time management
     remaining_time = request.session['should_end_at'] - now
     next = qids[indx+1] if indx<len(qids)-1 else None # len()-1 will be last index
     prev = qids[indx-1] if indx>0 else None # 0 is first inde
 
+    # How many answerd
+    student = Student.objects.get(user=request.user)
+    answerd = AnswerItem.objects.filter(student=student).count()
+
+    #if an option is previosuly answered we have to select it by default
+    sel_opt = None
+    try:
+        qi = QuestionItem.objects.get(pk=qid)
+        a = AnswerItem.objects.get(student=student, question_item=qi)
+        sel_opt = a.answer_id
+    except:
+        pass
+
     bundle = {
         'cur': str(int(qid)),
         'next': next,
         'options': options_pos,
         'cat_beg': dict(request.session['cat_beg']),
         'bookmarks': request.session.get('bookmarks', []),
+        'answerd': answerd,
+        'sel_opt': sel_opt,
     }
     return render(request, 'exam.html', bundle)
 
     return HttpResponse(json.dumps(data),mimetype="application/json")
 
 def submit(request):
-    return HttpResponse("Thanks")
+    student = Student.objects.get(user=request.user)
+    attempts = AnswerItem.objects.filter(student=student).order_by('question_item__category')
+
+    marks = defaultdict(float)
+    for item in attempts:
+        if item.answer_id == item.question_item.answer_id:
+            marks[item.question_item.category.name] += 1
+        else:
+            marks[item.question_item.category.name] -= 0.25
+
+    #create the report for the student
+    report = Report()
+    report.sid = student
+    report.name = str(student)
+    report.lr_marks = marks.get('LOGICAL', 0)
+    report.mathematics_marks = marks.get('MATH', 0) + marks.get('DI', 0)
+    report.rc_marks = marks.get('RC', 0)    
+    report.marks_obtained = report.lr_marks + report.mathematics_marks + report.rc_marks
+    report.save()
+
+    #log the user out and clear session
+    request.session.clear()
+    request.session.flush()
+    logout(request)
+
+    #redirect to regiser page
+    return HttpResponseRedirect("/")