]> git.parisson.com Git - django_quiz.git/commitdiff
removed the template tag user_previous_exam
authorTom Walker <tomwalker0472@gmail.com>
Sun, 13 Jul 2014 18:48:46 +0000 (19:48 +0100)
committerTom Walker <tomwalker0472@gmail.com>
Sun, 13 Jul 2014 18:48:46 +0000 (19:48 +0100)
quiz/models.py
quiz/templates/progress.html
quiz/templates/user_previous_exam.html [deleted file]
quiz/templatetags/quiz_tags.py
quiz/tests.py
quiz/views.py

index d4126d99bb3ea09bbf851045e0409a0a29b14b1a..cc473414a55ce7cd081d8909bb9443a13b6baee8 100644 (file)
@@ -124,6 +124,7 @@ class Quiz(models.Model):
     def get_questions(self):
         return self.question_set.all().select_subclasses()
 
+    @property
     def get_max_score(self):
         return self.get_questions().count()
 
@@ -382,6 +383,7 @@ class Sitting(models.Model):
     def get_current_score(self):
         return self.current_score
 
+    @property
     def get_percent_correct(self):
         dividend = float(self.current_score)
         divisor = self.quiz.question_set.all().select_subclasses().count()
index 3912f5fd028e348ec19b606064f8cb253671992b..224d0e5283d929e346fb9e3963f82ab54285dadf 100644 (file)
 
 <div class="container">
 
-{% if new_user %}
-
-               <div class="alert alert-block">
-                       <button type="button" class="close" data-dismiss="alert">&times;</button>
-                       <ul class="unstyled">
-                         <li>
-                               <h4>Thank you for joining this website. Welcome to your progress page.</h4>
-                         </li>
-                       </ul>
-               </div>
-
-{% endif %}
-
-
-{% if cat_scores %}
-
-<h1>Question Category Scores</h1>
-<p class="lead">
-       Below are the categories of questions that you have attempted. Blue is the percentage that are correct.
-</p>
-
-<script type="text/javascript" src="http://www.google.com/jsapi"></script>
-<script type="text/javascript">
-       google.load('visualization', '1', {packages: ['corechart']});
-</script>
-
-               {% for cat, value in cat_scores.items %}
-
-                       {% ifnotequal cat "empty" %}
-
-                               {% if forloop.first %}
-                                       <div class="row">
-                                               <ul class="thumbnails">
-                               {% endif %}
-
-                               {% ifequal forloop.counter 5 %}
-                                               </ul>
-                                       </div>
-                                       <div class="row">
-                                               <ul class="thumbnails">
-                               {% endifequal %}
-
-                               {% ifequal forloop.counter 9 %}
-                                               </ul>
-                                       </div>
-                                       <div class="row">
-                                               <ul class="thumbnails">
-                               {% endifequal %}
-
-                               {% ifequal forloop.counter 13 %}
-                                               </ul>
-                                       </div>
-                                       <div class="row">
-                                               <ul class="thumbnails">
-                               {% endifequal %}
-
-                               {% ifequal forloop.counter 17 %}
-                                               </ul>
-                                       </div>
-                                       <div class="row">
-                                               <ul class="thumbnails">
-                               {% endifequal %}
-
-                                                       <li class="span3">
-                                                               <div class="thumbnail">
-                                                                                                                           <script type="text/javascript">
-                                                     function drawVisualization() {
-                                                       // Create and populate the data table.
-                                                       var difference = {{ value.1 }} - {{ value.0 }};
-                                                       var correct = {{ value.0 }};
-                                                       var data = google.visualization.arrayToDataTable([
-                                                         ["",""],
-                                                         ['Correct',  correct],
-                                                         ['Incorrect', difference]
-                                                       ]);
-
-                                                       var options = {
-                                                               legend:{position:'none'},
-                                                               title:"{{ cat }}",
-                                                               fontSize: 16
-                                                               };
-
-                                                       // Create and draw the visualization.
-                                                       new google.visualization.PieChart(document.getElementById('visualization{{ cat }}')).
-                                                           draw(data, options);
-                                                     }
-
-
-                                                     google.setOnLoadCallback(drawVisualization);
-                                                   </script>
-
-                                               <div id="visualization{{ cat }}" ></div>
-                                                               </div>
-                                                       </li>
-
-                       {% endifnotequal %}
-
-
-        {% endfor %}
-                                               </ul>
-                                       </div>
-
-{% endif %}
-
-{% if exams %}
-
-<hr>
+  {% if cat_scores %}
 
-<h1>Previous exam papers</h1>
-<p class="lead">
+  <h1>Question Category Scores</h1>
+
+  <table class="table table-bordered table-striped">
+
+       <thead>
+         <tr>
+               <th>Category</th>
+               <th>Correctly answererd</th>
+               <th>Incorrect</th>
+               <th>%</th>
+         </tr>
+       </thead>
+
+       <tbody>
+
+
+         {% for cat, value in cat_scores.items %}
+         <tr>
+               <td>{{ cat }}</td>
+               <td>{{ value.0 }}</td>
+               <td>{{ value.1 }}</td>
+               <td>{{ value.2 }}</td>
+         </tr>
+
+         {% endfor %}
+
+       </tbody>
+
+  </table>
+
+
+  {% endif %}
+
+  {% if exams %}
+
+  <hr>
+
+  <h1>Previous exam papers</h1>
+  <p class="lead">
        Below are the results of exams that you have sat.
-</p>
+  </p>
 
-<table class="table table-bordered table-striped">
+  <table class="table table-bordered table-striped">
 
        <thead>
-               <tr>
-                       <th>Quiz Title</th>
-                       <th>Score</th>
-                       <th>Possible Score</th>
-                       <th>%</th>
-        </tr>
-    </thead>
+         <tr>
+               <th>Quiz Title</th>
+               <th>Score</th>
+               <th>Possible Score</th>
+               <th>%</th>
+         </tr>
+       </thead>
 
-    <tbody>
+       <tbody>
 
-           {% for exam in exams %}
+         {% for exam in exams %}
 
-               <tr>
-                       {% user_previous_exam exam %}
-               </tr>
+         <tr>
+               <td>{{ exam.quiz.title }}</td>
+               <td>{{ exam.current_score }}</td>
+               <td>{{ exam.quiz.get_max_score }}</td>
+               <td>{{ exam.get_percent_correct }}</td>
+         </tr>
 
-           {% endfor %}
+         {% endfor %}
 
-    </tbody>
+       </tbody>
 
-</table>
+  </table>
 
-{% endif %}
+  {% endif %}
 
 </div>
 
diff --git a/quiz/templates/user_previous_exam.html b/quiz/templates/user_previous_exam.html
deleted file mode 100644 (file)
index 42bda82..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-<td>{{ title }}</td>
-<td>{{ score }}</td>
-<td>{{ possible }}</td>
-<td>{{ percent }}</td>
index 35968f668bd3f7a899a1746aadf3cc78f4d926ef..d4dac7d53b2c31b77685a0a4b1661666a720befc 100644 (file)
@@ -19,17 +19,3 @@ def correct_answer_for_all(context, question):
 
     return {'previous': previous,
             'user_was_incorrect': user_was_incorrect}
-
-
-@register.inclusion_tag('user_previous_exam.html', takes_context=True)
-def user_previous_exam(context, exam):
-    """
-    Provides details of finished exams
-    """
-    final_score = exam.current_score
-    possible_score = exam.quiz.get_max_score()
-    percent = int(round((float(final_score) / float(possible_score)) * 100))
-    return {'title': exam.quiz.title,
-            'score': final_score,
-            'possible': possible_score,
-            'percent': percent}
index 768a7ce24ecde8e71413bc9ae24d7b5ffee81ae7..81506830873a86674a7d51408b8fa44cf0f73d21 100644 (file)
@@ -77,7 +77,7 @@ class TestQuiz(TestCase):
         self.assertEqual(self.quiz1.exam_paper, True)
 
     def test_get_max_score(self):
-        self.assertEqual(self.quiz1.get_max_score(), 1)
+        self.assertEqual(self.quiz1.get_max_score, 1)
 
     def test_get_questions(self):
         self.assertIn(self.question1, self.quiz1.get_questions())
@@ -195,15 +195,15 @@ class TestSitting(TestCase):
 
         self.sitting.add_to_score(1)
         self.assertEqual(self.sitting.get_current_score(), 1)
-        self.assertEqual(self.sitting.get_percent_correct(), 50)
+        self.assertEqual(self.sitting.get_percent_correct, 50)
 
         self.sitting.add_to_score(1)
         self.assertEqual(self.sitting.get_current_score(), 2)
-        self.assertEqual(self.sitting.get_percent_correct(), 100)
+        self.assertEqual(self.sitting.get_percent_correct, 100)
 
         self.sitting.add_to_score(1)
         self.assertEqual(self.sitting.get_current_score(), 3)
-        self.assertEqual(self.sitting.get_percent_correct(), 100)
+        self.assertEqual(self.sitting.get_percent_correct, 100)
 
     def test_incorrect_and_complete(self):
         self.assertEqual(self.sitting.get_incorrect_questions(), [])
@@ -286,8 +286,6 @@ class TestNonQuestionViews(TestCase):
         self.assertIn('straw.berries', response.context['cat_scores'])
         self.assertEqual([1, 2, 50],
                          response.context['cat_scores']['elderberries'])
-        self.assertContains(response, 'var difference = 2 - 1;')
-        self.assertContains(response, 'var correct = 1;')
 
     def test_quiz_start_page(self):
         response = self.client.get('/q/tq1/')
@@ -651,15 +649,3 @@ class TestTemplateTags(TestCase):
         self.assertTemplateUsed('correct_answer.html')
         self.assertIn('bing', template.render(context))
         self.assertIn('incorrectly', template.render(context))
-
-    def test_previous_exam(self):
-        template = Template('{% load quiz_tags %}' +
-                            '{% user_previous_exam exam %}')
-
-        context = Context({'exam': self.sitting})
-
-        self.assertTemplateUsed('user_previous_exam.html')
-        self.assertIn('test quiz 1', template.render(context))
-        self.assertIn('<td>1</td>', template.render(context))
-        self.assertIn('<td>2</td>', template.render(context))
-        self.assertIn('<td>50</td>', template.render(context))
index 1b11eed5fa095e531c1d93179c835b5106734b6a..e5d35918bd9e85cf17ca9582f436ee3d6e7516a0 100644 (file)
@@ -7,7 +7,6 @@ from django.utils.decorators import method_decorator
 from django.views.generic import DetailView, ListView, TemplateView
 
 from .models import Quiz, Category, Progress, Sitting, Question
-from multichoice.models import MCQuestion
 
 
 class QuizListView(ListView):
@@ -140,8 +139,8 @@ def user_load_next_question(request, sitting, quiz):
 def final_result_user(request, sitting, quiz, previous):
     score = sitting.get_current_score()
     incorrect = sitting.get_incorrect_questions()
-    max_score = quiz.get_max_score()
-    percent = sitting.get_percent_correct()
+    max_score = quiz.get_max_score
+    percent = sitting.get_percent_correct
 
     sitting.mark_quiz_complete()
 
@@ -266,7 +265,7 @@ def anon_session_score(request, to_add=0, possible=0):
 
 def final_result_anon(request, quiz, previous):
     score = request.session[quiz.anon_score_id()]
-    max_score = quiz.get_max_score()
+    max_score = quiz.get_max_score
     percent = int(round((float(score) / max_score) * 100))
     if score is 0:
         score = "0"