More little fixes
authorCharles Connell <charles@connells.org>
Tue, 4 Mar 2014 21:02:43 +0000 (16:02 -0500)
committerCharles Connell <charles@connells.org>
Tue, 4 Mar 2014 21:02:43 +0000 (16:02 -0500)
karmaworld/apps/quizzes/views.py
karmaworld/assets/css/quiz.css
karmaworld/assets/js/quiz.js
karmaworld/settings/common.py
karmaworld/templates/quizzes/quiz.html

index c67205d70f7b902c51fe75db5a1b0bef76ef9055..80c98b543c954ef82dda53ef0bbaa0e87ccb212a 100644 (file)
@@ -36,6 +36,7 @@ class QuizView(DetailView):
                              reverse=True)
 
         kwargs['questions'] = result_list
+        kwargs['quiz'] = self.object
 
         return super(QuizView, self).get_context_data(**kwargs)
 
@@ -120,8 +121,8 @@ def quiz_answer(request):
 
     except Exception, e:
         return HttpResponseBadRequest(json.dumps({'status': 'fail',
-                                                'message': e.message,
-                                                'exception': e.__class__.__name__}),
-                                    mimetype="application/json")
+                                                  'message': e.message,
+                                                  'exception': e.__class__.__name__}),
+                                      mimetype="application/json")
 
     return HttpResponse(json.dumps({'correct': correct}), mimetype="application/json")
\ No newline at end of file
index 4b51e874688273dec29bc3d2ba967d72184ae0c9..25938bdfc42a2f9cceaa0136292034bcbc2f67a6 100644 (file)
 .wrong-answer
 {
   background-color: #ffb4b4;
-}
\ No newline at end of file
+}
+
+div.question ul
+{
+  list-style-type: none;
+}
+
index f78f4dc26fd499ca8846d4d79287913a5312f270..7ff988422062704e8392bc0b69411c1e852115d9 100644 (file)
@@ -19,10 +19,22 @@ function prevQuestion() {
   }
 }
 
+function updateCorrectCount() {
+  var count = 0;
+  for (var i = 0; i < num_quiz_questions; i++) {
+    if (correct_questions[i]) {
+      count += 1
+    }
+  }
+  $('#num-correct').html(count);
+}
+
 function checkAnswerCallback(data, textStatus, jqXHR) {
   var question = $('div[data-question-index="' + current_question_index + '"]');
   var question_text = question.find('p.question-text');
   if (data.correct == true) {
+    correct_questions[current_question_index] = true;
+    updateCorrectCount();
     question_text.removeClass('wrong-answer');
     question_text.removeClass('correct-answer');
     question_text.addClass('correct-answer-flash');
@@ -73,8 +85,20 @@ function checkAnswer() {
 }
 
 $(function () {
+  // show the first question
   showQuestion();
+
+  // set up handlers
   $('button.check-answer').click(checkAnswer);
   $('button.prev-question').click(prevQuestion);
   $('button.next-question').click(nextQuestion);
+  $('input.multiple-choice-choice').click(checkAnswer);
+  $('input.true-false-choice').click(checkAnswer);
+
+  // initialize record of correct answers
+  correct_questions = new Array(num_quiz_questions);
+  for (var i = 0; i < num_quiz_questions; i++) {
+    correct_questions[i] = false;
+  }
+
 });
\ No newline at end of file
index ccc410c0adc4e14b07f1b60ed9a0b71e970a37b6..c3299f7d0ae29f6bd11ff27c3086b7e0f4f26866 100644 (file)
@@ -29,6 +29,7 @@ ALLOWED_HOSTS = [
     'beta.karmanotes.org',
     'www.karmanotes.org',
     'karmanotes.org',
+    'ec2-184-73-42-39.compute-1.amazonaws.com',
 ]
 ########## END SECURITY CONFIGURATION
 
index 4b2ac84a2fcdccb444f4ada31da043fd1f019cbc..3ac6e8a1e172d008d3abf0435b61118bd131438c 100644 (file)
 {% block content %}
   <section id="dashboard_content">
     <div id="stats_container" class="hero_gradient_bar">
+      <div class="row">
+        <div class="twelve columns header_subhead">
+          <a href="{{ quiz.note.get_absolute_url}} ">
+            <i class="fa fa-arrow-left"></i>&nbsp;back to {{ quiz.note.name }}
+          </a>
+        </div>
+      </div>
       <div class="row">
         <div class="small-10 columns small-centered center header_title">
           {{ quiz.name }}
             </div>
           </div>
           <div class="row">
-            <div class="small-6 columns center  stat_number stat_earned">
-              3
+            <div id="num-correct" class="small-6 columns center  stat_number stat_earned">
+              0
             </div>
             <div class="small-6 columns  center stat_number stat_uploaded">
-              14
+              {{ questions|length }}
             </div>
           </div>
           <div class="row">
                 <p class="question-text">{{ question.question_text }}</p>
                 <ul>
                   {% for choice in question.choices.all %}
-                    <li><input id="choice_{{ question.id }}_{{ choice.id }}"
-                               type="radio"
-                               name="{{ question.id }}"
-                               value="{{ choice.id }}"
-                               data-choice-id="{{ choice.id }}">
-                      <label for="choice_{{ question.id }}_{{ choice.id }}">{{ choice.text }}</label></li>
+                    <li><label for="choice_{{ question.id }}_{{ choice.id }}">
+                          <input id="choice_{{ question.id }}_{{ choice.id }}"
+                                 type="radio"
+                                 name="multiple_choice_{{ question.id }}"
+                                 value="{{ choice.id }}"
+                                 class="multiple-choice-choice"
+                                 data-choice-id="{{ choice.id }}">
+                          {{ choice.text }}</label></li>
                   {% endfor %}
                 </ul>
               {% endif %}
 
               {% if 'TrueFalseQuestion' in item.0 %}
                 <p class="question-text">{{ question.text }}</p>
-                <li><input id="choice_{{ question.id }}_true"
-                           type="radio"
-                           name="{{ question.id }}"
-                           value="true">
-                <label for="choice_{{ question.id }}_true">True</label></li>
-                <li><input id="choice_{{ question.id }}_false"
-                           type="radio"
-                           name="{{ question.id }}"
-                           value="false">
-                <label for="choice_{{ question.id }}_false">False</label></li>
+                <ul>
+                  <li><label for="choice_{{ question.id }}_true">
+                        <input id="choice_{{ question.id }}_true"
+                               type="radio"
+                               name="true_false_{{ question.id }}"
+                               class="true-false-choice"
+                               value="true">
+                          True</label></li>
+                  <li><label for="choice_{{ question.id }}_false">
+                        <input id="choice_{{ question.id }}_false"
+                               type="radio"
+                               name="true_false_{{ question.id }}"
+                               class="true-false-choice"
+                               value="false">
+                          False</label></li>
+                </ul>
               {% endif %}
 
               {% if 'FlashCardQuestion' in item.0 %}
                 <p class="question-text">{{ question.definition_side }}</p>
                 <input type="text"
-                       name="{{ question.id }}"
+                       name="flash_card_{{ question.id }}"
                        id="text_{{ question.id }}">
               {% endif %}